Module: Cryptozoologist::Generator
Instance Method Summary collapse
- #city ⇒ Object
- #full_name ⇒ Object
-
#lorem(sentence_count) ⇒ Object
Generates sentence_count sentences, ranging in length from 10-16 words, using the dictionaries from your config.
-
#random ⇒ Object
Generates a string using the dictionaries and delimiter from your config.
-
#state(desired_state, desired_library, desired_replace_index) ⇒ Object
Generates a string for a U.S.
-
#street_address ⇒ Object
Generates a string for a street address with a number and street.
Instance Method Details
#city ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cryptozoologist/generator.rb', line 78 def city exclude = Cryptozoologist.configuration.exclude cities_words = Cryptozoologist::Cities::Words.list cities_terminologies = Cryptozoologist::Cities::Terminologies.list words_formatted = exclude.include?(:words) ? [] : cities_words.map { |word| " #{word.capitalize}" } terminologies = exclude.include?(:terminologies) ? [] : cities_terminologies city_labels = words_formatted + terminologies "#{one_word_animals.sample.capitalize}#{city_labels.sample}" end |
#full_name ⇒ Object
89 90 91 92 93 94 |
# File 'lib/cryptozoologist/generator.rb', line 89 def full_name first_name = Cryptozoologist::Dictionaries::People::FirstName.list.sample last_name = Cryptozoologist::Dictionaries::People::LastName.list.sample "#{first_name} #{last_name}#{one_word_animals.sample.capitalize}" end |
#lorem(sentence_count) ⇒ Object
Generates sentence_count sentences, ranging in length from 10-16 words, using the dictionaries from your config.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cryptozoologist/generator.rb', line 8 def lorem(sentence_count) sentences = [] order = Cryptozoologist.configuration.order sentence_count.times do words = [] length = rand(9..16) per_dictionary = length / order.length order.each do |library| words += Dictionary.send(library).sample(per_dictionary) words << Dictionary.filler.sample end words.shuffle! sentence = words.join(" ") sentence.capitalize! sentence << Dictionary.punctuation.sample sentences << sentence end sentences.join(" ") end |
#random ⇒ Object
Generates a string using the dictionaries and delimiter from your config.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cryptozoologist/generator.rb', line 33 def random string = "" order = Cryptozoologist.configuration.order order.each do |library| word = Dictionary.send(library).sample compound_word = word.split(' ').join(Cryptozoologist.configuration.delimiter) string += "#{compound_word}" unless library == Cryptozoologist.configuration.order.last string += "#{Cryptozoologist.configuration.delimiter}" end end string end |
#state(desired_state, desired_library, desired_replace_index) ⇒ Object
Generates a string for a U.S. state name which is partially replaced by alliterative words from other dictionaries (e.g. “Oregon” can become “Oregoose” or “Orabbit”) Does not respect config exclusions Note: optional arguments desired_library is an String containing the single replacement word of your choice desired_state is a String of the specific state name of your choice {}‘desired_replace_index` is an integer that allows you to specify whether the first or second word will be replaced, or in the case of a one-word state - which letter is replaced
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cryptozoologist/generator.rb', line 66 def state(desired_state, desired_library, desired_replace_index) libraries = desired_library || [:animals, :clothing, :colors] state_name = desired_state || Dictionary.states.sample has_two_words = state_name.index(" ") if has_two_words handle_two_word(state_name, libraries, desired_replace_index) else handle_one_word(state_name, libraries, desired_replace_index) end end |
#street_address ⇒ Object
Generates a string for a street address with a number and street. Only uses animal dictionaries and does not respect config exclusions.
52 53 54 55 56 57 |
# File 'lib/cryptozoologist/generator.rb', line 52 def street_address number = rand(1..9000) street = Dictionary.animals.sample street = street.split(" ").map! {|word| word.capitalize! }.join(" ") "#{number} #{street} #{Dictionary.addresses.sample}" end |