Class: CWG::Words
- Inherits:
-
Object
show all
- Includes:
- TextHelpers
- Defined in:
- /Users/martyn/cw/cw_clone/lib/cw/words.rb
Overview
class Words deals with words
Instance Method Summary
(collapse)
#cw_chars, #exclude_non_cw_chars, #letter_group, #number_group
Instance Method Details
- (Object) add(words)
42
43
44
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 42
def add words
@words = words
end
|
- (Object) all
34
35
36
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 34
def all
@words
end
|
- (Object) alphabet(options = {reverse: nil})
161
162
163
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 161
def alphabet(options = {reverse: nil})
@words = [Alphabet.new(options).generate]
end
|
- (Object) assign(words)
130
131
132
133
134
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 130
def assign(words)
words.kind_of?(String) ?
@words = words.split(/\s+/) :
@words = words
end
|
- (Object) beginning_with
62
63
64
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 62
def beginning_with
letter_filter(:beginning_with, Params.begin)
end
|
- (Object) beginning_with_letter(letr)
54
55
56
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 54
def beginning_with_letter(letr)
@words.select{|wrd| wrd.start_with?(letr)}
end
|
- (Object) collect_words
136
137
138
139
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 136
def collect_words
@words.each{ |word| ' ' + word }.
collect{|wrd| wrd}.join(' ')
end
|
- (Object) containing
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 95
def containing
letters = Params.containing
letters.flatten.collect do |letr|
if letr.class == Range
letters = letr.collect { |let| let }
end
end
lets = letters.flatten.join('').split("")
found, temp, @words = false, @words, []
temp.each do |wrd|
wrd_lets = wrd.split("")
wrd_lets.each do |wrd_let|
if lets.include?(wrd_let)
found = true
else
found = false
break
end
end
if found
@words.push wrd
end
end
@words
end
|
- (Object) count(word_count)
87
88
89
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 87
def count word_count
@words = @words.take(word_count)
end
|
- (Object) double_words
17
18
19
20
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 17
def double_words
@words.collect! {|wrd| [wrd] * 2}
@words.flatten!
end
|
- (Object) ending_with
66
67
68
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 66
def ending_with
letter_filter(:ending_with, Params.end)
end
|
- (Object) ending_with_letter(letr)
58
59
60
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 58
def ending_with_letter(letr)
@words.select{|wrd| wrd.end_with?(letr)}
end
|
- (Boolean) exist?
46
47
48
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 46
def exist?
@words
end
|
- (Object) including
70
71
72
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 70
def including
letter_filter(:including, Params.including)
end
|
- (Object) including_letter(letr)
91
92
93
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 91
def including_letter(letr)
@words.select{|wrd| wrd.include?(letr)}
end
|
- (Object) letter_filter(option, letters)
74
75
76
77
78
79
80
81
82
83
84
85
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 74
def letter_filter(option,letters)
method_name = option.to_s + "_letter"
@words = letters.flatten.collect do |letr|
if letr.class == Range
letr.collect do |let|
self.send(method_name, let)
end
else
self.send(method_name, letr)
end
end.flatten
end
|
- (Object) letters_numbers
145
146
147
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 145
def letters_numbers
letter_group.push( * number_group)
end
|
- (Object) load(filename)
11
12
13
14
15
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 11
def load(filename)
File.open(filename, 'r') do |file|
@words = file.read.split
end
end
|
- (Object) no_longer_than(max)
122
123
124
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 122
def no_longer_than(max)
@words = @words.select{|wrd| wrd.size <= max}
end
|
- (Object) no_shorter_than(min)
126
127
128
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 126
def no_shorter_than(min)
@words = @words.select{|wrd| wrd.size >= min}
end
|
- (Object) numbers(options = {reverse: nil})
165
166
167
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 165
def numbers(options = {reverse: nil})
@words = [Numbers.new(options).generate]
end
|
- (Object) numbers_spoken
169
170
171
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 169
def numbers_spoken()
end
|
- (Object) random_letters(options = {})
149
150
151
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 149
def random_letters(options = {})
@words = Randomize.new(options, letter_group).generate
end
|
- (Object) random_letters_numbers(options = {})
157
158
159
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 157
def random_letters_numbers(options = {})
@words = Randomize.new(options, letters_numbers.shuffle).generate
end
|
- (Object) random_numbers(options = {})
153
154
155
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 153
def random_numbers(options = {})
@words = Randomize.new(options, number_group).generate
end
|
- (Object) repeat(multiplier)
22
23
24
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 22
def repeat multiplier
@words *= multiplier + 1
end
|
- (Object) reverse
141
142
143
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 141
def reverse
@words.reverse!
end
|
- (Object) shuffle
26
27
28
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 26
def shuffle
@words.shuffle!
end
|
- (Object) to_array
30
31
32
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 30
def to_array
@words
end
|
- (Object) to_s
38
39
40
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 38
def to_s
@words.join(' ')
end
|
- (Object) word_size(size)
50
51
52
|
# File '/Users/martyn/cw/cw_clone/lib/cw/words.rb', line 50
def word_size(size)
@words = @words.select{|wrd| wrd.size == size}
end
|