Class: Label
Constant Summary collapse
- @@ir =
{:kj => 8400, :kcal => 2000, :grasas => 70, :grasass => 20, :hc => 260, :azucar => 90, :protei => 50, :sal => 6}
Instance Attribute Summary collapse
-
#azucar ⇒ Object
readonly
Returns the value of attribute azucar.
-
#grasas ⇒ Object
readonly
Returns the value of attribute grasas.
-
#grasass ⇒ Object
readonly
Returns the value of attribute grasass.
-
#hc ⇒ Object
readonly
Returns the value of attribute hc.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
-
#porcion ⇒ Object
readonly
Returns the value of attribute porcion.
-
#protei ⇒ Object
readonly
Returns the value of attribute protei.
-
#sal ⇒ Object
readonly
Returns the value of attribute sal.
Instance Method Summary collapse
- #+(label) ⇒ Object
- #<=>(label) ⇒ Object
- #coerce(arg) ⇒ Object
-
#initialize(nombre, porcion, grasas, grasass, hc, azucar, protei, sal) ⇒ Label
constructor
A new instance of Label.
- #ir(method) ⇒ Object
- #kcal ⇒ Object
- #kj ⇒ Object
- #to_s ⇒ Object
- #toX(method, arg = nil) ⇒ Object
Constructor Details
#initialize(nombre, porcion, grasas, grasass, hc, azucar, protei, sal) ⇒ Label
Returns a new instance of Label.
10 11 12 13 |
# File 'lib/alu0101042305/label.rb', line 10 def initialize(nombre, porcion, grasas, grasass, hc, azucar, protei, sal) @nombre, @porcion, @grasas, @grasass, @hc, @azucar, @protei, @sal = nombre, porcion, grasas, grasass, hc, azucar, protei, sal end |
Instance Attribute Details
#azucar ⇒ Object (readonly)
Returns the value of attribute azucar.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def azucar @azucar end |
#grasas ⇒ Object (readonly)
Returns the value of attribute grasas.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def grasas @grasas end |
#grasass ⇒ Object (readonly)
Returns the value of attribute grasass.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def grasass @grasass end |
#hc ⇒ Object (readonly)
Returns the value of attribute hc.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def hc @hc end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def nombre @nombre end |
#porcion ⇒ Object (readonly)
Returns the value of attribute porcion.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def porcion @porcion end |
#protei ⇒ Object (readonly)
Returns the value of attribute protei.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def protei @protei end |
#sal ⇒ Object (readonly)
Returns the value of attribute sal.
5 6 7 |
# File 'lib/alu0101042305/label.rb', line 5 def sal @sal end |
Instance Method Details
#+(label) ⇒ Object
23 24 25 |
# File 'lib/alu0101042305/label.rb', line 23 def + (label) self.kcal + label.kcal end |
#<=>(label) ⇒ Object
43 44 45 46 47 |
# File 'lib/alu0101042305/label.rb', line 43 def <=>(label) return -1 if self.sal < label.sal return 1 if self.sal > label.sal return self.nombre <=> label.nombre end |
#coerce(arg) ⇒ Object
27 28 29 |
# File 'lib/alu0101042305/label.rb', line 27 def coerce(arg) [arg,self.kcal] end |
#ir(method) ⇒ Object
39 40 41 |
# File 'lib/alu0101042305/label.rb', line 39 def ir(method) ((send(method)*100)/@@ir[method]).round(2) end |
#kcal ⇒ Object
19 20 21 |
# File 'lib/alu0101042305/label.rb', line 19 def kcal grasas * 9 + hc * 4 + protei * 4 + sal * 6 end |
#kj ⇒ Object
15 16 17 |
# File 'lib/alu0101042305/label.rb', line 15 def kj grasas * 37 + hc * 17 + protei * 17 + sal * 25 end |
#to_s ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/alu0101042305/label.rb', line 49 def to_s str = String.new str << @nombre << "\n" str << "\t\t\t Por 100g\t IR (100g)\t Por #{@porcion}g\t IR(#{@porcion}g)\n" str << "Valor energético\t #{kj}kJ/#{kcal}kcal\t #{ir(:kcal)}%\t #{toX(:kj)}kJ/#{toX(:kcal)}kcal\t #{toX(:ir,:kcal)}%\n" str <<"Grasas\t\t\t #{@grasas}g\t\t #{ir(:grasas)}%\t\t #{toX(:grasas)}g\t\t #{toX(:ir,:grasas)}%\n" str <<" saturadas:\t\t #{@grasass}g\t\t #{ir(:grasass)}%\t\t #{toX(:grasass)}g\t\t #{toX(:ir,:grasass)}%\n" str <<"Hidratos de carbono\t #{@hc}g\t\t #{ir(:hc)}%\t\t #{toX(:hc)}g\t\t #{toX(:ir,:hc)}%\n" str <<" azúcares:\t\t #{@azucar}g\t\t #{ir(:azucar)}%\t\t #{toX(:azucar)}g\t\t #{toX(:ir,:azucar)}%\n" str <<"Proteínas\t\t #{@protei}g\t\t #{ir(:protei)}%\t\t #{toX(:protei)}g\t\t #{toX(:ir,:protei)}%\n" str <<"Sal\t\t\t #{@sal}g\t\t #{ir(:sal)}%\t\t #{toX(:sal)}g\t\t #{toX(:ir,:sal)}%\n" end |
#toX(method, arg = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/alu0101042305/label.rb', line 31 def toX(method, arg = nil) if arg == nil ((send(method)*@porcion)/100).round(2) else ((send(method, arg)*@porcion)/100).round(2) end end |