Class: Lolita::Menu::NestedTree::BranchBuilder
- Inherits:
-
Object
- Object
- Lolita::Menu::NestedTree::BranchBuilder
- Defined in:
- lib/lolita-menu/nested_tree/branch_builder.rb
Constant Summary collapse
- ROOT =
"root"
- NONE =
"none"
Instance Method Summary collapse
- #attribute_value_pairs ⇒ Object
- #attribute_value_pairs_hash ⇒ Object
-
#initialize(root, attributes) ⇒ BranchBuilder
constructor
A new instance of BranchBuilder.
- #root? ⇒ Boolean
- #value_for(attribute) ⇒ Object
Constructor Details
#initialize(root, attributes) ⇒ BranchBuilder
Returns a new instance of BranchBuilder.
9 10 11 12 13 14 15 |
# File 'lib/lolita-menu/nested_tree/branch_builder.rb', line 9 def initialize(root, attributes) @root = root @attributes = {} (attributes || {}).each do |key,value| @attributes[key.to_sym] = value end end |
Instance Method Details
#attribute_value_pairs ⇒ Object
25 26 27 28 29 |
# File 'lib/lolita-menu/nested_tree/branch_builder.rb', line 25 def attribute_value_pairs @attributes.map do |attr, value| [mapping[attr], convert(value)] end end |
#attribute_value_pairs_hash ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/lolita-menu/nested_tree/branch_builder.rb', line 31 def attribute_value_pairs_hash hash = {} attribute_value_pairs.each do |pair| next if pair[0] == :item_id hash[pair[0]] = pair[1] end hash end |
#root? ⇒ Boolean
17 18 19 |
# File 'lib/lolita-menu/nested_tree/branch_builder.rb', line 17 def root? @attributes[:item_id] == "root" end |
#value_for(attribute) ⇒ Object
21 22 23 |
# File 'lib/lolita-menu/nested_tree/branch_builder.rb', line 21 def value_for(attribute) convert(@attributes[attribute.to_sym]) end |