Class: Basilik::Snapshot::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/basilik/snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
12
13
# File 'lib/basilik/snapshot.rb', line 7

def initialize( name )
  @name     = name
  @priority = nil
  @children = []
  @value    = nil
  @parent   = nil
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/basilik/snapshot.rb', line 5

def children
  @children
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/basilik/snapshot.rb', line 5

def name
  @name
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/basilik/snapshot.rb', line 5

def parent
  @parent
end

#priorityObject

Returns the value of attribute priority.



5
6
7
# File 'lib/basilik/snapshot.rb', line 5

def priority
  @priority
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/basilik/snapshot.rb', line 5

def value
  @value
end

Instance Method Details

#add_child(child) ⇒ Object



15
16
17
18
# File 'lib/basilik/snapshot.rb', line 15

def add_child( child )
  child.parent = self
  children << child
end

#dumpObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/basilik/snapshot.rb', line 26

def dump
  puts "#{'  '*level}#{name} [#{priority.inspect}] --#{value.inspect}"  
  children.sort_by do |c|
    if c.priority and c.priority.is_a? Integer
      "b_#{c.priority}_#{c.name}"
    elsif c.priority
      "z_#{c.priority}_#{c.name}"
    else
      "a_#{c.name}"
    end
  end.each do |c|
    c.dump
  end
end

#to_mapObject



20
21
22
23
24
# File 'lib/basilik/snapshot.rb', line 20

def to_map
  map = Map.new
  order( map )
  map
end