Class: CW::Words

Inherits:
Object
  • Object
show all
Includes:
TextHelpers
Defined in:
lib/cw/words.rb

Overview

class Words deals with words

Instance Method Summary collapse

Methods included from TextHelpers

#cw_chars, #exclude_non_cw_chars, #letter_group, #number_group

Instance Method Details

#add(words) ⇒ Object



46
47
48
# File 'lib/cw/words.rb', line 46

def add words
  @words = words
end

#allObject



38
39
40
# File 'lib/cw/words.rb', line 38

def all
  @words
end

#alphabet(options = {reverse: nil}) ⇒ Object



165
166
167
# File 'lib/cw/words.rb', line 165

def alphabet(options = {reverse: nil})
  @words = [Alphabet.new(options).generate]
end

#assign(words) ⇒ Object



134
135
136
137
138
# File 'lib/cw/words.rb', line 134

def assign(words)
  words.kind_of?(String) ?
    @words = words.split(/\s+/) :
    @words = words
end

#beginning_withObject



66
67
68
# File 'lib/cw/words.rb', line 66

def beginning_with
  letter_filter(:beginning_with, Cfg.config["begin"])
end

#beginning_with_letter(letr) ⇒ Object



58
59
60
# File 'lib/cw/words.rb', line 58

def beginning_with_letter(letr)
  @words.select{|wrd| wrd.start_with?(letr)}
end

#collect_wordsObject



140
141
142
143
# File 'lib/cw/words.rb', line 140

def collect_words
  @words.each{ |word| ' ' + word }.
    collect{ |wrd| wrd }.join(' ')
end

#containingObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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) ⇒ Object



91
92
93
# File 'lib/cw/words.rb', line 91

def count(word_count)
  @words = @words.take(word_count.to_i)
end

#double_wordsObject



21
22
23
24
# File 'lib/cw/words.rb', line 21

def double_words
  @words.collect! {|wrd| [wrd] * 2}
  @words.flatten!
end

#ending_withObject



70
71
72
# File 'lib/cw/words.rb', line 70

def ending_with
  letter_filter(:ending_with, Cfg.config["end"])
end

#ending_with_letter(letr) ⇒ Object



62
63
64
# File 'lib/cw/words.rb', line 62

def ending_with_letter(letr)
  @words.select{|wrd| wrd.end_with?(letr)}
end

#exist?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/cw/words.rb', line 50

def exist?
  @words
end

#includingObject



74
75
76
# File 'lib/cw/words.rb', line 74

def including
  letter_filter(:including, Cfg.config["including"])
end

#including_letter(letr) ⇒ Object



95
96
97
# File 'lib/cw/words.rb', line 95

def including_letter(letr)
  @words.select{|wrd| wrd.include?(letr)}
end

#letter_filter(option, letters) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# 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_numbersObject



149
150
151
# File 'lib/cw/words.rb', line 149

def letters_numbers
  @words = letter_group.push( * number_group)
end

#load(args) ⇒ Object



11
12
13
# File 'lib/cw/words.rb', line 11

def load args
  @words = CommonWords.new.read(args)
end

#load_text(filename) ⇒ Object



15
16
17
18
19
# 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) ⇒ Object



126
127
128
# File 'lib/cw/words.rb', line 126

def no_longer_than(max)
  @words = @words.select{|wrd| wrd.size <= max}
end

#no_shorter_than(min) ⇒ Object



130
131
132
# File 'lib/cw/words.rb', line 130

def no_shorter_than(min)
  @words = @words.select{|wrd| wrd.size >= min}
end

#numbers(options = {reverse: nil}) ⇒ Object



169
170
171
# File 'lib/cw/words.rb', line 169

def numbers(options = {reverse: nil})
  @words = [Numbers.new(options).generate]
end

#numbers_spokenObject



173
174
# File 'lib/cw/words.rb', line 173

def numbers_spoken()
end

#random_letters(options = {}) ⇒ Object



153
154
155
# File 'lib/cw/words.rb', line 153

def random_letters(options = {})
  @words = Randomize.new(options, letter_group).generate
end

#random_letters_numbers(options = {}) ⇒ Object



161
162
163
# File 'lib/cw/words.rb', line 161

def random_letters_numbers(options = {})
  @words = Randomize.new(options, letters_numbers.shuffle).generate
end

#random_numbers(options = {}) ⇒ Object



157
158
159
# File 'lib/cw/words.rb', line 157

def random_numbers(options = {})
  @words = Randomize.new(options, number_group).generate
end

#repeat(multiplier) ⇒ Object



26
27
28
# File 'lib/cw/words.rb', line 26

def repeat multiplier
  @words *= multiplier + 1
end

#reverseObject



145
146
147
# File 'lib/cw/words.rb', line 145

def reverse
  @words.reverse!
end

#shuffleObject



30
31
32
# File 'lib/cw/words.rb', line 30

def shuffle
  @words.shuffle!
end

#to_arrayObject



34
35
36
# File 'lib/cw/words.rb', line 34

def to_array
  @words
end

#to_sObject



42
43
44
# File 'lib/cw/words.rb', line 42

def to_s
  @words.join(' ')
end

#word_size(size) ⇒ Object



54
55
56
# File 'lib/cw/words.rb', line 54

def word_size(size)
  @words = @words.select{|wrd| wrd.size == size}
end