Class: Diet

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

Direct Known Subclasses

AgeGroup, Aliments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, porcentaje, platos, porcion, gramos, vct, proteinas, grasas, hidratos) ⇒ Diet

Returns a new instance of Diet.



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

def initialize(nombre,porcentaje,platos,porcion,gramos,vct,proteinas,grasas,hidratos)
    @nombre = nombre
    @porcentaje = porcentaje
    @platos = platos
    @porcion = porcion
    @gramos = gramos
    @vct = vct
    @proteinas = proteinas
    @grasas = grasas
    @hidratos = hidratos
end

Instance Attribute Details

#gramosObject (readonly)

Returns the value of attribute gramos.



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

def gramos
  @gramos
end

#grasasObject (readonly)

Returns the value of attribute grasas.



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

def grasas
  @grasas
end

#hidratosObject (readonly)

Returns the value of attribute hidratos.



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

def hidratos
  @hidratos
end

#nombreObject (readonly)

Returns the value of attribute nombre.



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

def nombre
  @nombre
end

#platosObject (readonly)

Returns the value of attribute platos.



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

def platos
  @platos
end

#porcentajeObject (readonly)

Returns the value of attribute porcentaje.



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

def porcentaje
  @porcentaje
end

#porcionObject (readonly)

Returns the value of attribute porcion.



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

def porcion
  @porcion
end

#proteinasObject (readonly)

Returns the value of attribute proteinas.



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

def proteinas
  @proteinas
end

#vctObject (readonly)

Returns the value of attribute vct.



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

def vct
  @vct
end

Instance Method Details

#<=>(other) ⇒ Object

definimos el metodo necesario para comparar



25
26
27
# File 'lib/prct7/diet.rb', line 25

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

#to_sObject

Metodo para imprimir



16
17
18
19
20
21
22
23
# File 'lib/prct7/diet.rb', line 16

def to_s
    s="\n#{@nombre} (#{@porcentaje})\n"
    (0..@platos.size-1).each do |i|
        s<< "#{@platos[i]}, #{@porcion[i]}, #{@gramos[i]}gr.\n"
    end
    s<< "VCT | %\t#{@vct} kcal | #{@proteinas}% - #{@grasas}% - #{@hidratos}%\n"
    s
end