Class: Nutriscore::Common::Nutrients

Inherits:
Object
  • Object
show all
Defined in:
lib/nutriscore/common/nutrients.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ Nutrients

Returns a new instance of Nutrients.



15
16
17
# File 'lib/nutriscore/common/nutrients.rb', line 15

def initialize(h)
  @h = h.transform_values {|v| v && Range.wrap(v) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m) ⇒ Object (private)



21
22
23
# File 'lib/nutriscore/common/nutrients.rb', line 21

def method_missing(m)
  @h[m.to_sym]
end

Class Method Details

.wrap(o) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/nutriscore/common/nutrients.rb', line 7

def self.wrap(o)
  if o.is_a?(Nutrients)
    o
  else
    Nutrients.new(o)
  end
end