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.0.0'.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.
67 68 69 |
# File 'lib/random_word.rb', line 67 def word_list @word_list end |
Class Method Details
.adjs(opts = {}) ⇒ Enumerator
Returns Random adjective enumerator.
81 82 83 84 85 |
# File 'lib/random_word.rb', line 81 def adjs(opts = {}) @adjs ||= enumerator(load_word_list("adjs.dat"), 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).
100 101 102 103 104 105 |
# File 'lib/random_word.rb', line 100 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
69 70 71 |
# File 'lib/random_word.rb', line 69 def exclude_list @exclude_list ||= [] end |
.nouns(opts = {}) ⇒ Enumerator
Returns Random noun enumerator.
74 75 76 77 78 |
# File 'lib/random_word.rb', line 74 def nouns(opts = {}) @nouns ||= enumerator(load_word_list("nouns.dat"), exclude_list) word_list.set_constraints(opts) @nouns end |
.phrases ⇒ Enumerator
Returns Random phrase enumerator.
88 89 90 91 92 93 94 95 96 |
# File 'lib/random_word.rb', line 88 def phrases @phrases ||= Enumerator.new(Class.new do def each() while true yield "#{RandomWord.adjs.next} #{RandomWord.nouns.next}" end end end.new) end |