class Mat::Foodstuff
Attributes
data[R]
Public Class Methods
all(query)
click to toggle source
# File lib/mat/foodstuff.rb, line 10 def all(query) Mat.api.foodstuffs(query).map { |d| new(d) } end
find(number, nutrient = nil)
click to toggle source
# File lib/mat/foodstuff.rb, line 6 def find(number, nutrient = nil) new get_data(number, nutrient) end
get_data(number, nutrient = nil)
click to toggle source
# File lib/mat/foodstuff.rb, line 14 def get_data(number, nutrient = nil) Mat.api.foodstuff(number, nutrient) end
new(data)
click to toggle source
# File lib/mat/foodstuff.rb, line 21 def initialize(data) @data = data || {} end
Public Instance Methods
get_data!()
click to toggle source
# File lib/mat/foodstuff.rb, line 48 def get_data! initialize self.class.get_data(number) self end
method_missing(m, *args, &block)
click to toggle source
Calls superclass method
# File lib/mat/foodstuff.rb, line 39 def method_missing(m, *args, &block) if nutrient_values.respond_to?(:keys) && nutrient_values.keys.include?(m.to_s) nutrient_values[m.to_s] else super end end
name()
click to toggle source
# File lib/mat/foodstuff.rb, line 25 def name data['name'].to_s.strip end
number()
click to toggle source
# File lib/mat/foodstuff.rb, line 29 def number data['number'] end
nutrient_values()
click to toggle source
# File lib/mat/foodstuff.rb, line 33 def nutrient_values get_data! if data['nutrientValues'].nil? data['nutrientValues'] end