Class: Nutri
Overview
Manages all the informations a normal etiquett contains.
Instance Attribute Summary collapse
-
#energy ⇒ Object
readonly
Returns the value of attribute energy.
-
#fat ⇒ Object
readonly
Returns the value of attribute fat.
-
#hydrates ⇒ Object
readonly
Returns the value of attribute hydrates.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#protein ⇒ Object
readonly
Returns the value of attribute protein.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
-
#sfats ⇒ Object
readonly
Returns the value of attribute sfats.
-
#sugar ⇒ Object
readonly
Returns the value of attribute sugar.
Instance Method Summary collapse
-
#<=>(other) ⇒ bool
Defines wich value should be compared.
-
#initialize(name, fat, sfats, hydrates, sugar, protein, salt) ⇒ nil
constructor
[initialize the obj].
-
#senergy ⇒ string
Prints the calculated energy as a string.
-
#sfat ⇒ string
Prints fat as a string.
-
#shydrates ⇒ string
Prints hydrates as a string.
-
#sname ⇒ string
Prints name as a string.
-
#sprotein ⇒ string
Prints protein as a string.
-
#ssalt ⇒ string
Prints salt as a string.
-
#ssfats ⇒ string
Prints sfats as a string.
-
#ssugar ⇒ string
Prints sugar as a string.
-
#to_s ⇒ string
Prints the whole etiquetta as a string.
Constructor Details
#initialize(name, fat, sfats, hydrates, sugar, protein, salt) ⇒ nil
- initialize the obj
37 38 39 40 41 |
# File 'lib/prct06/nutri.rb', line 37 def initialize(name, fat, sfats, hydrates, sugar, protein, salt) @name, @fat, @sfats, @hydrates, @sugar, @protein, @salt = name, fat, sfats, hydrates, sugar, protein, salt @energy = 0.0 senergy() end |
Instance Attribute Details
#energy ⇒ Object (readonly)
Returns the value of attribute energy.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def energy @energy end |
#fat ⇒ Object (readonly)
Returns the value of attribute fat.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def fat @fat end |
#hydrates ⇒ Object (readonly)
Returns the value of attribute hydrates.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def hydrates @hydrates end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def name @name end |
#protein ⇒ Object (readonly)
Returns the value of attribute protein.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def protein @protein end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def salt @salt end |
#sfats ⇒ Object (readonly)
Returns the value of attribute sfats.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def sfats @sfats end |
#sugar ⇒ Object (readonly)
Returns the value of attribute sugar.
13 14 15 |
# File 'lib/prct06/nutri.rb', line 13 def sugar @sugar end |
Instance Method Details
#<=>(other) ⇒ bool
Defines wich value should be compared
21 22 23 |
# File 'lib/prct06/nutri.rb', line 21 def <=>(other) @name <=> other.name end |
#senergy ⇒ string
Prints the calculated energy as a string.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/prct06/nutri.rb', line 111 def senergy v1 = [@fat, @hydrates, @protein, @salt] v2 = [37, 17, 17, 25] v3 = [9, 4, 4, 6] s1 = 0 s2 = 0 i = 0 while (i < v1.length) s1 += v1[i] * v2[i] s2 += v1[i] * v3[i] i += 1 end @energy = s2 return "#{s1.round(2)} kJ/g / #{s2.round(2)} kcal/g\n" end |
#sfat ⇒ string
Prints fat as a string.
55 56 57 |
# File 'lib/prct06/nutri.rb', line 55 def sfat "#{@fat}" end |
#shydrates ⇒ string
Prints hydrates as a string.
71 72 73 |
# File 'lib/prct06/nutri.rb', line 71 def shydrates "#{@hydrates}" end |
#sname ⇒ string
Prints name as a string.
47 48 49 |
# File 'lib/prct06/nutri.rb', line 47 def sname "#{@name}" end |
#sprotein ⇒ string
Prints protein as a string.
87 88 89 |
# File 'lib/prct06/nutri.rb', line 87 def sprotein "#{@protein}" end |
#ssalt ⇒ string
Prints salt as a string.
95 96 97 |
# File 'lib/prct06/nutri.rb', line 95 def ssalt "#{@salt}" end |
#ssfats ⇒ string
Prints sfats as a string.
63 64 65 |
# File 'lib/prct06/nutri.rb', line 63 def ssfats "#{@sfats}" end |
#ssugar ⇒ string
Prints sugar as a string.
79 80 81 |
# File 'lib/prct06/nutri.rb', line 79 def ssugar "#{@sugar}" end |
#to_s ⇒ string
Prints the whole etiquetta as a string.
103 104 105 |
# File 'lib/prct06/nutri.rb', line 103 def to_s return "Name: \t\t#{@name}\nfat: \t\t#{@fat}\nsat.fats: \t#{@sfats}\nhydrates: \t#{@hydrates}\nsugar: \t\t#{@sugar}\nprotein: \t#{@protein}\nsalt: \t\t#{@salt}\n" end |