Class: Alimento

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

Overview

Almacena alimentos

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, proteinas, carbo, lipidos, emision, terreno) ⇒ Alimento

Constructor de la clase alimento



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

def initialize(nombre, proteinas, carbo, lipidos, emision, terreno)
  @nombre_ = nombre
  @proteinas_ = proteinas
  @carbo_ = carbo
  @lipidos_ = lipidos
  @emision_ = emision
  @terreno_ = terreno
end

Instance Attribute Details

#carbo_Object

Returns the value of attribute carbo_.



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

def carbo_
  @carbo_
end

#emision_Object

Returns the value of attribute emision_.



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

def emision_
  @emision_
end

#lipidos_Object

Returns the value of attribute lipidos_.



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

def lipidos_
  @lipidos_
end

#nombre_Object

Returns the value of attribute nombre_.



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

def nombre_
  @nombre_
end

#proteinas_Object

Returns the value of attribute proteinas_.



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

def proteinas_
  @proteinas_
end

#terreno_Object

Returns the value of attribute terreno_.



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

def terreno_
  @terreno_
end

Instance Method Details

#<=>(other) ⇒ Object

Método comparable



28
29
30
# File 'lib/p6/alimento.rb', line 28

def <=>(other)
  calorias <=> other.calorias
end

#caloriasObject

Devuelve las calorías del alimento



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

def calorias
  @carbo_*4 + @lipidos_*9 + @proteinas_*4
end

#to_sObject



23
24
25
# File 'lib/p6/alimento.rb', line 23

def to_s
   "(#{@nombre_},#{@proteinas_}, #{@carbo_}, #{@lipidos_}, #{@emision_}, #{@terreno_})"
end