cartodb-4.42/app/models/visualization/name_generator.rb

27 lines
618 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
require_relative './name_checker'
module CartoDB
module Visualization
class NameGenerator
PATTERN = 'Untitled map'
def initialize(user, checker=nil)
@user = user
@checker = checker || NameChecker.new(user)
end
def name(candidate=PATTERN, iteration=0)
candidate = (candidate || PATTERN).strip
new_candidate = iteration > 0 ? "#{candidate} #{iteration}" : candidate
return new_candidate if checker.available?(new_candidate)
name(candidate, iteration + 1)
end
private
attr_reader :checker, :user
end
end
end