Class: Tomereader::Phrase
- Inherits:
-
Object
- Object
- Tomereader::Phrase
- Defined in:
- lib/tomereader/phrase.rb
Instance Attribute Summary collapse
-
#words ⇒ Object
readonly
include Settings.
Instance Method Summary collapse
-
#initialize(phrase_string) ⇒ Phrase
constructor
A new instance of Phrase.
-
#split ⇒ Object
split phrase into words.
- #to_s ⇒ Object
- #word_strings ⇒ Object
Constructor Details
#initialize(phrase_string) ⇒ Phrase
Returns a new instance of Phrase.
5 6 7 8 9 10 |
# File 'lib/tomereader/phrase.rb', line 5 def initialize(phrase_string) @phrase_string = phrase_string.strip @word_pattern = /[\s,;\"\—]+/ @words = [] #@logger = create_logger end |
Instance Attribute Details
#words ⇒ Object (readonly)
include Settings
4 5 6 |
# File 'lib/tomereader/phrase.rb', line 4 def words @words end |
Instance Method Details
#split ⇒ Object
split phrase into words
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tomereader/phrase.rb', line 19 def split return false if words.count > 0 begin word_strings.each_with_index do |word_string, position| word = yield(word_string, position) @words << word if word.is_a? Word end words.count rescue => e #@logger.warn e.message end end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/tomereader/phrase.rb', line 11 def to_s @phrase_string end |
#word_strings ⇒ Object
14 15 16 |
# File 'lib/tomereader/phrase.rb', line 14 def word_strings @phrase_string.split @word_pattern end |