Class: DietaDia
- Inherits:
-
Object
- Object
- DietaDia
- Includes:
- Comparable
- Defined in:
- lib/NutrientesEdu/version.rb,
lib/NutrientesEdu/DietaDiaria.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#almuerzo(options = {}) ⇒ Object
readonly
Returns the value of attribute almuerzo.
-
#cena(options = {}) ⇒ Object
readonly
Returns the value of attribute cena.
-
#conversiones ⇒ Object
readonly
Returns the value of attribute conversiones.
-
#desayuno(options = {}) ⇒ Object
readonly
Returns the value of attribute desayuno.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(nombre, &bloque) ⇒ DietaDia
constructor
A new instance of DietaDia.
- #is_enough(persona) ⇒ Object
- #kcal ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(nombre, &bloque) ⇒ DietaDia
Returns a new instance of DietaDia.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 8 def initialize(nombre, &bloque) @conversiones = [ ["1 rodaja", 20], ["1 porcion", 100], ["1 taza", 180], ["1/2 cucharon",18], ["1 pieza", 135], ["1 vaso", 100]] @nombre = nombre @desayuno = Menu.new() @almuerzo = Menu.new() @cena = Menu.new() if block_given? if bloque.arity == 1 yield self else instance_eval(&bloque) end end end |
Instance Attribute Details
#almuerzo(options = {}) ⇒ Object (readonly)
Returns the value of attribute almuerzo.
6 7 8 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 6 def almuerzo @almuerzo end |
#cena(options = {}) ⇒ Object (readonly)
Returns the value of attribute cena.
6 7 8 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 6 def cena @cena end |
#conversiones ⇒ Object (readonly)
Returns the value of attribute conversiones.
6 7 8 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 6 def conversiones @conversiones end |
#desayuno(options = {}) ⇒ Object (readonly)
Returns the value of attribute desayuno.
6 7 8 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 6 def desayuno @desayuno end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
6 7 8 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 6 def nombre @nombre end |
Instance Method Details
#<=>(other) ⇒ Object
41 42 43 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 41 def <=>(other) kcal <=> other.kcal end |
#is_enough(persona) ⇒ Object
35 36 37 38 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 35 def is_enough(persona) x = kcal return (persona.g_en_total <= x * 1.1) && (persona.g_en_total >= x * 0.9) end |
#kcal ⇒ Object
30 31 32 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 30 def kcal @desayuno.kcal + @almuerzo.kcal + @cena.kcal end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/NutrientesEdu/DietaDiaria.rb', line 47 def to_s texto = @nombre texto << "\n#{'=' * @nombre.size}\n" texto << "Composicion nutricional: \n" texto << "Desayuno: " texto << "\n" texto << @desayuno.to_s texto << "Almuerzo: " texto << "\n" texto << @almuerzo.to_s texto << "Cena: " texto << "\n" texto << @cena.to_s texto << "Kcal totales: " texto << "#{kcal}" texto << "\n" return texto end |