Class: Webgen::Tag::Menu::MenuNode

Inherits:
Object
  • Object
show all
Defined in:
lib/webgen/tag/menu.rb

Overview

Special menu node class. It encapsulates the original node for later access.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, node) ⇒ MenuNode

Create a new menu node under parent for the real node node.



27
28
29
30
31
# File 'lib/webgen/tag/menu.rb', line 27

def initialize(parent, node)
  @parent = parent
  @node = node
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Array of the child nodes.



15
16
17
# File 'lib/webgen/tag/menu.rb', line 15

def children
  @children
end

#is_in_tree_of_files=(value) ⇒ Object (writeonly)

Set to true if the menu node is in the tree of files.



24
25
26
# File 'lib/webgen/tag/menu.rb', line 24

def is_in_tree_of_files=(value)
  @is_in_tree_of_files = value
end

#nodeObject (readonly)

The encapsulated node.



21
22
23
# File 'lib/webgen/tag/menu.rb', line 21

def node
  @node
end

#parentObject (readonly)

The parent node.



18
19
20
# File 'lib/webgen/tag/menu.rb', line 18

def parent
  @parent
end

Instance Method Details

#is_in_tree_of_files?Boolean

Return true if the menu node is in the menu tree of only files.

Returns:

  • (Boolean)


34
35
36
# File 'lib/webgen/tag/menu.rb', line 34

def is_in_tree_of_files?
  @is_in_tree_of_files
end

#sort!Object

Sort recursively all children of the node using the wrapped nodes.



39
40
41
42
43
# File 'lib/webgen/tag/menu.rb', line 39

def sort!
  self.children.sort! {|a,b| a.node <=> b.node}
  self.children.each {|child| child.sort!}
  self
end

#to_lcn_listObject

Return the menu tree under the node as nested list of alcn values.



46
47
48
# File 'lib/webgen/tag/menu.rb', line 46

def to_lcn_list
  self.children.inject([]) {|temp, n| temp << n.node.absolute_lcn; temp += ((t = n.to_lcn_list).empty? ? [] : [t]) }
end