Class: TreeObject
- Defined in:
- lib/rwd/tree.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#closed ⇒ Object
Returns the value of attribute closed.
-
#level ⇒ Object
Returns the value of attribute level.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#subtype ⇒ Object
Returns the value of attribute subtype.
-
#text ⇒ Object
Returns the value of attribute text.
-
#upordown ⇒ Object
Returns the value of attribute upordown.
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
-
#initialize(subtype = nil) ⇒ TreeObject
constructor
A new instance of TreeObject.
- #inspect ⇒ Object
- #previous(klass = [], skip = []) ⇒ Object
Methods included from ParseTree
Methods included from TextArray
Constructor Details
#initialize(subtype = nil) ⇒ TreeObject
Returns a new instance of TreeObject.
78 79 80 81 82 83 84 85 86 |
# File 'lib/rwd/tree.rb', line 78 def initialize(subtype=nil) @subtype = subtype @upordown = Same @level = nil @parent = nil @children = [] @closed = nil @visible = true end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
66 67 68 |
# File 'lib/rwd/tree.rb', line 66 def children @children end |
#closed ⇒ Object
Returns the value of attribute closed.
68 69 70 |
# File 'lib/rwd/tree.rb', line 68 def closed @closed end |
#level ⇒ Object
Returns the value of attribute level.
62 63 64 |
# File 'lib/rwd/tree.rb', line 62 def level @level end |
#parent ⇒ Object
Returns the value of attribute parent.
64 65 66 |
# File 'lib/rwd/tree.rb', line 64 def parent @parent end |
#subtype ⇒ Object
Returns the value of attribute subtype.
58 59 60 |
# File 'lib/rwd/tree.rb', line 58 def subtype @subtype end |
#text ⇒ Object
Returns the value of attribute text.
70 71 72 |
# File 'lib/rwd/tree.rb', line 70 def text @text end |
#upordown ⇒ Object
Returns the value of attribute upordown.
60 61 62 |
# File 'lib/rwd/tree.rb', line 60 def upordown @upordown end |
#visible ⇒ Object
Returns the value of attribute visible.
72 73 74 |
# File 'lib/rwd/tree.rb', line 72 def visible @visible end |
Instance Method Details
#inspect ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rwd/tree.rb', line 88 def inspect parent, children = @parent, @children @parent, @children = parent.object_id, children.collect{|obj| obj.object_id} res = " " * (level-1) + "#{self.class}(#{@subtype}) #{super}" @parent, @children = parent, children res end |
#previous(klass = [], skip = []) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rwd/tree.rb', line 100 def previous(klass=[], skip=[]) klass = [klass].flatten skip = [skip].flatten po = @parent return nil if po.nil? ch = po.children return nil if ch.nil? n = ch.index(self) return nil if n.nil? res = nil if klass.nil? n -= 1 res = ch[n] else begin n -= 1 res = ch[n] end while (klass.empty? or klass.collect{|k| ch[n-1].kind_of?(k)}.sort.uniq == [true]) \ and (skip.empty? or skip.collect{|k| ch[n-1].kind_of?(k)}.sort.uniq == [false]) end res end |