Class: Menu

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

Overview

Clase que representa un Menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &bloque) ⇒ Menu

Returns a new instance of Menu.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/menu_dietetico/menu.rb', line 8

def initialize(name, &bloque)
    self.name = name
    self.titulo = ""
    self.ingestas = []
    self.conjunto_platos = []
    self.conjunto_valores = []
   
    if block_given?
        if bloque.arity == 1
            yield self
        else
            instance_eval(&bloque)
        end
    end
end

Instance Attribute Details

#conjunto_platosObject

Returns the value of attribute conjunto_platos.



6
7
8
# File 'lib/menu_dietetico/menu.rb', line 6

def conjunto_platos
  @conjunto_platos
end

#conjunto_valoresObject

Returns the value of attribute conjunto_valores.



6
7
8
# File 'lib/menu_dietetico/menu.rb', line 6

def conjunto_valores
  @conjunto_valores
end

#ingestasObject

Returns the value of attribute ingestas.



6
7
8
# File 'lib/menu_dietetico/menu.rb', line 6

def ingestas
  @ingestas
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/menu_dietetico/menu.rb', line 6

def name
  @name
end

#porcentajeObject

Returns the value of attribute porcentaje.



6
7
8
# File 'lib/menu_dietetico/menu.rb', line 6

def porcentaje
  @porcentaje
end

#tituloObject

Returns the value of attribute titulo.



6
7
8
# File 'lib/menu_dietetico/menu.rb', line 6

def titulo
  @titulo
end

Instance Method Details

#<=>(other) ⇒ Object

Método de Modulo Comparable#### Comparamos el valor calórico total



71
72
73
# File 'lib/menu_dietetico/menu.rb', line 71

def <=> (other)
    @vct<=> other.vct
end

#ingesta(options = {}) ⇒ Object



28
29
30
31
32
33
# File 'lib/menu_dietetico/menu.rb', line 28

def ingesta(options = {})
    ingesta = "#{options[:min]}, " if options[:min]
    ingesta << "#{options[:max]}" if options[:max]
    ingestas << ingesta
    ingestas << "\n"
end

#plato(options = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/menu_dietetico/menu.rb', line 35

def plato(options = {})
    platos = "#{options[:descripcion]}, " if options[:descripcion]
    platos << "#{options[:porcion]}, " if options[:porcion]
    platos << "#{options[:gramos]}" if options[:gramos]
    conjunto_platos << platos
    conjunto_platos << "\n"
end

#porcentajes(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/menu_dietetico/menu.rb', line 43

def porcentajes(options = {})
    porcentaje = "#{options[:vct]}, " if options[:vct]
    porcentaje << "#{options[:proteinas]} - " if options[:proteinas]
    porcentaje << "#{options[:grasas]} - " if options[:grasas]
    porcentaje << "#{options[:hidratos]}" if options[:hidratos]
    conjunto_valores << porcentaje
    conjunto_valores << "\n"
end

#titulo_(titulos) ⇒ Object



24
25
26
# File 'lib/menu_dietetico/menu.rb', line 24

def titulo_(titulos)
    self.titulo = titulos
end

#to_sObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/menu_dietetico/menu.rb', line 52

def to_s
    output = "\n"
    output << titulo
    output << "\n"
    output << "#{ingesta.join()}"
    #conjunto_platos.each_with_index do |conjunto_platos, index|
     #   output << "\n#{conjunto_platos}"
    #end
    #conjunto_valores.each_with_index do |conjunto_valores, index|
     #   output << "\n#{conjunto_valores}"
    #end
    output << "#{conjunto_platos.join()}\n"
    output << "#{conjunto_valores.join()}\n\n"
end