Class: TextRazor::Phrase

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, words) ⇒ Phrase

Returns a new instance of Phrase.



7
8
9
10
# File 'lib/textrazor/phrase.rb', line 7

def initialize(params, words)
  @id    = params["id"]
  @text  = match_words(params["wordPositions"], words)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/textrazor/phrase.rb', line 5

def id
  @id
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/textrazor/phrase.rb', line 5

def text
  @text
end

Class Method Details

.create_from_hash(params, words) ⇒ Object



12
13
14
# File 'lib/textrazor/phrase.rb', line 12

def self.create_from_hash(params, words)
  new(params, words)
end

Instance Method Details

#match_words(positions, words) ⇒ Object



16
17
18
19
20
# File 'lib/textrazor/phrase.rb', line 16

def match_words(positions, words)
  phrase = []
  positions.each { |position| phrase.push words[position].token }
  phrase.join(' ')
end