class CW::Words
class Words
deals with words
Public Instance Methods
add(words)
click to toggle source
# File lib/cw/words.rb, line 46 def add words @words = words end
all()
click to toggle source
# File lib/cw/words.rb, line 38 def all @words end
alphabet(options = {reverse: nil})
click to toggle source
# File lib/cw/words.rb, line 165 def alphabet(options = {reverse: nil}) @words = [Alphabet.new(options).generate] end
assign(words)
click to toggle source
# File lib/cw/words.rb, line 134 def assign(words) words.kind_of?(String) ? @words = words.split(/\s+/) : @words = words end
beginning_with()
click to toggle source
# File lib/cw/words.rb, line 66 def beginning_with letter_filter(:beginning_with, Cfg.config["begin"]) end
beginning_with_letter(letr)
click to toggle source
# File lib/cw/words.rb, line 58 def beginning_with_letter(letr) @words.select{|wrd| wrd.start_with?(letr)} end
collect_words()
click to toggle source
# File lib/cw/words.rb, line 140 def collect_words @words.each{ |word| ' ' + word }. collect{ |wrd| wrd }.join(' ') end
containing()
click to toggle source
# File lib/cw/words.rb, line 99 def containing letters = Cfg.config["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
count(word_count)
click to toggle source
# File lib/cw/words.rb, line 91 def count(word_count) @words = @words.take(word_count.to_i) end
double_words()
click to toggle source
# File lib/cw/words.rb, line 21 def double_words @words.collect! {|wrd| [wrd] * 2} @words.flatten! end
ending_with()
click to toggle source
# File lib/cw/words.rb, line 70 def ending_with letter_filter(:ending_with, Cfg.config["end"]) end
ending_with_letter(letr)
click to toggle source
# File lib/cw/words.rb, line 62 def ending_with_letter(letr) @words.select{|wrd| wrd.end_with?(letr)} end
exist?()
click to toggle source
# File lib/cw/words.rb, line 50 def exist? @words end
including()
click to toggle source
# File lib/cw/words.rb, line 74 def including letter_filter(:including, Cfg.config["including"]) end
including_letter(letr)
click to toggle source
# File lib/cw/words.rb, line 95 def including_letter(letr) @words.select{|wrd| wrd.include?(letr)} end
letter_filter(option,letters)
click to toggle source
# File lib/cw/words.rb, line 78 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
letters_numbers()
click to toggle source
# File lib/cw/words.rb, line 149 def letters_numbers @words = letter_group.push( * number_group) end
load(args)
click to toggle source
# File lib/cw/words.rb, line 11 def load args @words = CommonWords.new.read(args) end
load_text(filename)
click to toggle source
# File lib/cw/words.rb, line 15 def load_text(filename) File.open(filename, 'r') do |file| @words = file.read.split end end
no_longer_than(max)
click to toggle source
# File lib/cw/words.rb, line 126 def no_longer_than(max) @words = @words.select{|wrd| wrd.size <= max} end
no_shorter_than(min)
click to toggle source
# File lib/cw/words.rb, line 130 def no_shorter_than(min) @words = @words.select{|wrd| wrd.size >= min} end
numbers(options = {reverse: nil})
click to toggle source
# File lib/cw/words.rb, line 169 def numbers(options = {reverse: nil}) @words = [Numbers.new(options).generate] end
numbers_spoken()
click to toggle source
# File lib/cw/words.rb, line 173 def numbers_spoken() end
random_letters(options = {})
click to toggle source
# File lib/cw/words.rb, line 153 def random_letters(options = {}) @words = Randomize.new(options, letter_group).generate end
random_letters_numbers(options = {})
click to toggle source
# File lib/cw/words.rb, line 161 def random_letters_numbers(options = {}) @words = Randomize.new(options, letters_numbers.shuffle).generate end
random_numbers(options = {})
click to toggle source
# File lib/cw/words.rb, line 157 def random_numbers(options = {}) @words = Randomize.new(options, number_group).generate end
repeat(multiplier)
click to toggle source
# File lib/cw/words.rb, line 26 def repeat multiplier @words *= multiplier + 1 end
reverse()
click to toggle source
# File lib/cw/words.rb, line 145 def reverse @words.reverse! end
shuffle()
click to toggle source
# File lib/cw/words.rb, line 30 def shuffle @words.shuffle! end
to_array()
click to toggle source
# File lib/cw/words.rb, line 34 def to_array @words end
to_s()
click to toggle source
# File lib/cw/words.rb, line 42 def to_s @words.join(' ') end
word_size(size)
click to toggle source
# File lib/cw/words.rb, line 54 def word_size(size) @words = @words.select{|wrd| wrd.size == size} end