Class: Menu

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/dieta/Menu.rb

Overview

Representa un Menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Menu

Constructor



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dieta/Menu.rb', line 9

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/dieta/Menu.rb', line 4

def name
  @name
end

#platosObject

Returns the value of attribute platos.



4
5
6
# File 'lib/dieta/Menu.rb', line 4

def platos
  @platos
end

#porcentajeObject

Returns the value of attribute porcentaje.



4
5
6
# File 'lib/dieta/Menu.rb', line 4

def porcentaje
  @porcentaje
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/dieta/Menu.rb', line 4

def title
  @title
end

#titulo_porcentajeObject

Returns the value of attribute titulo_porcentaje.



4
5
6
# File 'lib/dieta/Menu.rb', line 4

def titulo_porcentaje
  @titulo_porcentaje
end

Instance Method Details

#<=>(other) ⇒ Object



60
61
62
# File 'lib/dieta/Menu.rb', line 60

def <=> (other)
       porcentajes <=> other.porcentajes
end

#ingesta(options = {}) ⇒ Object



30
31
32
33
# File 'lib/dieta/Menu.rb', line 30

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

#plato(options = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/dieta/Menu.rb', line 42

def plato(options = {})
    plat = []
    plat << "#{options[:descripcion]}" if options[:descripcion]
    plat << "#{options[:porcion]}" if options[:porcion]  
    plat << "#{options[:gramos]}" if 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]}" if options[:vct]
    porcentaje << "#{options[:proteinas]}" if options[:proteinas]
    porcentaje << "#{options[:hidratos]}" if options[:hidratos]
    porcentaje << "#{options[:grasas]}" if options[:grasas]
end

#titulo(text) ⇒ Object



26
27
28
# File 'lib/dieta/Menu.rb', line 26

def titulo(text)
   title << text
end

#to_sObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/dieta/Menu.rb', line 49

def to_s
    formato = "#{title} "
    output = formato
    output << "(" + titulo_porcentaje.map { |k| "#{k}%" }.join(" - ") + ")\n"
    platos.each do |plato|
        output << "- #{plato[0]}, #{plato[1]}, #{plato[2]}gr\n"
    end
    output << "V.C.T. | %\t #{porcentaje[0]} kcal | #{porcentaje[1]}% - #{porcentaje[2]}% - #{porcentaje[3]}%"
    return output
end