Class: Plate
Instance Attribute Summary collapse
Attributes inherited from Alimento
#glucid, #glucose, #lipid, #protein
Instance Method Summary
collapse
Methods inherited from Grupo
#delete, #glucid_energy, #has_a, #insert, #lipid_energy, #protein_energy, #to_s
Methods inherited from Alimento
#<=>, #==, #aibc, #energy, #glucid_energy, #lipid_energy, #protein_energy, #show_energy, #to_s
Constructor Details
#initialize(name, &block) ⇒ Plate
Returns a new instance of Plate.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/pract/plate.rb', line 7
def initialize(name, &block)
super(name)
@@plates = []
@@amount = []
@@type = []
if block_given?
if block.arity == 1
yield self
else
instance_eval(&block)
end
end
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/pract/plate.rb', line 5
def name
@name
end
|
#plates ⇒ Object
Returns the value of attribute plates.
5
6
7
|
# File 'lib/pract/plate.rb', line 5
def plates
@plates
end
|
Instance Method Details
#aceite(val, options = {}) ⇒ Object
55
56
57
58
|
# File 'lib/pract/plate.rb', line 55
def aceite (val, options = {})
@@type << 4
new_plate(val, options)
end
|
#calculate ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/pract/plate.rb', line 87
def calculate
@@plates.each_with_index do
|i, j|
elements = []
elements = i.to_s.tr('()','').split(" ")
amount = 0
amount = elements[1].to_f * 90 / 20 if (elements[2] == 'lata')
amount = elements[1].to_f * 30 / 20 if (elements[2] == 'pieza')
amount = elements[1].to_f * 10 / 20 if (elements[2] == 'cucharada')
amount = elements[1].to_f / 20 if (elements[2] == 'g')
@@amount[j] = amount;
end
return @@amount
end
|
#cereal(val, options = {}) ⇒ Object
45
46
47
48
|
# File 'lib/pract/plate.rb', line 45
def cereal (val, options = {})
@@type << 2
new_plate(val, options)
end
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/pract/plate.rb', line 69
def formatted_to_s
total = 0
string = @name
string << "\n#{'=' * @name.size}\n"
string << "Composicion nutricional:\n\n"
@lista.each_with_index do
|i, j|
string << "#{j + 1}) " + i.name + ": " + ((i.protein_energy* @@amount[j]).round(2)).to_s + "g proteinas, " + ((i.glucid_energy * @@amount[j]).round(2)).to_s + "g glucidos, " + ((i.lipid_energy * @@amount[j]).round(2)).to_s + "g grasas. (" + ((i.energy* @@amount[j]).round(2)).to_s + " g totales)\n"
total = (total + i.energy* @@amount[j]).round(2)
end
string << "\n TOTAL: #{total} g "
return string
end
|
#fruta(val, options = {}) ⇒ Object
40
41
42
43
|
# File 'lib/pract/plate.rb', line 40
def fruta (val, options = {})
@@type << 1
new_plate(val, options)
end
|
#new_plate(val, options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/pract/plate.rb', line 22
def new_plate (val, options = {})
ingredient = val.name
ingredient << " (#{options[:amount]})" if options[:amount]
@@plates << ingredient
@lista.add_last(val)
self.calculate
return val
end
|
#proteina(val, options = {}) ⇒ Object
50
51
52
53
|
# File 'lib/pract/plate.rb', line 50
def proteina (val, options = {})
@@type << 3
new_plate(val, options)
end
|
#to_s_other ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/pract/plate.rb', line 60
def to_s_other
elements = ""
elements << @name + ": "
@@plates.each do
|i| elements << i.to_s + " "
end
return elements
end
|
#vegetal(val, options = {}) ⇒ Object
35
36
37
38
|
# File 'lib/pract/plate.rb', line 35
def vegetal (val, options = {})
@@type << 0
new_plate(val, options)
end
|