Class: Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
12
13
14
15
16
# File 'lib/node.rb', line 7

def initialize(xml)
  children = xml.children
  @pred = Predicate.new(children[0])

  @decision = xml.attribute('score').to_s

  return if children.count == 1
  @left = Node.new(children[1]) if children[1]
  @right = Node.new(children[2]) if children[2]
end

Instance Attribute Details

#decisionObject (readonly)

Returns the value of attribute decision.



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

def decision
  @decision
end

#leftObject (readonly)

Returns the value of attribute left.



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

def left
  @left
end

#predObject (readonly)

Returns the value of attribute pred.



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

def pred
  @pred
end

#rightObject (readonly)

Returns the value of attribute right.



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

def right
  @right
end

Instance Method Details

#true?(features) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/node.rb', line 18

def true?(features)
  @pred.nil? || @pred.true?(features)
end