Class: Alimento

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

Overview

alimento.rb

Autor

Himar Manuel Barquín Carrasco

Web

github.com/ULL-ESIT-LPP-1920/tdd-alu0101119373

Descripción

Clase que representa un alimento, con la información de las proteínas, carbohidratos, lípidos, gases de efecto invernadero y metros cuadrados de tierra consumida que provoca producir el alimento.

Métodos

  • to_s

  • energetic_value

  • <=>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, protein, carbohydrates, lipids, gei, terrain) ⇒ Alimento

Constructor de la clase Alimento

Parámetros
  • name: Nombre del alimento

  • protein: Proteínas del alimento

  • carbohydrates: Carbohidratos del alimento

  • lipids: Lípidos del alimento

  • gei: Gases de Efecto Invernadero que se producen al producir el alimento

  • terrain: Terreno que se usa para la producción del alimento



29
30
31
# File 'lib/tddAlimentos/alimento.rb', line 29

def initialize (name, protein, carbohydrates, lipids, gei, terrain)
  @name, @protein, @carbohydrates, @lipids, @gei, @terrain = name, protein, carbohydrates, lipids, gei, terrain
end

Instance Attribute Details

#carbohydratesObject (readonly)

Returns the value of attribute carbohydrates.



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

def carbohydrates
  @carbohydrates
end

#geiObject (readonly)

Returns the value of attribute gei.



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

def gei
  @gei
end

#lipidsObject (readonly)

Returns the value of attribute lipids.



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

def lipids
  @lipids
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#proteinObject (readonly)

Returns the value of attribute protein.



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

def protein
  @protein
end

#terrainObject (readonly)

Returns the value of attribute terrain.



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

def terrain
  @terrain
end

Instance Method Details

#<=>(another) ⇒ Object

Nos permite comparar alimentos por su valor energético

Parámetros
  • another: Otro plato que se compara con el invocante

Devuelve

‘true’ si la comparación es verdadera. ‘false’ en otro caso



52
53
54
# File 'lib/tddAlimentos/alimento.rb', line 52

def <=> (another)
  self.energetic_value <=> another.energetic_value
end

#energetic_valueObject

Calcula el valor energético del alimento

Devuelve

Valor decimal con el valor energético



43
44
45
# File 'lib/tddAlimentos/alimento.rb', line 43

def energetic_value
  4 * @protein + 4 * @carbohydrates + 9 * @lipids
end

#to_sObject

Imprime la información del alimento

Devuelve

Cadena de texto con la información del alimento



36
37
38
# File 'lib/tddAlimentos/alimento.rb', line 36

def to_s
  "Nombre: #{@name}\nProteínas (g): #{@protein}\nCarbohidratos (g): #{@carbohydrates}\nLípidos (g): #{@lipids}\nGEI (kgCO2eq): #{@gei}\nTerreno (m2 año): #{@terrain}\n"
end