Class: EagleLabels::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/eagle_labels/category.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/eagle_labels/category.rb', line 3

def code
  @code
end

#nameObject (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_labelsObject



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

#featuresObject



11
12
13
# File 'lib/eagle_labels/category.rb', line 11

def features
  @features.map { |k, v| Feature.new(k, v) }
end