class FruitInfo::Fruit
Attributes
color[RW]
family[RW]
genus[RW]
id[RW]
name[RW]
nutritions[RW]
order[RW]
Public Class Methods
all()
click to toggle source
# File lib/fruit.rb, line 59 def self.all @@all end
max(element)
click to toggle source
# File lib/fruit.rb, line 14 def self.max(element) all.max { |a, b| a.nutritions[element] <=> b.nutritions[element] } end
min(element)
click to toggle source
# File lib/fruit.rb, line 18 def self.min(element) all.min { |a, b| a.nutritions[element] <=> b.nutritions[element] } end
new(attributes)
click to toggle source
# File lib/fruit.rb, line 8 def initialize(attributes) attributes.each { |k, v| send("#{k}=", v) } add_color @@all << self end
new_from_api(fruits)
click to toggle source
# File lib/fruit.rb, line 63 def self.new_from_api(fruits) fruits.each { |fruit| new(fruit) } end
Public Instance Methods
add_color()
click to toggle source
# File lib/fruit.rb, line 22 def add_color case name when 'Apricot' self.color = :yellow when 'Banana' self.color = :light_yellow when 'Blueberry' self.color = :blue when 'Cherry' self.color = :red when 'Apple' self.color = :green when 'Lemon' self.color = :light_yellow when 'Mango' self.color = :yellow when 'Orange' self.color = :yellow when 'Pear' self.color = :green when 'Pineapple' self.color = :light_yellow when 'Raspberry' self.color = :light_red when 'Strawberry' self.color = :red when 'Tomato' self.color = :red when 'Watermelon' self.color = :light_green when 'Guava' self.color = :light_green else self.color = :white end end