Class: Tomereader::Phrase

Inherits:
Object
  • Object
show all
Defined in:
lib/tomereader/phrase.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#wordsObject (readonly)

include Settings



4
5
6
# File 'lib/tomereader/phrase.rb', line 4

def words
  @words
end

Instance Method Details

#splitObject

split phrase into words

Returns:

  • Array of 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_sObject



11
12
13
# File 'lib/tomereader/phrase.rb', line 11

def to_s
  @phrase_string
end

#word_stringsObject



14
15
16
# File 'lib/tomereader/phrase.rb', line 14

def word_strings
  @phrase_string.split @word_pattern
end