Class: Packr::Words
- Inherits:
-
Object
- Object
- Packr::Words
- Defined in:
- lib/packr/words.rb
Defined Under Namespace
Classes: Item
Constant Summary collapse
- WORDS =
/\w+/
Instance Attribute Summary collapse
-
#words ⇒ Object
Returns the value of attribute words.
Instance Method Summary collapse
- #add(word) ⇒ Object
- #get(word) ⇒ Object
- #has?(word) ⇒ Boolean
-
#initialize(script) ⇒ Words
constructor
A new instance of Words.
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#words ⇒ Object
Returns the value of attribute words.
5 6 7 |
# File 'lib/packr/words.rb', line 5 def words @words end |
Instance Method Details
#add(word) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/packr/words.rb', line 12 def add(word) @words ||= [] @words << (stored_word = Item.new(word)) unless stored_word = get(word) word = stored_word word.count = word.count + 1 word end |
#get(word) ⇒ Object
20 21 22 |
# File 'lib/packr/words.rb', line 20 def get(word) @words.find { |w| w.word == word.to_s } end |
#has?(word) ⇒ Boolean
24 25 26 |
# File 'lib/packr/words.rb', line 24 def has?(word) !!(get word) end |
#size ⇒ Object
28 29 30 |
# File 'lib/packr/words.rb', line 28 def size @words.size end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/packr/words.rb', line 32 def to_s @words.join("|") end |