Class: Mat::Nutrient

Inherits:
Object
  • Object
show all
Defined in:
lib/mat/nutrient.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



19
20
21
# File 'lib/mat/nutrient.rb', line 19

def data
  @data
end

Class Method Details

.allObject



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

.get_data(slug) ⇒ Object



14
15
16
# File 'lib/mat/nutrient.rb', line 14

def get_data(slug)
  Mat.api.nutrient(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

#nameObject



29
30
31
# File 'lib/mat/nutrient.rb', line 29

def name
  @data['name']
end

#slugObject



25
26
27
# File 'lib/mat/nutrient.rb', line 25

def slug
  @data['slug']
end

#unitObject



33
34
35
# File 'lib/mat/nutrient.rb', line 33

def unit
  @data['unit']
end