Class: Alimentos

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

Direct Known Subclasses

AGrupos

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, proteinas, glucidos, lipidos) ⇒ Alimentos

Returns a new instance of Alimentos



10
11
12
13
14
# File 'lib/alimento.rb', line 10

def initialize(nombre,proteinas,glucidos,lipidos)
    
    @nombre,@proteinas,@glucidos,@lipidos= nombre,proteinas,glucidos,lipidos

end

Instance Attribute Details

#glucidosObject (readonly)

Returns the value of attribute glucidos



8
9
10
# File 'lib/alimento.rb', line 8

def glucidos
  @glucidos
end

#lipidosObject (readonly)

Returns the value of attribute lipidos



8
9
10
# File 'lib/alimento.rb', line 8

def lipidos
  @lipidos
end

#nombreObject (readonly)

Returns the value of attribute nombre



8
9
10
# File 'lib/alimento.rb', line 8

def nombre
  @nombre
end

#proteinasObject (readonly)

Returns the value of attribute proteinas



8
9
10
# File 'lib/alimento.rb', line 8

def proteinas
  @proteinas
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
19
# File 'lib/alimento.rb', line 16

def <=>(other)
    nombre.size <=> other.nombre.size
    ve <=> other.ve
end

#to_sObject



25
26
27
28
29
# File 'lib/alimento.rb', line 25

def to_s

    "Alimento: #{@nombre}\n------------------------------\nProteínas:\s#{@proteinas}g\nGlúcidos:\s#{@glucidos}g\nLípidos:\s#{@lipidos}g"  
   
end

#veObject



21
22
23
# File 'lib/alimento.rb', line 21

def ve
    @proteinas*4+@glucidos*4+@lipidos*9
end