Class: GraphBuilder::Base
- Inherits:
-
Object
- Object
- GraphBuilder::Base
- Defined in:
- lib/graph_builder.rb
Overview
implements an AND/OR tree An Branch represents a branch An Chain represents a chain A Leaf contains a thing
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #debug(&proc) ⇒ Object
- #depth ⇒ Object
- #dump(recursive = true) ⇒ Object
- #empty? ⇒ Boolean
- #indent ⇒ Object
-
#initialize(parent, opts = {}) ⇒ Base
constructor
A new instance of Base.
- #process ⇒ Object
Constructor Details
#initialize(parent, opts = {}) ⇒ Base
Returns a new instance of Base.
13 14 15 |
# File 'lib/graph_builder.rb', line 13 def initialize parent, opts = {} @parent, @opts, @children = parent, opts, [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
11 12 13 |
# File 'lib/graph_builder.rb', line 11 def children @children end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
11 12 13 |
# File 'lib/graph_builder.rb', line 11 def opts @opts end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
11 12 13 |
# File 'lib/graph_builder.rb', line 11 def parent @parent end |
Instance Method Details
#ancestors ⇒ Object
33 |
# File 'lib/graph_builder.rb', line 33 def ancestors; parent ? parent.ancestors << parent : []; end |
#debug(&proc) ⇒ Object
25 26 27 28 29 |
# File 'lib/graph_builder.rb', line 25 def debug &proc DEBUG or return false puts indent + proc.call true end |
#depth ⇒ Object
32 |
# File 'lib/graph_builder.rb', line 32 def depth; ancestors.count; end |
#dump(recursive = true) ⇒ Object
20 21 22 23 |
# File 'lib/graph_builder.rb', line 20 def dump recursive = true debug{self.to_s} or return false children.each{|c|c.dump(recursive)} if recursive end |
#empty? ⇒ Boolean
18 |
# File 'lib/graph_builder.rb', line 18 def empty?; children.all? &:empty?; end |
#indent ⇒ Object
31 |
# File 'lib/graph_builder.rb', line 31 def indent; " " * depth; end |
#process ⇒ Object
17 |
# File 'lib/graph_builder.rb', line 17 def process; children.each &:process; end |