Class: Dieta

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/prct06/Dieta.rb

Overview

Clase dieta base. Almacena un menú, indicando aspectos, tales como, porcentaje de ingesta, VCT, proteínas, grasas, hidratos y los platos

Direct Known Subclasses

Dieta_edades, Dieta_grupos

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(titulo = 0, porcentaje_ingesta = 0, nplatos = 0, vct = 0, proteinas = 0, grasas = 0, hidratos = 0, *des_platos, &block) ⇒ Dieta

constructor



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/prct06/Dieta.rb', line 9

def initialize (titulo=0, porcentaje_ingesta=0, nplatos=0, vct=0, proteinas=0, grasas=0, hidratos=0, *des_platos, &block)
	@name = titulo
	@platos = []


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

		@platos = []
		for i in 0..nplatos-1 do
			aux = [des_platos[i][0], des_platos[i][1], des_platos[i][2]]
			@platos.push(aux)
		end

		@VCT = vct
		@proteinas = proteinas
		@grasas = grasas
		@hidratos = hidratos

	end
end

Instance Attribute Details

#grasasObject (readonly)

Returns the value of attribute grasas.



5
6
7
# File 'lib/prct06/Dieta.rb', line 5

def grasas
  @grasas
end

#hidratosObject (readonly)

Returns the value of attribute hidratos.



5
6
7
# File 'lib/prct06/Dieta.rb', line 5

def hidratos
  @hidratos
end

#platosObject (readonly)

Returns the value of attribute platos.



5
6
7
# File 'lib/prct06/Dieta.rb', line 5

def platos
  @platos
end

#porcentaje_ingestaObject (readonly)

Returns the value of attribute porcentaje_ingesta.



5
6
7
# File 'lib/prct06/Dieta.rb', line 5

def porcentaje_ingesta
  @porcentaje_ingesta
end

#proteinasObject (readonly)

Returns the value of attribute proteinas.



5
6
7
# File 'lib/prct06/Dieta.rb', line 5

def proteinas
  @proteinas
end

#tituloObject (readonly)

Returns the value of attribute titulo.



5
6
7
# File 'lib/prct06/Dieta.rb', line 5

def titulo
  @titulo
end

#VCTObject (readonly)

Returns the value of attribute VCT.



5
6
7
# File 'lib/prct06/Dieta.rb', line 5

def VCT
  @VCT
end

Instance Method Details

#<=>(other) ⇒ Object



67
68
69
# File 'lib/prct06/Dieta.rb', line 67

def <=> (other)
	@VCT <=>  other.VCT
end

#ingesta(options = {}) ⇒ Object



45
46
47
48
49
# File 'lib/prct06/Dieta.rb', line 45

def ingesta(options = {})

	@porcentaje_ingesta = "#{options[:min]}-#{options[:max]}"

end

#nplatosObject



62
63
64
# File 'lib/prct06/Dieta.rb', line 62

def nplatos
	@platos.length
end

#plate(options = {}) ⇒ Object



51
52
53
# File 'lib/prct06/Dieta.rb', line 51

def plate(options = {})
	@platos << ["#{options[:descripcion]}", "#{options[:porcion]}", options[:gramos]]
end

#plato(n) ⇒ Object



71
72
73
74
75
76
# File 'lib/prct06/Dieta.rb', line 71

def plato (n)
	if n > @platos.length || n < 1 then
		return ""
	end
	return @platos[n-1]
end

#porcentajes(options = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/prct06/Dieta.rb', line 55

def porcentajes(options = {})
	@VCT = options[:vct] if options[:vct]
	@proteinas = options[:proteinas] if options[:proteinas]
	@grasas = options[:grasas] if options[:grasas]
	@hidratos = options[:hidratos] if options[:hidratos]
end

#title(name) ⇒ Object



39
40
41
42
43
# File 'lib/prct06/Dieta.rb', line 39

def title(name)

	@titulo = name

end

#to_sObject

Muestra el menú correctamente formateado



79
80
81
82
83
84
85
86
87
88
# File 'lib/prct06/Dieta.rb', line 79

def to_s
	x = ""
	x << "#{@titulo} (#{@porcentaje_ingesta}%)\n"

	@platos.each do |i|
		x << "- #{i[0]}, #{i[1]}, #{i[2]}g\n"
	end

	x << "V.C.T | %    #{@VCT} kcal | #{@proteinas} #{@grasas} #{@hidratos}"
end