Class: StringTree::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/stringtree/item.rb

Overview

Represents an individual tokenized item in a dataset, i.e. A match, its offset and its terminator node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset, match, node = nil) ⇒ Item

Create a new Item with the specifid offset,match and optionally, node.



12
13
14
15
16
# File 'lib/stringtree/item.rb', line 12

def initialize(offset, match, node = nil)
  @offset = offset
  @match = match
  @node = node
end

Instance Attribute Details

#matchObject

The match itself



7
8
9
# File 'lib/stringtree/item.rb', line 7

def match
  @match
end

#nodeObject

The terminating node of the match.



9
10
11
# File 'lib/stringtree/item.rb', line 9

def node
  @node
end

#offsetObject

The offset of the Item in the dataset, in chars



5
6
7
# File 'lib/stringtree/item.rb', line 5

def offset
  @offset
end

Instance Method Details

#match?Boolean

Returns true if this is a match.

Returns:

  • (Boolean)


19
20
21
# File 'lib/stringtree/item.rb', line 19

def match?
  @match
end

#valueObject

Returns the value of the match if not nil



24
25
26
# File 'lib/stringtree/item.rb', line 24

def value
  @node.value unless @node.nil?
end