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
true
if 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
parent
for the real nodenode
. -
#is_in_tree_of_files? ⇒ Boolean
Return
true
if 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
.
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
#children ⇒ Object (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 |
#node ⇒ Object (readonly)
The encapsulated node.
21 22 23 |
# File 'lib/webgen/tag/menu.rb', line 21 def node @node end |
#parent ⇒ Object (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.
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_list ⇒ Object
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 |