Module: RandomWord
- Defined in:
- lib/random_word.rb,
lib/random_word/version.rb
Overview
Provides random, non-repeating enumerators of a large list of english words. For example“
RandomWord.adjs.next #=> "strengthened"
Defined Under Namespace
Modules: EachRandomly
Constant Summary collapse
- VERSION =
'2.1.1'.freeze
Class Attribute Summary collapse
-
.word_list ⇒ Object
Returns the value of attribute word_list.
Class Method Summary collapse
-
.adjs(opts = {}) ⇒ Enumerator
Random adjective enumerator.
-
.enumerator(word_list, list_of_regexs_or_strings_to_exclude = []) ⇒ Object
Create a random, non-repeating enumerator for a list of words (or anything really).
- .exclude_list ⇒ Object
-
.nouns(opts = {}) ⇒ Enumerator
Random noun enumerator.
-
.phrases ⇒ Enumerator
Random phrase enumerator.
Class Attribute Details
.word_list ⇒ Object
Returns the value of attribute word_list.
68 69 70 |
# File 'lib/random_word.rb', line 68 def word_list @word_list end |
Class Method Details
.adjs(opts = {}) ⇒ Enumerator
Returns Random adjective enumerator.
82 83 84 85 86 |
# File 'lib/random_word.rb', line 82 def adjs(opts = {}) @adjs ||= enumerator(load_word_list("adjs.json"), exclude_list) word_list.set_constraints(opts) @adjs end |
.enumerator(word_list, list_of_regexs_or_strings_to_exclude = []) ⇒ Object
Create a random, non-repeating enumerator for a list of words (or anything really).
101 102 103 104 105 106 |
# File 'lib/random_word.rb', line 101 def enumerator(word_list, list_of_regexs_or_strings_to_exclude = []) @word_list = word_list word_list.extend EachRandomly word_list.random_word_exclude_list = list_of_regexs_or_strings_to_exclude word_list.enum_for(:each_randomly) end |
.exclude_list ⇒ Object
70 71 72 |
# File 'lib/random_word.rb', line 70 def exclude_list @exclude_list ||= [] end |
.nouns(opts = {}) ⇒ Enumerator
Returns Random noun enumerator.
75 76 77 78 79 |
# File 'lib/random_word.rb', line 75 def nouns(opts = {}) @nouns ||= enumerator(load_word_list("nouns.json"), exclude_list) word_list.set_constraints(opts) @nouns end |
.phrases ⇒ Enumerator
Returns Random phrase enumerator.
89 90 91 92 93 94 95 96 97 |
# File 'lib/random_word.rb', line 89 def phrases @phrases ||= (Class.new do def each() while true yield "#{RandomWord.adjs.next} #{RandomWord.nouns.next}" end end end.new).to_enum end |