Class: Dieta::Dieta

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/practica8/dieta.rb

Direct Known Subclasses

Alimento, Edad

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, c) ⇒ Dieta

Returns a new instance of Dieta



9
10
11
# File 'lib/practica8/dieta.rb', line 9

def initialize (a,b,c)
    @cabecera, @descrip, @vct = a, b, c
end

Instance Attribute Details

#cabeceraObject

Returns the value of attribute cabecera



5
6
7
# File 'lib/practica8/dieta.rb', line 5

def cabecera
  @cabecera
end

#descripObject

Returns the value of attribute descrip



5
6
7
# File 'lib/practica8/dieta.rb', line 5

def descrip
  @descrip
end

#vctObject

Returns the value of attribute vct



5
6
7
# File 'lib/practica8/dieta.rb', line 5

def vct
  @vct
end

Instance Method Details

#<=>(otro) ⇒ Object

Comparamos segun la cantidad de calorias del menu



14
15
16
# File 'lib/practica8/dieta.rb', line 14

def <=> (otro)
    @vct[0] <=> otro.vct[0]
end


92
93
94
95
96
97
98
99
# File 'lib/practica8/dieta.rb', line 92

def get_footer
    
    out = get_vct
    out << get_porc_prot
    out << get_porc_gras
    out << get_porc_hdc
    out 
end

#get_plato(i) ⇒ Object



44
45
46
47
48
# File 'lib/practica8/dieta.rb', line 44

def get_plato(i)
    
    out = "#{@descrip[i]}"
    out
end

#get_platosObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/practica8/dieta.rb', line 50

def get_platos
    
    out=""
    i=0
    @descrip.each do
        out << "- "
        out << get_plato(i)
        out << "\n"
        i+=1
    end
    out    
end

#get_porc_grasObject



78
79
80
81
82
83
# File 'lib/practica8/dieta.rb', line 78

def get_porc_gras
    
    out = "#{@vct[2]}" 
    out << "% - "
    out       
end

#get_porc_hdcObject



85
86
87
88
89
90
# File 'lib/practica8/dieta.rb', line 85

def get_porc_hdc
    
    out = "#{@vct[3]}" 
    out << "%"
    out       
end

#get_porc_inges_diariaObject



34
35
36
37
38
39
40
41
42
# File 'lib/practica8/dieta.rb', line 34

def get_porc_inges_diaria
    
    out = " ("
    out << "#{@cabecera[1]}"
    out << " - "
    out << "#{@cabecera[2]}"
    out << "%)\n"
    out
end

#get_porc_protObject



71
72
73
74
75
76
# File 'lib/practica8/dieta.rb', line 71

def get_porc_prot
    
    out = "#{@vct[1]}" 
    out << "% - "
    out       
end

#get_tituloObject



27
28
29
30
31
32
# File 'lib/practica8/dieta.rb', line 27

def get_titulo
    
    out ="#{@cabecera[0]}"
    out << get_porc_inges_diaria
    out        
end

#get_vctObject



63
64
65
66
67
68
69
# File 'lib/practica8/dieta.rb', line 63

def get_vct
    
    out = "V.C.T. | %    "
    out << "#{@vct[0]}" 
    out << " kcal | "
    out       
end

#to_sObject



18
19
20
21
22
23
24
25
# File 'lib/practica8/dieta.rb', line 18

def to_s
    
    out = get_titulo
    out << get_platos
    out << get_footer
    out
    
end