Class: Diet
Overview
esta clase representa una dieta con atributos que representan las distintas caracterÃsticas que podrÃa tener una dieta
Instance Attribute Summary collapse
-
#con_plato ⇒ Object
readonly
Returns the value of attribute con_plato.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#des_plato ⇒ Object
readonly
Returns the value of attribute des_plato.
-
#percentage ⇒ Object
readonly
Returns the value of attribute percentage.
-
#title ⇒ Object
readonly
permitimos leer desde fuera los siguientes atributos.
-
#vct ⇒ Object
readonly
Returns the value of attribute vct.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
definiendo el metodo <=> del mixin Comparable.
-
#gras ⇒ Object
nos dice la grasa de la dieta.
-
#group_plates ⇒ Object
nos devuelve un conjunto de platos.
-
#hid_car ⇒ Object
nos devuelve los hidratos de carbono del menu.
-
#initialize(title, percentage, con_plato, vct, data) ⇒ Diet
constructor
se asignan los diferentes campos de la dieta.
-
#obtain_plate ⇒ Object
nos devuelve el primer plato.
-
#prot ⇒ Object
nos dice las proteinas de la dieta.
-
#to_s ⇒ Object
formateo de la salida por pantalla de una dieta.
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_plato ⇒ Object (readonly)
Returns the value of attribute con_plato
15 16 17 |
# File 'lib/practica7/diet.rb', line 15 def con_plato @con_plato end |
#data ⇒ Object (readonly)
Returns the value of attribute data
16 17 18 |
# File 'lib/practica7/diet.rb', line 16 def data @data end |
#des_plato ⇒ Object (readonly)
Returns the value of attribute des_plato
14 15 16 |
# File 'lib/practica7/diet.rb', line 14 def des_plato @des_plato end |
#percentage ⇒ Object (readonly)
Returns the value of attribute percentage
13 14 15 |
# File 'lib/practica7/diet.rb', line 13 def percentage @percentage end |
#title ⇒ Object (readonly)
permitimos leer desde fuera los siguientes atributos
12 13 14 |
# File 'lib/practica7/diet.rb', line 12 def title @title end |
#vct ⇒ Object (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 |
#gras ⇒ Object
nos dice la grasa de la dieta
49 50 51 |
# File 'lib/practica7/diet.rb', line 49 def gras data[1] end |
#group_plates ⇒ Object
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_car ⇒ Object
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_plate ⇒ Object
nos devuelve el primer plato
30 31 32 |
# File 'lib/practica7/diet.rb', line 30 def obtain_plate con_plato[0][0] end |
#prot ⇒ Object
nos dice las proteinas de la dieta
45 46 47 |
# File 'lib/practica7/diet.rb', line 45 def prot data[0] end |
#to_s ⇒ Object
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 |