Module: NTEE
- Defined in:
- lib/ntee.rb,
lib/ntee/version.rb,
lib/ntee/search_dimension.rb
Defined Under Namespace
Classes: Category, FlatDimension, FlatDimensionValue, HierarchicalDimension, HierarchicalDimensionValue
Constant Summary
collapse
- VERSION =
"0.0.4"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.all_categories ⇒ Object
Returns the value of attribute all_categories.
90
91
92
|
# File 'lib/ntee.rb', line 90
def all_categories
@all_categories
end
|
.root_categories ⇒ Object
Returns the value of attribute root_categories.
90
91
92
|
# File 'lib/ntee.rb', line 90
def root_categories
@root_categories
end
|
Class Method Details
.add_category!(category) ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/ntee.rb', line 101
def add_category!(category)
root_categories[category.code.to_s] = category if category.parent.nil?
category.subcategories.each do |code, subcategory|
add_category!(subcategory)
end
all_categories[category.code.to_s] = category
end
|
.as_list ⇒ Object
113
114
115
|
# File 'lib/ntee.rb', line 113
def self.as_list
@as_list ||= sort_by_code(flattened_categories)
end
|
.category(cat_or_code) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/ntee.rb', line 92
def category(cat_or_code)
case cat_or_code
when NTEE::Category
cat_or_code
else
all_categories[cat_or_code.to_s]
end
end
|
.flattened_categories ⇒ Object
119
120
121
122
123
124
|
# File 'lib/ntee.rb', line 119
def self.flattened_categories
all_categories.map do |parent_category|
c = parent_category[1]
[c.to_s, c.code]
end
end
|
.sort_by_code(arr) ⇒ Object
126
127
128
|
# File 'lib/ntee.rb', line 126
def self.sort_by_code(arr)
arr.sort {|a, b| a[1] <=> b[1] }
end
|