Class: TreeObject

Inherits:
Object show all
Includes:
ParseTree, TextArray
Defined in:
lib/rwd/tree.rb

Direct Known Subclasses

SGMLObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParseTree

#parsetree

Methods included from TextArray

#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

#childrenObject

Returns the value of attribute children


66
67
68
# File 'lib/rwd/tree.rb', line 66

def children
  @children
end

#closedObject

Returns the value of attribute closed


68
69
70
# File 'lib/rwd/tree.rb', line 68

def closed
  @closed
end

#levelObject

Returns the value of attribute level


62
63
64
# File 'lib/rwd/tree.rb', line 62

def level
  @level
end

#parentObject

Returns the value of attribute parent


64
65
66
# File 'lib/rwd/tree.rb', line 64

def parent
  @parent
end

#subtypeObject

Returns the value of attribute subtype


58
59
60
# File 'lib/rwd/tree.rb', line 58

def subtype
  @subtype
end

#textObject

Returns the value of attribute text


70
71
72
# File 'lib/rwd/tree.rb', line 70

def text
  @text
end

#upordownObject

Returns the value of attribute upordown


60
61
62
# File 'lib/rwd/tree.rb', line 60

def upordown
  @upordown
end

#visibleObject

Returns the value of attribute visible


72
73
74
# File 'lib/rwd/tree.rb', line 72

def visible
  @visible
end

Instance Method Details

#inspectObject


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