Class: Webgen::Tag::Menu::MenuNode
- Inherits:
-
Object
- Object
- Webgen::Tag::Menu::MenuNode
- Defined in:
- lib/webgen/tag/menu.rb
Overview
Special menu node class. It encapsulates the original node for later access.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Array of the child nodes.
-
#is_in_tree_of_files ⇒ Object
writeonly
Set to
trueif the menu node is in the tree of files. -
#node ⇒ Object
readonly
The encapsulated node.
-
#parent ⇒ Object
readonly
The parent node.
Instance Method Summary collapse
-
#initialize(parent, node) ⇒ MenuNode
constructor
Create a new menu node under
parentfor the real nodenode. -
#is_in_tree_of_files? ⇒ Boolean
Return
trueif the menu node is in the menu tree of only files. -
#sort! ⇒ Object
Sort recursively all children of the node using the wrapped nodes.
-
#to_lcn_list ⇒ Object
Return the menu tree under the node as nested list of alcn values.
Constructor Details
#initialize(parent, node) ⇒ MenuNode
Create a new menu node under parent for the real node node.
28 29 30 31 32 |
# File 'lib/webgen/tag/menu.rb', line 28 def initialize(parent, node) @parent = parent @node = node @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Array of the child nodes.
16 17 18 |
# File 'lib/webgen/tag/menu.rb', line 16 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.
25 26 27 |
# File 'lib/webgen/tag/menu.rb', line 25 def is_in_tree_of_files=(value) @is_in_tree_of_files = value end |
#node ⇒ Object (readonly)
The encapsulated node.
22 23 24 |
# File 'lib/webgen/tag/menu.rb', line 22 def node @node end |
#parent ⇒ Object (readonly)
The parent node.
19 20 21 |
# File 'lib/webgen/tag/menu.rb', line 19 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.
35 36 37 |
# File 'lib/webgen/tag/menu.rb', line 35 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.
40 41 42 43 44 |
# File 'lib/webgen/tag/menu.rb', line 40 def sort! self.children.sort! {|a,b| a.node <=> b.node} self.children.each {|child| child.sort!} self end |
#to_lcn_list ⇒ Object
Return the menu tree under the node as nested list of alcn values.
47 48 49 |
# File 'lib/webgen/tag/menu.rb', line 47 def to_lcn_list self.children.inject([]) {|temp, n| temp << n.node.absolute_lcn; temp += ((t = n.to_lcn_list).empty? ? [] : [t]) } end |