Class: Etiqueta
Instance Attribute Summary collapse
-
#carbs ⇒ Object
readonly
Returns the value of attribute carbs.
-
#fat ⇒ Object
readonly
Returns the value of attribute fat.
-
#ir ⇒ Object
readonly
Returns the value of attribute ir.
-
#ir_percent ⇒ Object
readonly
Returns the value of attribute ir_percent.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
-
#p ⇒ Object
readonly
Returns the value of attribute p.
-
#portion ⇒ Object
readonly
Returns the value of attribute portion.
-
#proteins ⇒ Object
readonly
Returns the value of attribute proteins.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
-
#sat_fat ⇒ Object
readonly
Returns the value of attribute sat_fat.
-
#sugar ⇒ Object
readonly
Returns the value of attribute sugar.
-
#v_energetic ⇒ Object
readonly
Returns the value of attribute v_energetic.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Método del módulo comparable.
-
#conver_kcal ⇒ Numeric
Método conver_kcal => Conversión de los diferentes nutrientes.
-
#conver_kJ ⇒ Numeric
Método conver_kJ => Conversión de los diferentes nutrientes.
-
#initialize(nombre, fat, sat_fat, carbs, sugar, proteins, salt) ⇒ Etiqueta
constructor
Método initialize => Se crea la etiqueta.
-
#ir_calc ⇒ Array
Método ir_calc => Calcula el IR.
-
#portion_calc ⇒ Array
Método portion_calc => Calcula la porción.
-
#to_s ⇒ String
Método to_s => Imprime por pantalla.
Constructor Details
#initialize(nombre, fat, sat_fat, carbs, sugar, proteins, salt) ⇒ Etiqueta
Método initialize => Se crea la etiqueta
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
#carbs ⇒ Object (readonly)
Returns the value of attribute carbs.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def carbs @carbs end |
#fat ⇒ Object (readonly)
Returns the value of attribute fat.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def fat @fat end |
#ir ⇒ Object (readonly)
Returns the value of attribute ir.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def ir @ir end |
#ir_percent ⇒ Object (readonly)
Returns the value of attribute ir_percent.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def ir_percent @ir_percent end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def nombre @nombre end |
#p ⇒ Object (readonly)
Returns the value of attribute p.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def p @p end |
#portion ⇒ Object (readonly)
Returns the value of attribute portion.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def portion @portion end |
#proteins ⇒ Object (readonly)
Returns the value of attribute proteins.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def proteins @proteins end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def salt @salt end |
#sat_fat ⇒ Object (readonly)
Returns the value of attribute sat_fat.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def sat_fat @sat_fat end |
#sugar ⇒ Object (readonly)
Returns the value of attribute sugar.
27 28 29 |
# File 'lib/nutritag/label.rb', line 27 def sugar @sugar end |
#v_energetic ⇒ Object (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_kcal ⇒ Numeric
Método conver_kcal => Conversión de los diferentes nutrientes
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_kJ ⇒ Numeric
Método conver_kJ => Conversión de los diferentes nutrientes
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_calc ⇒ Array
Método ir_calc => Calcula el IR
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_calc ⇒ Array
Método portion_calc => Calcula la 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_s ⇒ String
Método to_s => Imprime por pantalla
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 |