Class: EagleLabels::Category
- Inherits:
-
Object
- Object
- EagleLabels::Category
- Defined in:
- lib/eagle_labels/category.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #all_labels ⇒ Object
- #features ⇒ Object
-
#initialize(name, spec) ⇒ Category
constructor
A new instance of Category.
Constructor Details
#initialize(name, spec) ⇒ Category
Returns a new instance of Category.
5 6 7 8 9 |
# File 'lib/eagle_labels/category.rb', line 5 def initialize(name, spec) @name = name @code = spec['code'].to_s @features = spec['features'] || {} end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/eagle_labels/category.rb', line 3 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/eagle_labels/category.rb', line 3 def name @name end |
Instance Method Details
#all_labels ⇒ Object
15 16 17 18 19 |
# File 'lib/eagle_labels/category.rb', line 15 def all_labels features.inject([]) do |labels, feature| labels.any? ? labels.product(feature.codes) : feature.codes end.map { |l| "#{code}#{l.is_a?(String) ? l : l.flatten.join}" } end |