Class: Alimento

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

Direct Known Subclasses

Grupoal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, prt, gluc, lip) ⇒ Alimento

Returns a new instance of Alimento.



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

def initialize(nombre,prt,gluc,lip)
        @nombre=nombre
        @prt=prt
        @gluc=gluc
        @lip=lip
end

Instance Attribute Details

#glucObject (readonly)

Returns the value of attribute gluc.



2
3
4
# File 'lib/alimento/alimento.rb', line 2

def gluc
  @gluc
end

#lipObject (readonly)

Returns the value of attribute lip.



2
3
4
# File 'lib/alimento/alimento.rb', line 2

def lip
  @lip
end

#nombreObject (readonly)

Returns the value of attribute nombre.



2
3
4
# File 'lib/alimento/alimento.rb', line 2

def nombre
  @nombre
end

#prtObject (readonly)

Returns the value of attribute prt.



2
3
4
# File 'lib/alimento/alimento.rb', line 2

def prt
  @prt
end

Instance Method Details

#<=>(another) ⇒ Object



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

def <=>(another)
        kcal <=> another.kcal
end

#kcalObject



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

def kcal()
        @prt*4+@gluc*4+@lip*9
end

#to_sObject



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

def to_s()
        "#{@nombre} prt=#{@prt}g gluc=#{@gluc}g lip=#{@lip}g"
end