Module: Cryptozoologist::Generator
Instance Method Summary collapse
-
#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.
-
#street_address ⇒ Object
Generates a string for a street address with a number and street.
Instance Method Details
#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 |
#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 |