Class: Decision

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(decider, *symbols) ⇒ Decision

Returns a new instance of Decision.



51
52
53
54
55
56
57
# File 'lib/args.rb', line 51

def initialize(decider, *symbols)
  @decider = decider
  @tree = { }
  symbols.each { |symbol|
    @tree[symbol] = Flow.new(nil)
  }
end

Instance Attribute Details

#flow ⇒ Object

Returns the value of attribute flow.



49
50
51
# File 'lib/args.rb', line 49

def flow
  @flow
end

Instance Method Details

#add(child, arg) ⇒ Object



71
72
73
# File 'lib/args.rb', line 71

def add(child, arg)
  @tree[child].add arg
end

#children ⇒ Object



67
68
69
# File 'lib/args.rb', line 67

def children
  @tree.values
end

#chosen ⇒ Object



59
60
61
62
63
64
65
# File 'lib/args.rb', line 59

def chosen
  vars = @flow.find(self)
  arr = @decider.decide(vars, @tree.keys).map { |symbol|
    @tree[symbol].root
  }
  arr
end

#to_s ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/args.rb', line 75

def to_s
  result = "branch names:"
  @tree.keys.each { |child|
    result = result + child.to_s + " "
  }
  result += "\nbranches are of classes:"
  @tree.keys.each { |child|
    result = result + @tree[child].class.to_s + " "
  }
  result
end