Class: Dieta

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

Overview

Clase que representa un menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, &block) ⇒ Dieta

Constructor de la clase



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/menus/dieta.rb', line 13

def initialize(label, &block)
    self.label = label
    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

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#platosObject

Returns the value of attribute platos.



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

def platos
  @platos
end

#porcentajeObject

Returns the value of attribute porcentaje.



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

def porcentaje
  @porcentaje
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#titulo_porcentajeObject

Returns the value of attribute titulo_porcentaje.



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

def titulo_porcentaje
  @titulo_porcentaje
end

Instance Method Details

#<=>(other) ⇒ Object



8
9
10
# File 'lib/menus/dieta.rb', line 8

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

#plato(options = {}) ⇒ Object

Obtener un plato



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

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



49
50
51
52
53
54
# File 'lib/menus/dieta.rb', line 49

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



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

def titulo(text)
    title << text
end

#titulo_porcentajes(options = {}) ⇒ Object

Obtener porcentaje



34
35
36
37
# File 'lib/menus/dieta.rb', line 34

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

#to_sObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/menus/dieta.rb', line 56

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