Class: Mappum::MapServer::StrTree

Inherits:
Object
  • Object
show all
Defined in:
lib/mappum/mapserver/mapgraph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, level, root) ⇒ StrTree

Returns a new instance of StrTree.



167
168
169
170
171
# File 'lib/mappum/mapserver/mapgraph.rb', line 167

def initialize(parent, level, root)
  @parent=parent  if level > -1
  root << self if level == -1
  @parent.add(self, level) unless @parent.nil?
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



166
167
168
# File 'lib/mappum/mapserver/mapgraph.rb', line 166

def children
  @children
end

#lineObject

Returns the value of attribute line.



166
167
168
# File 'lib/mappum/mapserver/mapgraph.rb', line 166

def line
  @line
end

#nameObject

Returns the value of attribute name.



166
167
168
# File 'lib/mappum/mapserver/mapgraph.rb', line 166

def name
  @name
end

#parentObject

Returns the value of attribute parent.



166
167
168
# File 'lib/mappum/mapserver/mapgraph.rb', line 166

def parent
  @parent
end

Instance Method Details

#==(other) ⇒ Object



181
182
183
184
185
186
# File 'lib/mappum/mapserver/mapgraph.rb', line 181

def ==(other)
  return false unless other.kind_of?(StrTree)
  if @line == other.line and @parent == other.parent and @children == other.children
    return true
  end
end

#add(child, level = 0) ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/mappum/mapserver/mapgraph.rb', line 173

def add(child, level=0)
  @children ||= []
  if level == 0 
    @children << child  unless @children.include?(child)
  else
    @parent.add(child, level - 1)
  end
end

#rootObject



187
188
189
190
# File 'lib/mappum/mapserver/mapgraph.rb', line 187

def root
  return parent.root unless parent.nil?
  return self         
end