Class: Structured::ParserStack
- Inherits:
-
Object
- Object
- Structured::ParserStack
- Defined in:
- lib/structured/parser_stack.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type:, element:, parent:) ⇒ ParserStack
constructor
A new instance of ParserStack.
- #path ⇒ Object (also: #to_s)
- #push(element, type) ⇒ Object
- #root ⇒ Object
- #root? ⇒ Boolean
Constructor Details
#initialize(type:, element:, parent:) ⇒ ParserStack
Returns a new instance of ParserStack.
5 6 7 8 9 |
# File 'lib/structured/parser_stack.rb', line 5 def initialize(type:, element:, parent:) @type = type @element = element @parent = parent end |
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
3 4 5 |
# File 'lib/structured/parser_stack.rb', line 3 def element @element end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/structured/parser_stack.rb', line 3 def parent @parent end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/structured/parser_stack.rb', line 3 def type @type end |
Class Method Details
.root(type) ⇒ Object
36 37 38 |
# File 'lib/structured/parser_stack.rb', line 36 def self.root(type) new(type: type, element: nil, parent: nil) end |
Instance Method Details
#path ⇒ Object Also known as: to_s
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/structured/parser_stack.rb', line 15 def path if root? type.type_name elsif element.nil? # abtract elements like Step use no element, they just forward parsing to a concrete type. parent.path else parent.path + parent.type.format_stack_frame_element(element) end end |
#push(element, type) ⇒ Object
11 12 13 |
# File 'lib/structured/parser_stack.rb', line 11 def push(element, type) self.class.new(type: type, element: element, parent: self) end |
#root ⇒ Object
32 33 34 |
# File 'lib/structured/parser_stack.rb', line 32 def root root? ? self : parent.root end |
#root? ⇒ Boolean
28 29 30 |
# File 'lib/structured/parser_stack.rb', line 28 def root? parent.nil? end |