Class: PerfectTOML::Parser::Node
- Inherits:
-
Object
- Object
- PerfectTOML::Parser::Node
- Defined in:
- lib/perfect_toml.rb
Overview
object builder
Constant Summary collapse
- Terminal =
Node.new(:defined_as_value, nil)
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, parent) ⇒ Node
constructor
This is an internal data structure to create a Ruby object from TOML.
- #path ⇒ Object
Constructor Details
#initialize(type, parent) ⇒ Node
This is an internal data structure to create a Ruby object from TOML. A node corresponds to a table in TOML.
There are five node types:
- declared
Declared as a table by a dotted-key header, but not defined yet. This type may be changed to "1. defined_by_header".
Example 1: "a" and "a.b" of "[a.b.c]"
Example 2: "a" and "a.b" of "[[a.b.c]]".
- defined_by_header
Defined as a table by a header. This type is final.
Example: "a.b.c" of "[a.b.c]"
- defined_by_dot
Defined as a table by a dotted-key value definition. This type is final.
Example: "a" and "a.b" of "a.b.c = val"
Note: we need to distinguish between defined_by_header and
defined_by_dot because defined_by_dot can modify a table of
defined_by_dot:
a.b.c=1 # define "a.b" as defined_by_dot
a.b.d=2 # able to modify "a.b" (add "d" to "a.b")
but cannot modify a table of defined_by_header:
[a.b] # define "a.b" as defined_by_header
c=1
[a]
b.d=2 # unable to modify "a.b"
- defined_as_array
Defined as an array of tables. This type is final, but this node may be replaced with a new element of the array. A node has a reference to the last table in the array.
Example: "a.b.c" of "[[a.b.c]]"
- defined_as_value
Defined as a value. This type is final.
Example: "a.b.c" of "a.b.c = val"
663 664 665 666 667 668 |
# File 'lib/perfect_toml.rb', line 663 def initialize(type, parent) @type = type @children = {} @table = {} @parent = parent end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
671 672 673 |
# File 'lib/perfect_toml.rb', line 671 def children @children end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
671 672 673 |
# File 'lib/perfect_toml.rb', line 671 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
670 671 672 |
# File 'lib/perfect_toml.rb', line 670 def type @type end |
Instance Method Details
#path ⇒ Object
675 676 677 678 679 |
# File 'lib/perfect_toml.rb', line 675 def path return [] unless @parent key, = @parent.children.find {|key, child| child == self } @parent.path + [key] end |