class Plate
Attributes
name[RW]
plates[RW]
Public Class Methods
new(name) { |self| ... }
click to toggle source
Calls superclass method
Grupo::new
# 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
Public Instance Methods
aceite(val, options = {})
click to toggle source
# File lib/pract/plate.rb, line 55 def aceite (val, options = {}) @@type << 4 new_plate(val, options) end
calculate()
click to toggle source
# 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 = {})
click to toggle source
# File lib/pract/plate.rb, line 45 def cereal (val, options = {}) @@type << 2 new_plate(val, options) end
formatted_to_s()
click to toggle source
# 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 " #@instructions.each_with_index do |instruction, index| # string << "#{index + 1}) #{instruction}\n" # end return string end
fruta(val, options = {})
click to toggle source
# File lib/pract/plate.rb, line 40 def fruta (val, options = {}) @@type << 1 new_plate(val, options) end
new_plate(val, options = {})
click to toggle source
# 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 = {})
click to toggle source
# File lib/pract/plate.rb, line 50 def proteina (val, options = {}) @@type << 3 new_plate(val, options) end
to_s_other()
click to toggle source
# File lib/pract/plate.rb, line 60 def to_s_other elements = "" elements << @name + ": " @@plates.each do |i| elements << i.to_s + " "#+ @plates[j][0] end return elements end
vegetal(val, options = {})
click to toggle source
# File lib/pract/plate.rb, line 35 def vegetal (val, options = {}) @@type << 0 new_plate(val, options) end