Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/InformacionNutricional/array.rb
Instance Method Summary collapse
Instance Method Details
#kcal_each ⇒ Object
24 25 26 |
# File 'lib/InformacionNutricional/array.rb', line 24 def kcal_each self.collect{|comida| comida.calculate_calories;}.reduce(:+).round(2) end |
#kcal_for ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/InformacionNutricional/array.rb', line 2 def kcal_for total = 0 for i in (0...self.size) total += self[i].calculate_calories end total end |
#sort_each ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/InformacionNutricional/array.rb', line 27 def sort_each sorted = [self[0]] self.each_with_index do |x, pos_x| if (pos_x != 0) sorted.each_with_index do |y, pos_y| if (pos_y == sorted.size-1) if (x.kcal_each < y.kcal_each) sorted.insert(pos_y, x) break else sorted.push(x) break end elsif (x.kcal_each < y.kcal_each) sorted.insert(pos_y, x) break end end end end return sorted end |
#sort_for ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/InformacionNutricional/array.rb', line 9 def sort_for sorted = [self[0]] for i in (1...self.size) actual = self[i] for j in (0..sorted.size) if (j == sorted.size) sorted.push(actual) elsif (actual.kcal_for < sorted[j].kcal_for) sorted.insert(j, actual) break end end end return sorted end |