Class: Tomereader::Word
- Inherits:
-
Object
- Object
- Tomereader::Word
- Defined in:
- lib/tomereader/word.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#phrases ⇒ Object
readonly
Returns the value of attribute phrases.
Instance Method Summary collapse
- #add(phrase, position) ⇒ Object
- #frequency ⇒ Object
-
#initialize(word) ⇒ Word
constructor
A new instance of Word.
- #phrase_format(phrase) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(word) ⇒ Word
Returns a new instance of Word.
4 5 6 7 |
# File 'lib/tomereader/word.rb', line 4 def initialize(word) @name = word @phrases = Hash.new end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/tomereader/word.rb', line 3 def name @name end |
#phrases ⇒ Object (readonly)
Returns the value of attribute phrases.
3 4 5 |
# File 'lib/tomereader/word.rb', line 3 def phrases @phrases end |
Instance Method Details
#add(phrase, position) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/tomereader/word.rb', line 8 def add(phrase, position) if @phrases.has_key? phrase @phrases[phrase] << position else @phrases[phrase] = [position] end self end |
#frequency ⇒ Object
16 17 18 |
# File 'lib/tomereader/word.rb', line 16 def frequency @phrases.count end |
#phrase_format(phrase) ⇒ Object
19 20 21 |
# File 'lib/tomereader/word.rb', line 19 def phrase_format(phrase) {source: phrase[0].to_s, positions: phrase[1]} end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/tomereader/word.rb', line 29 def to_s "#{name} : #{@phrases.count}" end |