Class: RubySGF::SGF::Node
- Inherits:
-
Object
- Object
- RubySGF::SGF::Node
- Defined in:
- lib/sgf/node.rb
Overview
– this class is partially inspired by code written by Stefan Rusterholz, stefan.rusterholz <AT> gmail <DOT> com ++
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
- #<<(node) ⇒ Object
- #[](index) ⇒ Object
-
#initialize(parent, properties = []) ⇒ Node
constructor
A new instance of Node.
- #leaf? ⇒ Boolean
- #next ⇒ Object
- #prev ⇒ Object
- #root? ⇒ Boolean
- #to_s ⇒ Object
- #write_tree(string = "") ⇒ Object
Constructor Details
#initialize(parent, properties = []) ⇒ Node
Returns a new instance of Node.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sgf/node.rb', line 17 def initialize(parent, properties = []) @parent = parent @properties = properties @children = [] @parent << self if parent if parent @number = parent.number + 1 else @number = 0 end end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
14 15 16 |
# File 'lib/sgf/node.rb', line 14 def children @children end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
14 15 16 |
# File 'lib/sgf/node.rb', line 14 def number @number end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
14 15 16 |
# File 'lib/sgf/node.rb', line 14 def parent @parent end |
#properties ⇒ Object
Returns the value of attribute properties.
15 16 17 |
# File 'lib/sgf/node.rb', line 15 def properties @properties end |
Instance Method Details
#<<(node) ⇒ Object
43 44 45 |
# File 'lib/sgf/node.rb', line 43 def <<(node) @children << node end |
#[](index) ⇒ Object
39 40 41 |
# File 'lib/sgf/node.rb', line 39 def [](index) @children[index] end |
#leaf? ⇒ Boolean
47 48 49 |
# File 'lib/sgf/node.rb', line 47 def leaf? @children.empty? end |
#next ⇒ Object
35 36 37 |
# File 'lib/sgf/node.rb', line 35 def next @children[0] end |
#prev ⇒ Object
31 32 33 |
# File 'lib/sgf/node.rb', line 31 def prev @parent end |
#root? ⇒ Boolean
51 52 53 |
# File 'lib/sgf/node.rb', line 51 def root? @parent.nil? end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/sgf/node.rb', line 55 def to_s " "*@number << @number.to_s end |
#write_tree(string = "") ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/sgf/node.rb', line 59 def write_tree(string="") string << self.to_s << "\n" @children.each do |child| child.write_tree(string) end string end |