Class: FruitInfo::Fruit
- Inherits:
-
Object
- Object
- FruitInfo::Fruit
- Defined in:
- lib/fruit.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#family ⇒ Object
Returns the value of attribute family.
-
#genus ⇒ Object
Returns the value of attribute genus.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nutritions ⇒ Object
Returns the value of attribute nutritions.
-
#order ⇒ Object
Returns the value of attribute order.
Class Method Summary collapse
Instance Method Summary collapse
- #add_color ⇒ Object
-
#initialize(attributes) ⇒ Fruit
constructor
A new instance of Fruit.
Constructor Details
#initialize(attributes) ⇒ Fruit
Returns a new instance of Fruit.
8 9 10 11 12 |
# File 'lib/fruit.rb', line 8 def initialize(attributes) attributes.each { |k, v| send("#{k}=", v) } add_color @@all << self end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
6 7 8 |
# File 'lib/fruit.rb', line 6 def color @color end |
#family ⇒ Object
Returns the value of attribute family.
6 7 8 |
# File 'lib/fruit.rb', line 6 def family @family end |
#genus ⇒ Object
Returns the value of attribute genus.
6 7 8 |
# File 'lib/fruit.rb', line 6 def genus @genus end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/fruit.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/fruit.rb', line 6 def name @name end |
#nutritions ⇒ Object
Returns the value of attribute nutritions.
6 7 8 |
# File 'lib/fruit.rb', line 6 def nutritions @nutritions end |
#order ⇒ Object
Returns the value of attribute order.
6 7 8 |
# File 'lib/fruit.rb', line 6 def order @order end |
Class Method Details
.all ⇒ Object
57 58 59 |
# File 'lib/fruit.rb', line 57 def self.all @@all end |
.max(element) ⇒ Object
14 15 16 |
# File 'lib/fruit.rb', line 14 def self.max(element) all.max { |a, b| a.nutritions[element] <=> b.nutritions[element] } end |
.min(element) ⇒ Object
18 19 20 |
# File 'lib/fruit.rb', line 18 def self.min(element) all.min { |a, b| a.nutritions[element] <=> b.nutritions[element] } end |
.new_from_api(fruits) ⇒ Object
61 62 63 |
# File 'lib/fruit.rb', line 61 def self.new_from_api(fruits) fruits.each { |fruit| new(fruit) } end |
Instance Method Details
#add_color ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 else self.color = :white end end |