Skip to content

Commit

Permalink
practica terminada
Browse files Browse the repository at this point in the history
  • Loading branch information
alu0101015729 committed Jan 11, 2019
1 parent 81abdaa commit d646584
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/prct06.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "prct06/individuo"
require "prct06/paciente"
require "prct06/Array"
require "prct06/menu"
module Prct06
class Error < StandardError; end
# Your code goes here...
Expand Down
147 changes: 147 additions & 0 deletions lib/prct06/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
class Menu

attr_accessor :titulo, :ingesta, :desayuno, :almuerzo, :cena, :dia

def initialize(dia_a_tomar, &block)
@dia = dia_a_tomar
@ingesta = []
@titulo = []
@desayuno = []
@almuerzo = []
@cena = []

if block_given?
if block.arity == 1
yield self
else
instance_eval(&block)
end
end
end
def titulo(cadena)
@titulo = cadena
end

def desayuno(bf,options = {})
breakfast = bf
breakfast << " (#{options[:descripcion]})" if options[:descripcion]
breakfast << " (#{options[:porcion]})" if options[:porcion]
breakfast << " (#{options[:gramos]})" if options[:gramos]
breakfast << " (#{options[:grasas]})" if options[:grasas]
breakfast << " (#{options[:carbohidratos]})" if options[:carbohidratos]
breakfast << " (#{options[:proteinas]})" if options[:proteinas]
breakfast << " (#{options[:fibra]})" if options[:fibra]
if breakfast[:fibra] == nil
breakfast[:fibra] = 0.00
end
if breakfast[:sal] == nil
breakfast[:sal] = 0.00
end

@desayuno << breakfast
end

def almuerzo(lch, options = {})
lunch = lch
lunch << " (#{options[:descripcion]})" if options[:descripcion]
lunch << " (#{options[:porcion]})" if options[:porcion]
lunch << " (#{options[:gramos]})" if options[:gramos]
lunch << " (#{options[:grasas]})" if options[:grasas]
lunch << " (#{options[:carbohidratos]})" if options[:carbohidratos]
lunch << " (#{options[:proteinas]})" if options[:proteinas]
lunch << " (#{options[:fibra]})" if options[:fibra]

if lunch[:fibra] == nil
lunch[:fibra] = 0.00
end

if lunch[:sal] == nil
lunch[:sal] = 0.00
end

@almuerzo << lunch

end

def cena(dr,options = {})
dinner = dr
dinner << " (#{options[:descripcion]})" if options[:descripcion]
dinner << " (#{options[:porcion]})" if options[:porcion]
dinner << " (#{options[:gramos]})" if options[:gramos]
dinner << " (#{options[:grasas]})" if options[:grasas]
dinner << " (#{options[:carbohidratos]})" if options[:carbohidratos]
dinner << " (#{options[:proteinas]})" if options[:proteinas]
dinner << " (#{options[:fibra]})" if options[:fibra]

if dinner[:fibra] == nil
dinner[:fibra] = 0.00
end

if dinner[:sal] == nil
dinner[:sal] = 0.00
end

@cena << dinner
end

def ingesta(ingest,options = {})
ing = ingest
ing << " (#{options[:min]})" if options[:min]
ing << " (#{options[:max]})" if options[:max]
@ingesta << ing
end

def valor_energetico(comida)
kcal = comida[:grasas] * 9
kcal += comida[:carbohidratos] * 4
kcal += comida[:proteinas] * 4
kcal.round(2)
end

def to_s
vet = 0
output = @dia
output << " Composición nutricional\n"
output << "=======================================\n"
output << "\t\t\tgrasas carbohidratos proteínas fibra sal valor energetico\n"
output << "Desayuno\n"
@desayuno.each do |breakfast|
vet += valor_energetico(breakfast)
output << "#{breakfast[:descripcion]} "
output << "#{breakfast[:grasas]} "
output << "#{breakfast[:carbohidratos]} "
output << "#{breakfast[:proteinas]} "
output << "#{breakfast[:fibra]} "
output << "#{breakfast[:sal]} "
output << "#{valor_energetico(breakfast)}"
output << "\n"
end
output << "Almuerzo\n"
@almuerzo.each do |lunch|
vet += valor_energetico(lunch)
output << "#{lunch[:descripcion]} "
output << "#{lunch[:grasas]} "
output << "#{lunch[:carbohidratos]} "
output << "#{lunch[:proteinas]} "
output << "#{lunch[:fibra]} "
output << "#{lunch[:sal]} "
output << "#{valor_energetico(lunch)}"
output << "\n"
end

output << "Cena\n"
@cena.each do |dinner|
vet += valor_energetico(dinner)
output << "#{dinner[:descripcion]} "
output << "#{dinner[:grasas]} "
output << "#{dinner[:carbohidratos]} "
output << "#{dinner[:proteinas]} "
output << "#{dinner[:fibra]} "
output << "#{dinner[:sal]} "
output << "#{valor_energetico(dinner)}"
output << "\n"
end
output << "Valor energético total #{(vet).round(2)}"
output
end
end
55 changes: 55 additions & 0 deletions spec/prct06_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,61 @@
end
end
end
describe "menu" do
it "menus" do
menu = Menu.new("Lunes") do
titulo "Bajo en calorías"
ingesta :min => 30, :max => 35
desayuno :descripcion => "Pan",
:porcion => "1 rodaja",
:gramos => 100,
:grasas => 3.3,
:carbohidratos => 54.0,
:proteinas => 11.0,
:fibra => 2.3,
:sal => 0.06
desayuno :descripcion => "Yogurt",
:porcion => "1 porcion",
:gramos => 100,
:grasas => 3.4,
:carbohidratos => 4.4,
:proteinas => 3.6,
:sal => 0.05
almuerzo :descripcion => "Arroz",
:porcion => "1 taza",
:gramos => 100,
:grasas => 0.9,
:carbohidratos => 81.6,
:proteinas => 6.67,
:fibra => 1.4,
:sal => 0.04
almuerzo :descripcion => "Judias",
:porcion => "1/2 cucharon",
:grasas => 0.4,
:carbohidratos => 20.0,
:proteinas => 9.0,
:fibra => 8.0,
:sal => 0.02
almuerzo :descripcion => "Mandarina",
:porcion => "1 pieza",
:gramos => 100,
:grasas => 0.12,
:carbohidratos => 11.75,
:proteinas => 0.94,
:fibra => 2.4
cena :descripcion => "Leche",
:porcion => "1 vaso",
:gramos => 100,
:grasas => 3.6,
:carbohidratos => 4.6,
:proteinas => 3.1,
:sal => 0.13
end

expect(menu.to_s).to eq("Lunes Composición nutricional\n=======================================\n\t\t\tgrasas carbohidratos proteínas fibra sal valor energetico\nDesayuno\nPan 3.3 54.0 11.0 2.3 0.06 289.7\nYogurt 3.4 4.4 3.6 0.0 0.05 62.6\nAlmuerzo\nArroz 0.9 81.6 6.67 1.4 0.04 361.18\nJudias 0.4 20.0 9.0 8.0 0.02 119.6\nMandarina 0.12 11.75 0.94 2.4 0.0 51.84\nCena\nLeche 3.6 4.6 3.1 0.0 0.13 63.2\nValor energético total 948.12")

end
end
end


0 comments on commit d646584

Please sign in to comment.