Class: Xsdvi::Tree::Element
- Inherits:
-
Object
- Object
- Xsdvi::Tree::Element
- Defined in:
- lib/xsdvi/tree/element.rb
Overview
Represents a node in the tree structure
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #children? ⇒ Boolean
- #code ⇒ Object
- #first_child? ⇒ Boolean
- #index ⇒ Object
-
#initialize ⇒ Element
constructor
A new instance of Element.
- #last_child ⇒ Object
- #last_child? ⇒ Boolean
- #parent? ⇒ Boolean
Constructor Details
#initialize ⇒ Element
Returns a new instance of Element.
10 11 12 13 |
# File 'lib/xsdvi/tree/element.rb', line 10 def initialize @parent = nil @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
8 9 10 |
# File 'lib/xsdvi/tree/element.rb', line 8 def children @children end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/xsdvi/tree/element.rb', line 7 def parent @parent end |
Instance Method Details
#add_child(child) ⇒ Object
41 42 43 |
# File 'lib/xsdvi/tree/element.rb', line 41 def add_child(child) children << child end |
#children? ⇒ Boolean
45 46 47 |
# File 'lib/xsdvi/tree/element.rb', line 45 def children? !children.empty? end |
#code ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/xsdvi/tree/element.rb', line 49 def code buffer = [] element = self while element.parent? buffer.unshift(element.index) buffer.unshift("_") element = element.parent end buffer.unshift("_1") buffer.join end |
#first_child? ⇒ Boolean
35 36 37 38 39 |
# File 'lib/xsdvi/tree/element.rb', line 35 def first_child? return true unless parent? parent.children.first == self end |
#index ⇒ Object
15 16 17 18 19 |
# File 'lib/xsdvi/tree/element.rb', line 15 def index return 1 unless parent? parent.children.index(self) + 1 end |
#last_child ⇒ Object
25 26 27 |
# File 'lib/xsdvi/tree/element.rb', line 25 def last_child children.last end |
#last_child? ⇒ Boolean
29 30 31 32 33 |
# File 'lib/xsdvi/tree/element.rb', line 29 def last_child? return true unless parent? parent.children.last == self end |
#parent? ⇒ Boolean
21 22 23 |
# File 'lib/xsdvi/tree/element.rb', line 21 def parent? !parent.nil? end |