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.
9 10 11 12 13 |
# File 'lib/fruit.rb', line 9 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
60 61 62 |
# File 'lib/fruit.rb', line 60 def self.all @@all end |
.max(element) ⇒ Object
15 16 17 |
# File 'lib/fruit.rb', line 15 def self.max(element) all.max { |a, b| a.nutritions[element] <=> b.nutritions[element] } end |
.min(element) ⇒ Object
19 20 21 |
# File 'lib/fruit.rb', line 19 def self.min(element) all.min { |a, b| a.nutritions[element] <=> b.nutritions[element] } end |
.new_from_api(fruits) ⇒ Object
64 65 66 |
# File 'lib/fruit.rb', line 64 def self.new_from_api(fruits) fruits.each { |fruit| new(fruit) } end |
Instance Method Details
#add_color ⇒ Object
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 56 57 58 |
# File 'lib/fruit.rb', line 23 def add_color self.color = case name when 'Apricot' :yellow when 'Banana' :light_yellow when 'Blueberry' :blue when 'Cherry' :red when 'Apple' :green when 'Lemon' :light_yellow when 'Mango' :yellow when 'Orange' :yellow when 'Pear' :green when 'Pineapple' :light_yellow when 'Raspberry' :light_red when 'Strawberry' :red when 'Tomato' :red when 'Watermelon' :light_green when 'Guava' :light_green else :white end end |