Class: Lolita::Menu::NestedTree::BranchBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lolita-menu/nested_tree/branch_builder.rb

Constant Summary collapse

ROOT =
"root"
NONE =
"none"

Instance Method Summary collapse

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_pairsObject



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_hashObject



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

Returns:

  • (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