Class: CorrectHorseBatteryStaple::Assembler
- Inherits:
-
Object
- Object
- CorrectHorseBatteryStaple::Assembler
show all
- Includes:
- Common
- Defined in:
- lib/correct_horse_battery_staple/assembler.rb
Constant Summary
collapse
- VALID_INITIAL_CHARS =
([*'a'..'z']).map {|ls| ls[0]}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Common
#array_sample, #logger, #random_in_range, #random_number, #set_sample
Constructor Details
#initialize(parser = nil) ⇒ Assembler
Returns a new instance of Assembler.
Instance Attribute Details
#words ⇒ Object
Returns the value of attribute words.
7
8
9
|
# File 'lib/correct_horse_battery_staple/assembler.rb', line 7
def words
@words
end
|
Instance Method Details
#limit(count) ⇒ Object
34
35
36
37
|
# File 'lib/correct_horse_battery_staple/assembler.rb', line 34
def limit(count)
self.words.slice!(count..-1) if self.words.length > count
self
end
|
#randomize ⇒ Object
29
30
31
32
|
# File 'lib/correct_horse_battery_staple/assembler.rb', line 29
def randomize
self.words.shuffle!
self
end
|
#read(urls) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/correct_horse_battery_staple/assembler.rb', line 15
def read(urls)
self.words =
urls.map do |url|
@parser.parse open(url)
end.reduce(:+).
select {|wstruct| VALID_INITIAL_CHARS.include?(wstruct.word[0]) }.
inject({}) {|h, wstruct| h[wstruct.word] = wstruct; h }.
values.
sort
self
end
|