Class: Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/Dieta/Menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(etiqueta, &block) ⇒ Menu

Returns a new instance of Menu.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/Dieta/Menu.rb', line 4

def initialize(etiqueta,&block)
    self.etiqueta=etiqueta
    self.title = ""
    self.ingest = []
    self.platos = []
    self.porcentaje = []
    if block_given?  
      if block.arity == 1
        yield self
      else
        instance_eval(&block)
      end
    end
end

Instance Attribute Details

#etiquetaObject

Returns the value of attribute etiqueta.



2
3
4
# File 'lib/Dieta/Menu.rb', line 2

def etiqueta
  @etiqueta
end

#ingestObject

Returns the value of attribute ingest.



2
3
4
# File 'lib/Dieta/Menu.rb', line 2

def ingest
  @ingest
end

#platosObject

Returns the value of attribute platos.



2
3
4
# File 'lib/Dieta/Menu.rb', line 2

def platos
  @platos
end

#porcentajeObject

Returns the value of attribute porcentaje.



2
3
4
# File 'lib/Dieta/Menu.rb', line 2

def porcentaje
  @porcentaje
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/Dieta/Menu.rb', line 2

def title
  @title
end

Instance Method Details

#ingesta(options = {}) ⇒ Object



24
25
26
27
# File 'lib/Dieta/Menu.rb', line 24

def ingesta(options = {})
    ingest << "#{options[:min]}"
    ingest << "#{options[:max]}"
end

#plato(options = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/Dieta/Menu.rb', line 29

def plato(options = {})
    plat = []
    plat << "#{options[:descripcion]}"
    plat << "#{options[:porcion]}"
    plat << "#{options[:gramos]}"
    platos << plat
end

#porcentajes(options = {}) ⇒ Object



36
37
38
39
40
41
# File 'lib/Dieta/Menu.rb', line 36

def porcentajes(options = {})
    porcentaje << "#{options[:vct]}"
    porcentaje << "#{options[:proteinas]}"
    porcentaje << "#{options[:grasas]}"
    porcentaje << "#{options[:hidratos]}"
end

#titulo(options = {}) ⇒ Object



20
21
22
# File 'lib/Dieta/Menu.rb', line 20

def titulo(options = {})
    title << "#{options[:titulo]}"
end

#to_sObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/Dieta/Menu.rb', line 43

def to_s
    output = "#{title}\n"
    output << "#{'#' * title.size}\n\n"
    output << "Entre{"
    ingest.each do |p|
        output << p + " "
     end
     output << "}\n"
     platos.each do |p|
        p.each do |x|
            output << x + " "
        end
        output << "g \n"
     end
     porcentaje.each do |p|
        output << p + " "
     end
    output
end