class Nameit
Constants
- VERSION
Attributes
max_number[R]
number[R]
random[R]
Public Class Methods
generate(options = {})
click to toggle source
# File lib/nameit.rb, line 26 def self.generate(options = {}) new(options).generate end
new(options = {})
click to toggle source
# File lib/nameit.rb, line 14 def initialize(options = {}) @random = options.fetch(:random, ::Nameit::Random.new) @number = options.fetch(:number, false) @max_number = [options.fetch(:max_number, 999), 1].max end
Public Instance Methods
generate()
click to toggle source
# File lib/nameit.rb, line 20 def generate name = "#{random_adjective}-#{random_noun}" name += "-#{random_number}" if number name end
Private Instance Methods
adjectives()
click to toggle source
# File lib/nameit.rb, line 34 def adjectives @adjectives ||= IO.readlines(data_file("nameit-adjectives.txt")) end
data_file(name)
click to toggle source
# File lib/nameit.rb, line 38 def data_file(name) File.join(File.dirname(__FILE__), "..", "data", name) end
nouns()
click to toggle source
# File lib/nameit.rb, line 42 def nouns @nouns ||= IO.readlines(data_file("nameit-nouns.txt")) end
random_adjective()
click to toggle source
# File lib/nameit.rb, line 46 def random_adjective adjectives[random.rand(adjectives.size)].chomp end
random_noun()
click to toggle source
# File lib/nameit.rb, line 50 def random_noun nouns[random.rand(nouns.size)].chomp end
random_number()
click to toggle source
# File lib/nameit.rb, line 54 def random_number "%0#{(Math.log10(max_number) + 1).to_i}d" % random.rand(max_number) end