Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/practica6/menu_dietetico.rb
Instance Attribute Summary collapse
-
#almuerzo(options = {}) ⇒ Object
readonly
Returns the value of attribute almuerzo.
-
#cena(options = {}) ⇒ Object
readonly
Returns the value of attribute cena.
-
#desayuno(options = {}) ⇒ Object
readonly
Returns the value of attribute desayuno.
- #ingesta(options = {}) ⇒ Object readonly
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#titulo(titulo) ⇒ Object
readonly
Returns the value of attribute titulo.
-
#v_energetico_total ⇒ Object
readonly
Returns the value of attribute v_energetico_total.
Instance Method Summary collapse
- #calcular_valor_energetico(ingredientes) ⇒ Object
-
#initialize(name, &block) ⇒ Menu
constructor
A new instance of Menu.
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Menu
Returns a new instance of Menu.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/practica6/menu_dietetico.rb', line 3 def initialize(name, &block) @name = name @titulo = "" @ingesta = [30,35] @desayuno = [] @almuerzo = [] @cena = [] @v_energetico_total = 0 if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#almuerzo(options = {}) ⇒ Object (readonly)
Returns the value of attribute almuerzo.
2 3 4 |
# File 'lib/practica6/menu_dietetico.rb', line 2 def almuerzo @almuerzo end |
#cena(options = {}) ⇒ Object (readonly)
Returns the value of attribute cena.
2 3 4 |
# File 'lib/practica6/menu_dietetico.rb', line 2 def cena @cena end |
#desayuno(options = {}) ⇒ Object (readonly)
Returns the value of attribute desayuno.
2 3 4 |
# File 'lib/practica6/menu_dietetico.rb', line 2 def desayuno @desayuno end |
#ingesta(options = {}) ⇒ Object (readonly)
def ingesta(options={})
ingesta << "(#{[:min]})" if [:min]
ingesta << "(#{[:max]})" if [:max]
@ingesta << ingesta
end
52 53 54 |
# File 'lib/practica6/menu_dietetico.rb', line 52 def ingesta @ingesta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/practica6/menu_dietetico.rb', line 2 def name @name end |
#titulo(titulo) ⇒ Object (readonly)
Returns the value of attribute titulo.
2 3 4 |
# File 'lib/practica6/menu_dietetico.rb', line 2 def titulo @titulo end |
#v_energetico_total ⇒ Object (readonly)
Returns the value of attribute v_energetico_total.
2 3 4 |
# File 'lib/practica6/menu_dietetico.rb', line 2 def v_energetico_total @v_energetico_total end |
Instance Method Details
#calcular_valor_energetico(ingredientes) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/practica6/menu_dietetico.rb', line 57 def calcular_valor_energetico(ingredientes) valor_energetico = 0 valor_energetico += ingredientes[:grasas] * 9 valor_energetico += ingredientes[:carbohidratos] * 4 valor_energetico += ingredientes[:azucares] * 4 valor_energetico += ingredientes[:fibra] * 2 valor_energetico += ingredientes[:proteinas] * 4 valor_energetico += ingredientes[:sal] * 6 end |
#to_s ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/practica6/menu_dietetico.rb', line 25 def to_s output = "#{@name}\t\t\t\t" output << "Composición Nutricional" output << "\n#{'=' * @name.size * 12}\n" output << "#{' ' * 32 }" output << "grasas\tcarbohidratos\tproteinas fibra sal azucares valor energetico\n\n" output << "Desayuno\n" output << "#{@desayuno.join}\n" output << "Almuerzo\n" output << "#{@almuerzo.join}\n" output << "Cena\n" output << "#{@cena.join}\n" output << "Valor Energetico Total: " << "#{@v_energetico_total}" end |