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.



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

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.



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

def children
  @children
end

#lineObject

Returns the value of attribute line.



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

def line
  @line
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

Instance Method Details

#==(other) ⇒ Object



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

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



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

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

#rootObject



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

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