Class: Diet

Inherits:
Object
  • Object
show all
Defined in:
lib/practica7/diet.rb

Direct Known Subclasses

Dietedad, Diettipo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nomb, &block) ⇒ Diet

Returns a new instance of Diet.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/practica7/diet.rb', line 4

def initialize(nomb,&block)
    self.nombre = nomb
self.titulo=""
self.inges=[]
self.plat=[]
self.porcen=[]
if block_given?
 if block.arity == 1
     		yield self
   	else
    		instance_eval(&block)
  		end
	  end
end

Instance Attribute Details

#con_platoObject

Returns the value of attribute con_plato.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def con_plato
  @con_plato
end

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def data
  @data
end

#des_platoObject

Returns the value of attribute des_plato.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def des_plato
  @des_plato
end

#ingesObject

Returns the value of attribute inges.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def inges
  @inges
end

#nombreObject

Returns the value of attribute nombre.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def nombre
  @nombre
end

#percentageObject

Returns the value of attribute percentage.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def percentage
  @percentage
end

#platObject

Returns the value of attribute plat.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def plat
  @plat
end

#porcenObject

Returns the value of attribute porcen.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def porcen
  @porcen
end

#tituloObject

Returns the value of attribute titulo.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def titulo
  @titulo
end

#vctObject

Returns the value of attribute vct.



3
4
5
# File 'lib/practica7/diet.rb', line 3

def vct
  @vct
end

Instance Method Details

#group_platesObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/practica7/diet.rb', line 38

def group_plates
 s = "#{self.con_plato[0][0]}"
 $i=1
 while $i < self.con_plato.length do
	 s+= ", "
	 s+= "#{self.con_plato[$i][0]}"
	 $i+=1
 end
 s
end

#ingesta(options = {}) ⇒ Object



21
22
23
24
# File 'lib/practica7/diet.rb', line 21

def ingesta(options={})
 inges << " (#{options[:min]})" if options[:min]
 inges << " (#{options[:max]})" if options[:max]
end

#plato(options = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/practica7/diet.rb', line 25

def plato(options={})
 vec_plat = "(#{options[:descripcion]})" if options[:descripcion]
 vec_plat << "(#{options[:porcion]})" if options[:porcion]
 vec_plat << "(#{options[:gramos]})" if options[:gramos]
 plat<<vec_plat
end

#porcentajes(options = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/practica7/diet.rb', line 31

def porcentajes(options={})
 porcen<<"(#{options[:vct]})" if options[:vct]
 porcen<<"(#{options[:proteinas]})" if options[:proteinas]
 porcen<<"(#{options[:grasas]})" if options[:grasas]
 porcen<<"(#{options[:hidratos]})" if options[:hidratos]
end

#title(name) ⇒ Object



18
19
20
# File 'lib/practica7/diet.rb', line 18

def title(name)
 self.titulo=name
end

#to_sObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/practica7/diet.rb', line 48

def to_s
 output= "\n\n#{self.nombre}"
 output << "\n#{'=' * titulo.size}\n\n"
 output << "Ingesta min:#{inges[0]} max:#{inges[1]}\n\n"
 plat.each do |n|
	 output<<"#{n}\n"
 end
 output <<"\n\n"
 output << "vct: #{porcen[0]} protinas: #{porcen[1]} grasas: #{porcen[2]} hidratos: #{porcen[3]}"
end