Class: Menu
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #almuerzo(h = {}) ⇒ Object
- #cena(h = {}) ⇒ Object
- #desayuno(h = {}) ⇒ Object
- #ingesta(h = {}) ⇒ Object
-
#initialize(day, &block) ⇒ Menu
constructor
A new instance of Menu.
- #kcal ⇒ Object
- #titulo(str) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(day, &block) ⇒ Menu
Returns a new instance of Menu.
5 6 7 8 9 10 11 12 13 |
# File 'lib/alu0101042305/menu.rb', line 5 def initialize(day,&block) @day = day @almuerzo = [] @cena = [] @desayuno = [] if block_given? instance_eval &block end end |
Class Method Details
.each_sort(menus) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/alu0101042305/menu.rb', line 82 def self.each_sort() array = Array.new .each do || sz = array.size array.each_with_index do |,i| array.insert(i,) if > and sz == array.size end array << if sz == array.size end array end |
.for_sort(menus) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/alu0101042305/menu.rb', line 69 def self.for_sort() for i in (0...size-2) for j in (i+1...size-1) if([i] > [j]) aux = [i]; [i] = [j]; [j] = aux; end end end end |
Instance Method Details
#<=>(other) ⇒ Object
43 44 45 |
# File 'lib/alu0101042305/menu.rb', line 43 def <=> (other) self.kcal <=> other.kcal end |
#almuerzo(h = {}) ⇒ Object
29 30 31 32 |
# File 'lib/alu0101042305/menu.rb', line 29 def almuerzo(h = {}) @almuerzo << Label.new(h[:descripcion],h[:gramos],h[:grasas],0,h[:carbohidratos],0,h[:proteinas], h[:sal]) end |
#cena(h = {}) ⇒ Object
34 35 36 37 |
# File 'lib/alu0101042305/menu.rb', line 34 def cena(h = {}) @cena << Label.new(h[:descripcion],h[:gramos],h[:grasas],0,h[:carbohidratos],0,h[:proteinas], h[:sal]) end |
#desayuno(h = {}) ⇒ Object
24 25 26 27 |
# File 'lib/alu0101042305/menu.rb', line 24 def desayuno(h = {}) @desayuno << Label.new(h[:descripcion],h[:gramos],h[:grasas],0,h[:carbohidratos],0,h[:proteinas], h[:sal]) end |
#ingesta(h = {}) ⇒ Object
19 20 21 22 |
# File 'lib/alu0101042305/menu.rb', line 19 def ingesta(h = {}) @min = h[:min] if h[:min] @max = h[:max] if h[:max] end |
#kcal ⇒ Object
39 40 41 |
# File 'lib/alu0101042305/menu.rb', line 39 def kcal (@desayuno.reduce(:+) + @cena.reduce(:+) + @almuerzo.reduce(:+)).round(2) end |
#titulo(str) ⇒ Object
15 16 17 |
# File 'lib/alu0101042305/menu.rb', line 15 def titulo(str) @title = str end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/alu0101042305/menu.rb', line 47 def to_s table = Table.new table << @day table << '' << 'grasas' << 'carbohidratos' << 'proteinas' << 'sal' << 'valor energético' table << 'Desayuno' @desayuno.each do |label| table << label.nombre << label.grasas << label.hc << label.protei << label.sal << label.kcal end table << '' table << 'Almuerzo' @almuerzo.each do |label| table << label.nombre << label.grasas << label.hc << label.protei << label.sal << label.kcal end table << '' table << 'Cena' @cena.each do |label| table << label.nombre << label.grasas << label.hc << label.protei << label.sal << label.kcal end table << 'Valor energético total' << self.kcal table.to_s end |