Sha256: b17a239a0f480d0a917d445732775ee958955e6cd67944fae4e0b7b6a50e1b61

Contents?: true

Size: 785 Bytes

Versions: 4

Compression:

Stored size: 785 Bytes

Contents

require "pstore"

class NamingProvider

  def value
    self
  end

  def generate_name(adj_first_letter = nil, noun_first_letter = nil)
    "#{adjective adj_first_letter}-#{noun noun_first_letter}"
  end

  def random_letter
    ('a'..'z').to_a.shuffle.first
  end

  private

  def dictionary(key)
    @dictionary ||= PStore.new dictionary_file
    @dictionary.transaction(true) { @dictionary[key] }
  end

  def dictionary_file
    File.expand_path '../naming/dictionary.pstore', __FILE__
  end

  def noun(first_letter)
    word 'nouns', first_letter
  end

  def adjective(first_letter)
    word 'adjectives', first_letter
  end

  def word(type, first_letter)
    first_letter ||= random_letter
    list = dictionary(type)[first_letter]
    list[rand(list.length - 1)]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rumm-0.1.0 app/providers/naming_provider.rb
rumm-0.0.24 app/providers/naming_provider.rb
rumm-0.0.23 app/providers/naming_provider.rb
rumm-0.0.22 app/providers/naming_provider.rb