Class: Odca::Overlays::LabelOverlay::CategoryResolver
- Inherits:
-
Object
- Object
- Odca::Overlays::LabelOverlay::CategoryResolver
- Defined in:
- lib/odca/overlays/label_overlay.rb
Instance Attribute Summary collapse
-
#attr_categories ⇒ Object
readonly
Returns the value of attribute attr_categories.
-
#category_attributes ⇒ Object
readonly
Returns the value of attribute category_attributes.
-
#category_labels ⇒ Object
readonly
Returns the value of attribute category_labels.
Instance Method Summary collapse
- #call(attributes) ⇒ Object
-
#initialize ⇒ CategoryResolver
constructor
A new instance of CategoryResolver.
Constructor Details
#initialize ⇒ CategoryResolver
Returns a new instance of CategoryResolver.
43 44 45 46 47 |
# File 'lib/odca/overlays/label_overlay.rb', line 43 def initialize @attr_categories = [] @category_labels = {} @category_attributes = {} end |
Instance Attribute Details
#attr_categories ⇒ Object (readonly)
Returns the value of attribute attr_categories.
41 42 43 |
# File 'lib/odca/overlays/label_overlay.rb', line 41 def attr_categories @attr_categories end |
#category_attributes ⇒ Object (readonly)
Returns the value of attribute category_attributes.
41 42 43 |
# File 'lib/odca/overlays/label_overlay.rb', line 41 def category_attributes @category_attributes end |
#category_labels ⇒ Object (readonly)
Returns the value of attribute category_labels.
41 42 43 |
# File 'lib/odca/overlays/label_overlay.rb', line 41 def category_labels @category_labels end |
Instance Method Details
#call(attributes) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/odca/overlays/label_overlay.rb', line 49 def call(attributes) attributes.each do |attribute| next if attribute.categories.empty? categories = attribute.categories.dup category = categories.pop supercategory_numbers = [] categories.each do |supercategory| supercategory_attr = find_or_create_category_attr( supercategory_numbers, supercategory ) supercategory_numbers.push( supercategory_attr.delete('_').split('-').last ) unless attr_categories.include? supercategory_attr attr_categories.push(supercategory_attr) end category_labels[supercategory_attr] = supercategory end category_attr = find_or_create_category_attr( supercategory_numbers, category ) unless attr_categories.include? category_attr attr_categories.push(category_attr) end category_labels[category_attr] = category category_attributes[category_attr] = category_attributes .fetch(category_attr) { [] }.push(attribute.attr_name).uniq end self end |