Class: HybridForest::Trees::BinaryNode

Inherits:
Object
  • Object
show all
Defined in:
lib/hybridforest/trees/nodes/binary_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test, true_branch, false_branch) ⇒ BinaryNode

Returns a new instance of BinaryNode.



8
9
10
11
12
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 8

def initialize(test, true_branch, false_branch)
  @test = test
  @true_branch = true_branch
  @false_branch = false_branch
end

Instance Attribute Details

#false_branchObject (readonly)

Returns the value of attribute false_branch.



6
7
8
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 6

def false_branch
  @false_branch
end

#testObject (readonly)

Returns the value of attribute test.



6
7
8
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 6

def test
  @test
end

#true_branchObject (readonly)

Returns the value of attribute true_branch.



6
7
8
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 6

def true_branch
  @true_branch
end

Instance Method Details

#branch_for(instance) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 14

def branch_for(instance)
  if @test.passed_by? instance
    @true_branch
  else
    @false_branch
  end
end

#classify(instance) ⇒ Object



22
23
24
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 22

def classify(instance)
  branch_for(instance).classify(instance)
end


26
27
28
29
30
31
32
33
34
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 26

def print_string(spacing = "")
  print spacing
  puts "#{@test} True"
  @true_branch.print_string(spacing + "  ")

  print spacing
  puts "#{@test} False"
  @false_branch.print_string(spacing + "  ")
end