Class: Etiqueta

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, fat, sat_fat, carbs, sugar, proteins, salt) ⇒ Etiqueta

Método initialize => Se crea la etiqueta

Parameters:

  • nombre (String)

    nombre del alimento

  • fat (Numeric)

    grasas

  • sat_fat (Numeric)

    grasas saturadas

  • carbs (Numeric)

    hidratos de carbono

  • sugar (Numeric)

    azúcares

  • proteins (Numeric)

    proteinas

  • salt (Numeric)

    sal



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nutritag/label.rb', line 41

def initialize(nombre, fat, sat_fat, carbs, sugar, proteins, salt)

	@nombre=nombre
	@fat=fat
   		@sat_fat=sat_fat
   		@carbs=carbs
   		@sugar=sugar
   		@proteins=proteins
   		@salt=salt
	@v_energetic=[self.conver_kJ,self.conver_kcal]
	@portion=0.35
	@p=self.portion_calc
	@ir=[8400.0,2000.0,70.0,20.0,260.0,90.0,50.0,6.0]
	@ir_percent=self.ir_calc

end

Instance Attribute Details

#carbsObject (readonly)

Returns the value of attribute carbs.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def carbs
  @carbs
end

#fatObject (readonly)

Returns the value of attribute fat.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def fat
  @fat
end

#irObject (readonly)

Returns the value of attribute ir.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def ir
  @ir
end

#ir_percentObject (readonly)

Returns the value of attribute ir_percent.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def ir_percent
  @ir_percent
end

#nombreObject (readonly)

Returns the value of attribute nombre.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def nombre
  @nombre
end

#pObject (readonly)

Returns the value of attribute p.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def p
  @p
end

#portionObject (readonly)

Returns the value of attribute portion.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def portion
  @portion
end

#proteinsObject (readonly)

Returns the value of attribute proteins.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def proteins
  @proteins
end

#saltObject (readonly)

Returns the value of attribute salt.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def salt
  @salt
end

#sat_fatObject (readonly)

Returns the value of attribute sat_fat.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def sat_fat
  @sat_fat
end

#sugarObject (readonly)

Returns the value of attribute sugar.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def sugar
  @sugar
end

#v_energeticObject (readonly)

Returns the value of attribute v_energetic.



27
28
29
# File 'lib/nutritag/label.rb', line 27

def v_energetic
  @v_energetic
end

Instance Method Details

#<=>(other) ⇒ Object

Método del módulo comparable



87
88
89
90
# File 'lib/nutritag/label.rb', line 87

def <=>(other)
	return nil unless other.is_a?Etiqueta
	conver_kcal <=> other.conver_kcal
end

#conver_kcalNumeric

Método conver_kcal => Conversión de los diferentes nutrientes

Returns:

  • (Numeric)

    devuelve el valor energético en kcal



68
69
70
# File 'lib/nutritag/label.rb', line 68

def conver_kcal
(9.0*@fat) + (4.0*@carbs) + (4.0*@proteins) + (6.0*@salt)
end

#conver_kJNumeric

Método conver_kJ => Conversión de los diferentes nutrientes

Returns:

  • (Numeric)

    devuelve el valor energético en kJ



61
62
63
# File 'lib/nutritag/label.rb', line 61

def conver_kJ
	(37.0*@fat) + (17.0*@carbs) + (17.0*@proteins) + (25.0*@salt)
end

#ir_calcArray

Método ir_calc => Calcula el IR

Returns:

  • (Array)

    devuele la ingesta recomendada



82
83
84
# File 'lib/nutritag/label.rb', line 82

def ir_calc
 	[((@v_energetic[0]/@ir[0]).round(1)*100),((@v_energetic[1]/@ir[1]).round(1)*100),((@fat/@ir[2]).round(1)*100),((@sat_fat/@ir[3]).round(1)*100),((@carbs/@ir[4]).round(1)*100),((@sugar/@ir[5]).round(1)*100),((@proteins/@ir[6]).round(1)*100),((@salt/@ir[7]).round(1)*100)]
end

#portion_calcArray

Método portion_calc => Calcula la porción

Returns:

  • (Array)

    devuelve un array con los nutrientes por porción



75
76
77
# File 'lib/nutritag/label.rb', line 75

def portion_calc
 	[(self.conver_kJ*@portion).round(1),(self.conver_kcal*@portion).round(1),(@fat*@portion).round(1),(@sat_fat*@portion).round(1),(@carbs*@portion).round(1),(@sugar*@portion).round(1),(@proteins*@portion).round(1),(@salt*@portion).round(1)]
end

#to_sString

Método to_s => Imprime por pantalla

Returns:

  • (String)

    devuelve la etiqueta formateada



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/nutritag/label.rb', line 95

def to_s
 	puts "Nombre del Producto: #{@nombre}"
 	puts "\t\t\t\t\tPor 100g| Por porción de #{@portion*100}g  | IR (por 100g) |"
 	puts "Valor energético: \t  #{@v_energetic[0]}(kJ)/#{@v_energetic[1]}(kcal)| #{@p[0]}(kJ)/ #{@p[1]}(kcal)|\t#{@ir_percent[0]}%\t|"
 	puts "Grasas \t\t\t\t\t#{@fat} g\t|\t\t#{@p[2]} g\t|\t#{@ir_percent[2]}%\t|"
 	puts "de las cuales saturadas: \t\t#{@sat_fat} g\t|\t\t#{@p[3]} g\t|\t#{@ir_percent[3]}%\t|"
 	puts "Hidratos \t\t\t\t#{@carbs} g\t|\t\t#{@p[4]} g\t|\t#{@ir_percent[4]}%\t|"
 	puts "de los cuales azúcares: \t\t#{@sugar} g\t|\t\t#{@p[5]} g\t|\t#{@ir_percent[5]}%\t|"
 	puts "Proteínas: \t\t\t\t#{@proteins} g\t|\t\t#{@p[6]} g\t|\t#{@ir_percent[6]}%\t|"
 	puts "Sal: \t\t\t\t\t#{@salt} g\t|\t\t#{@p[7]} g\t|\t#{@ir_percent[7]}%\t|"
end