Class: Arbolobra::Node
- Inherits:
-
Object
- Object
- Arbolobra::Node
- Includes:
- Comparable
- Defined in:
- lib/arbolobra/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(value, *children) ⇒ Node
constructor
A new instance of Node.
- #print(intro: "", lead: "", output: $stdout, charset: Arbolobra::CharSet::DEFAULT) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value, *children) ⇒ Node
Returns a new instance of Node.
14 15 16 17 18 19 20 21 |
# File 'lib/arbolobra/node.rb', line 14 def initialize value, *children @children = if children.size == 1 && children.first.class == Array children.first else children end @value = value end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
12 13 14 |
# File 'lib/arbolobra/node.rb', line 12 def children @children end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
11 12 13 |
# File 'lib/arbolobra/node.rb', line 11 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/arbolobra/node.rb', line 32 def <=> other cmp = value <=> other.value if cmp == 0 cmp = children <=> other.children end cmp end |
#print(intro: "", lead: "", output: $stdout, charset: Arbolobra::CharSet::DEFAULT) ⇒ Object
23 24 25 26 |
# File 'lib/arbolobra/node.rb', line 23 def print intro: "", lead: "", output: $stdout, charset: Arbolobra::CharSet::DEFAULT fmt = Formatter.new charset: charset, output: output fmt.print self, intro, lead end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/arbolobra/node.rb', line 28 def to_s "value: #{@value}, #{@children && @children.size}" end |