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.



25
26
27
28
29
# File 'lib/webgen/tag/menu.rb', line 25

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

Instance Attribute Details

#childrenObject (readonly)

Array of the child nodes.



13
14
15
# File 'lib/webgen/tag/menu.rb', line 13

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.



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

def is_in_tree_of_files=(value)
  @is_in_tree_of_files = value
end

#nodeObject (readonly)

The encapsulated node.



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

def node
  @node
end

#parentObject (readonly)

The parent node.



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

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)


32
33
34
# File 'lib/webgen/tag/menu.rb', line 32

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.



37
38
39
40
41
# File 'lib/webgen/tag/menu.rb', line 37

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.



44
45
46
# File 'lib/webgen/tag/menu.rb', line 44

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