Class: Moka::SiteTree::TreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/lib/site_tree.rb

Direct Known Subclasses

GroupNode, PageNode, SiteNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params = {}, parent = nil) ⇒ TreeNode

Returns a new instance of TreeNode.



9
10
11
12
13
14
15
# File 'lib/commands/lib/site_tree.rb', line 9

def initialize(name, params = {}, parent = nil)
  @name = name
  @parent = parent
  @children = NodeArray.new
  @params = {"name" => @name}
  @variables = {}
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/commands/lib/site_tree.rb', line 6

def name
  @name
end

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/commands/lib/site_tree.rb', line 7

def parent
  @parent
end

Instance Method Details

#childrenObject

Returns a NodeArray object containing all the children nodes of the current node



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/commands/lib/site_tree.rb', line 18

def children
  return @children.sort do |a, b|
    if a.respond_to?(:order) and b.respond_to?(:order)
      a.send(:order) <=> b.send(:order)
    else
      if b.respond_to?(:order)
        -1
      else
        1
      end
    end
  end
end

#find_child(child_name) ⇒ Object

Returns the child node having the name equal to the string passed as argument or nil if such child does not exist



33
34
35
# File 'lib/commands/lib/site_tree.rb', line 33

def find_child(child_name)
  children.find(child_name)
end

#paramsObject

Returns a Hash containing the node’s parameters (as keys) and their respective value (as values).



48
49
50
# File 'lib/commands/lib/site_tree.rb', line 48

def params
  @params
end

#variables(include_defined_in_parent = true) ⇒ Object

Returns a Hash with the node’s defined variable names (as keys) and their respective value (as values).



38
39
40
41
42
43
44
45
# File 'lib/commands/lib/site_tree.rb', line 38

def variables(include_defined_in_parent = true)
  unless self.parent.nil? or include_defined_in_parent == false
    v = self.parent.variables
  else
    v = {}
  end
  v.merge!(@variables)
end

#vars(include_defined_in_parent = true) ⇒ Object

Alias for variables



53
54
55
# File 'lib/commands/lib/site_tree.rb', line 53

def vars(include_defined_in_parent = true)
  variables(include_defined_in_parent)
end