Class: Menu

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/alu0101042305/menu.rb

Class Method Summary collapse

Instance Method Summary collapse

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(menus)
  array = Array.new
  menus.each do |menu|
    sz = array.size
    array.each_with_index do |menu2,i|
      array.insert(i,menu) if menu2 > menu and sz == array.size
    end
    array << menu 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(menus)
  for i in (0..menus.size-2)
    for j in (i+1..menus.size-1)
      if(menus[i] > menus[j])
         aux = menus[i];
         menus[i] = menus[j];
         menus[j] = aux;
      end
    end
  end
  menus
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

#kcalObject



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_sObject



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