Class: Alimento
Overview
Almacena alimentos
Instance Attribute Summary collapse
-
#carbo_ ⇒ Object
Returns the value of attribute carbo_.
-
#emision_ ⇒ Object
Returns the value of attribute emision_.
-
#lipidos_ ⇒ Object
Returns the value of attribute lipidos_.
-
#nombre_ ⇒ Object
Returns the value of attribute nombre_.
-
#proteinas_ ⇒ Object
Returns the value of attribute proteinas_.
-
#terreno_ ⇒ Object
Returns the value of attribute terreno_.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Método comparable.
-
#calorias ⇒ Object
Devuelve las calorías del alimento.
-
#initialize(nombre, proteinas, carbo, lipidos, emision, terreno) ⇒ Alimento
constructor
Constructor de la clase alimento.
- #to_s ⇒ Object
Constructor Details
#initialize(nombre, proteinas, carbo, lipidos, emision, terreno) ⇒ Alimento
Constructor de la clase alimento
9 10 11 12 13 14 15 16 |
# File 'lib/p6/alimento.rb', line 9 def initialize(nombre, proteinas, carbo, lipidos, emision, terreno) @nombre_ = nombre @proteinas_ = proteinas @carbo_ = carbo @lipidos_ = lipidos @emision_ = emision @terreno_ = terreno end |
Instance Attribute Details
#carbo_ ⇒ Object
Returns the value of attribute carbo_.
6 7 8 |
# File 'lib/p6/alimento.rb', line 6 def carbo_ @carbo_ end |
#emision_ ⇒ Object
Returns the value of attribute emision_.
6 7 8 |
# File 'lib/p6/alimento.rb', line 6 def emision_ @emision_ end |
#lipidos_ ⇒ Object
Returns the value of attribute lipidos_.
6 7 8 |
# File 'lib/p6/alimento.rb', line 6 def lipidos_ @lipidos_ end |
#nombre_ ⇒ Object
Returns the value of attribute nombre_.
6 7 8 |
# File 'lib/p6/alimento.rb', line 6 def nombre_ @nombre_ end |
#proteinas_ ⇒ Object
Returns the value of attribute proteinas_.
6 7 8 |
# File 'lib/p6/alimento.rb', line 6 def proteinas_ @proteinas_ end |
#terreno_ ⇒ Object
Returns the value of attribute terreno_.
6 7 8 |
# File 'lib/p6/alimento.rb', line 6 def terreno_ @terreno_ end |
Instance Method Details
#<=>(other) ⇒ Object
Método comparable
28 29 30 |
# File 'lib/p6/alimento.rb', line 28 def <=>(other) calorias <=> other.calorias end |
#calorias ⇒ Object
Devuelve las calorías del alimento
19 20 21 |
# File 'lib/p6/alimento.rb', line 19 def calorias @carbo_*4 + @lipidos_*9 + @proteinas_*4 end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/p6/alimento.rb', line 23 def to_s "(#{@nombre_},#{@proteinas_}, #{@carbo_}, #{@lipidos_}, #{@emision_}, #{@terreno_})" end |