Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/prct06/menu.rb
Overview
Manages all the informations
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #almuerzo(properties = {}) ⇒ Object
- #cena(properties = {}) ⇒ Object
- #desayuno(properties = {}) ⇒ Object
- #food(properties) ⇒ Object
- #ingesta(properties = {}) ⇒ Object
-
#initialize(day, &block) ⇒ Menu
constructor
A new instance of Menu.
- #titulo(titulo) ⇒ Object
- #to_s ⇒ Object
- #to_s_helper(liste) ⇒ Object
Constructor Details
#initialize(day, &block) ⇒ Menu
Returns a new instance of Menu.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/prct06/menu.rb', line 9 def initialize(day, &block) @day = day @title = title @breakfast, @lunch, @dinner = [], [], [] @table = [" ", "grasas carbohidratos", "proteínas", "fibra", "sal", "valor energético"] @tot_energy = 0 if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
7 8 9 |
# File 'lib/prct06/menu.rb', line 7 def day @day end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/prct06/menu.rb', line 7 def title @title end |
Instance Method Details
#almuerzo(properties = {}) ⇒ Object
37 38 39 |
# File 'lib/prct06/menu.rb', line 37 def almuerzo(properties = {}) @lunch.push(food(properties)) end |
#cena(properties = {}) ⇒ Object
41 42 43 |
# File 'lib/prct06/menu.rb', line 41 def cena(properties = {}) @dinner.push(food(properties)) end |
#desayuno(properties = {}) ⇒ Object
33 34 35 |
# File 'lib/prct06/menu.rb', line 33 def desayuno(properties = {}) @breakfast.push(food(properties)) end |
#food(properties) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/prct06/menu.rb', line 45 def food(properties) food = Array.new(7) food[0] = properties[:descripcion] ? "\"#{properties[:descripcion]}\"" : "unknown" food[0] = food[0].length > 23 ? "#{food[0][0,20]}..\"" : food[0] food[1] = properties[:grasas] ? properties[:grasas] : 0.0 food[2] = properties[:carbohidratos] ? properties[:carbohidratos] : 0.0 food[3] = properties[:proteinas] ? properties[:proteinas] : 0.0 food[4] = properties[:fibra] ? properties[:fibra] : 0.0 food[5] = properties[:sal] ? properties[:sal] : 0.0 food[6] = (food[1] * 36 + food[2] * 17 + food[3] * 17 + food[5] * 25).round(2) @tot_energy += food[6] return food end |
#ingesta(properties = {}) ⇒ Object
28 29 30 31 |
# File 'lib/prct06/menu.rb', line 28 def ingesta(properties = {}) @min = properties[:min] ? properties[:min] : "unknown" @max = properties[:max] ? properties[:max] : "unknown" end |
#titulo(titulo) ⇒ Object
24 25 26 |
# File 'lib/prct06/menu.rb', line 24 def titulo(titulo) @title = titulo end |
#to_s ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/prct06/menu.rb', line 59 def to_s() output = "#{@day}\t\t\t\t\tComposición nutricional\n" output << "=" * 100 + "\n" output << "\t\t\tgrasas\tcarbohidratos\tproteínas\tfibra\tsal\tvalor energético\n" output << "Desayuno\n" + to_s_helper(@breakfast) + "\n" output << "Almuerzo\n" + to_s_helper(@lunch) + "\n" output << "Cena\n" + to_s_helper(@dinner) output << "Valor energético total #{@tot_energy}" output end |
#to_s_helper(liste) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/prct06/menu.rb', line 70 def to_s_helper(liste) o = "" liste.each do |obj| o << "#{obj[0]}\t" if obj[0].length < 16 o << "\t" if obj[0].length < 8 o << "\t" end end o << "#{obj[1]}\t#{obj[2]}\t\t#{obj[3]}\t\t#{obj[4]}\t#{obj[5]}\t#{obj[6]}\n" end return o end |