Class: Diet

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

Overview

esta clase representa una dieta con atributos que representan las distintas características que podría tener una dieta

Direct Known Subclasses

Dietedad, Diettipo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, percentage, con_plato, vct, data) ⇒ Diet

se asignan los diferentes campos de la dieta



21
22
23
24
25
26
27
28
# File 'lib/practica7/diet.rb', line 21

def initialize(title,percentage,con_plato,vct,data)
    @title=title
    @percentage=percentage
		@con_plato = Array.new + con_plato
		@des_plato = con_plato[0]
		@vct = vct
		@data = Array.new + data
end

Instance Attribute Details

#con_platoObject (readonly)

Returns the value of attribute con_plato



15
16
17
# File 'lib/practica7/diet.rb', line 15

def con_plato
  @con_plato
end

#dataObject (readonly)

Returns the value of attribute data



16
17
18
# File 'lib/practica7/diet.rb', line 16

def data
  @data
end

#des_platoObject (readonly)

Returns the value of attribute des_plato



14
15
16
# File 'lib/practica7/diet.rb', line 14

def des_plato
  @des_plato
end

#percentageObject (readonly)

Returns the value of attribute percentage



13
14
15
# File 'lib/practica7/diet.rb', line 13

def percentage
  @percentage
end

#titleObject (readonly)

permitimos leer desde fuera los siguientes atributos



12
13
14
# File 'lib/practica7/diet.rb', line 12

def title
  @title
end

#vctObject (readonly)

Returns the value of attribute vct



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

def vct
  @vct
end

Instance Method Details

#<=>(other) ⇒ Object

definiendo el metodo <=> del mixin Comparable



68
69
70
71
# File 'lib/practica7/diet.rb', line 68

def <=> (other)
	return nil unless other.is_a?Diet
	self.vct<=>other.vct
end

#grasObject

nos dice la grasa de la dieta



49
50
51
# File 'lib/practica7/diet.rb', line 49

def gras
	data[1]
end

#group_platesObject

nos devuelve un conjunto de platos



34
35
36
37
38
39
40
41
42
43
# File 'lib/practica7/diet.rb', line 34

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

#hid_carObject

nos devuelve los hidratos de carbono del menu



53
54
55
# File 'lib/practica7/diet.rb', line 53

def hid_car
	data[2]
end

#obtain_plateObject

nos devuelve el primer plato



30
31
32
# File 'lib/practica7/diet.rb', line 30

def obtain_plate
	con_plato[0][0]
end

#protObject

nos dice las proteinas de la dieta



45
46
47
# File 'lib/practica7/diet.rb', line 45

def prot
	data[0]
end

#to_sObject

formateo de la salida por pantalla de una dieta



57
58
59
60
61
62
63
64
65
66
# File 'lib/practica7/diet.rb', line 57

def to_s
	s="#{title} (#{percentage}%)\n"
	$i=0
	while $i<con_plato.length do
		s+= "- #{con_plato[$i][0]}, #{con_plato[$i][1]}, #{con_plato[$i][2]} gr\n"
		$i+=1
	end
	s+="V.C.T | %  #{vct} kcal | #{data[0]}% - #{data[1]} - #{data[2]}" 
	
end