Class: Rley::SPPF::CompositeNode
- Defined in:
- lib/rley/sppf/composite_node.rb,
lib/rley/parse_forest_visitor.rb
Overview
Monkey-patching
Direct Known Subclasses
Instance Attribute Summary collapse
-
#signatures ⇒ Object
readonly
Returns the value of attribute signatures.
-
#subnodes ⇒ Array<SPFFNode>
(also: #children)
readonly
Sub-nodes (children).
Attributes inherited from SPPFNode
Instance Method Summary collapse
-
#add_edge_signatures(prime_enumerator) ⇒ Object
Associate for each edge between this node and each subnode an unique prime number (called a signature).
-
#add_subnode(aSubnode) ⇒ Object
Add a sub-node (child) to this one.
-
#initialize(aRange) ⇒ CompositeNode
constructor
Constructor.
-
#inspect ⇒ String
A text representation of the node.
- #key ⇒ String
- #signature_exist? ⇒ Boolean
Methods inherited from SPPFNode
Constructor Details
#initialize(aRange) ⇒ CompositeNode
Constructor
17 18 19 20 |
# File 'lib/rley/sppf/composite_node.rb', line 17 def initialize(aRange) super(aRange) @subnodes = [] end |
Instance Attribute Details
#signatures ⇒ Object (readonly)
Returns the value of attribute signatures.
10 11 12 |
# File 'lib/rley/parse_forest_visitor.rb', line 10 def signatures @signatures end |
#subnodes ⇒ Array<SPFFNode> (readonly) Also known as: children
Returns Sub-nodes (children).
11 12 13 |
# File 'lib/rley/sppf/composite_node.rb', line 11 def subnodes @subnodes end |
Instance Method Details
#add_edge_signatures(prime_enumerator) ⇒ Object
Associate for each edge between this node and each subnode an unique prime number (called a signature).
14 15 16 |
# File 'lib/rley/parse_forest_visitor.rb', line 14 def add_edge_signatures(prime_enumerator) @signatures = subnodes.map { |_| prime_enumerator.next } end |
#add_subnode(aSubnode) ⇒ Object
Add a sub-node (child) to this one.
24 25 26 |
# File 'lib/rley/sppf/composite_node.rb', line 24 def add_subnode(aSubnode) subnodes.unshift(aSubnode) end |
#inspect ⇒ String
Returns a text representation of the node.
29 30 31 |
# File 'lib/rley/sppf/composite_node.rb', line 29 def inspect key end |
#key ⇒ String
34 35 36 |
# File 'lib/rley/sppf/composite_node.rb', line 34 def key @key ||= to_string(0) end |
#signature_exist? ⇒ Boolean
18 19 20 |
# File 'lib/rley/parse_forest_visitor.rb', line 18 def signature_exist? !@signatures.nil? end |