You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
618 B

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