Class: Mat::Nutrient
- Inherits:
-
Object
- Object
- Mat::Nutrient
- Defined in:
- lib/mat/nutrient.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #get_data! ⇒ Object
-
#initialize(data) ⇒ Nutrient
constructor
A new instance of Nutrient.
- #name ⇒ Object
- #slug ⇒ Object
- #unit ⇒ Object
Constructor Details
#initialize(data) ⇒ Nutrient
Returns a new instance of Nutrient.
21 22 23 |
# File 'lib/mat/nutrient.rb', line 21 def initialize(data) @data = data || {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/mat/nutrient.rb', line 19 def data @data end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/mat/nutrient.rb', line 10 def all Mat.api.nutrients.map { |d| new(d) } end |
.find(slug) ⇒ Object
6 7 8 |
# File 'lib/mat/nutrient.rb', line 6 def find(slug) new get_data(slug) end |
Instance Method Details
#get_data! ⇒ Object
37 38 39 40 |
# File 'lib/mat/nutrient.rb', line 37 def get_data! initialize self.class.get_data(slug) self end |
#name ⇒ Object
29 30 31 |
# File 'lib/mat/nutrient.rb', line 29 def name @data['name'] end |
#slug ⇒ Object
25 26 27 |
# File 'lib/mat/nutrient.rb', line 25 def slug @data['slug'] end |
#unit ⇒ Object
33 34 35 |
# File 'lib/mat/nutrient.rb', line 33 def unit @data['unit'] end |