Class: Menudsl

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(etiqueta, &block) ⇒ Menudsl

Returns a new instance of Menudsl.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/menu/menudsl.rb', line 5

def initialize(etiqueta, &block) 
 self.etiqueta = etiqueta
 self.tit
 self.porcentaje
 self.platos = []
 self.vct
 
 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.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def etiqueta
  @etiqueta
end

#pGrasasObject

Returns the value of attribute pGrasas.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def pGrasas
  @pGrasas
end

#pHidratosObject

Returns the value of attribute pHidratos.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def pHidratos
  @pHidratos
end

#platosObject

Returns the value of attribute platos.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def platos
  @platos
end

#porcentajeObject

Returns the value of attribute porcentaje.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def porcentaje
  @porcentaje
end

#pProteinasObject

Returns the value of attribute pProteinas.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def pProteinas
  @pProteinas
end

#titObject

Returns the value of attribute tit.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def tit
  @tit
end

#vctObject

Returns the value of attribute vct.



3
4
5
# File 'lib/menu/menudsl.rb', line 3

def vct
  @vct
end

Instance Method Details

#<=>(other) ⇒ Object



55
56
57
58
59
# File 'lib/menu/menudsl.rb', line 55

def <=>(other)
    if(other.instance_of? Menudsl)
    @vct <=> other.vct
    end
end

#ingesta(opciones = {}) ⇒ Object



25
26
27
# File 'lib/menu/menudsl.rb', line 25

def ingesta(opciones = {})  
    @porcentaje = "(#{opciones[:min]}% - #{opciones[:max]}%)" 
end

#plato(opciones = {}) ⇒ Object



29
30
31
32
# File 'lib/menu/menudsl.rb', line 29

def plato(opciones = {})
    plato= Plato.new(opciones[:nombre], opciones[:porcion], "#{opciones[:gramos]} gramos") 
    platos << plato
end

#porcentajes(opciones = {}) ⇒ Object



34
35
36
37
38
39
# File 'lib/menu/menudsl.rb', line 34

def porcentajes(opciones = {})
      @vct = "#{opciones[:vct]} Kcal"
      @pProteinas = "#{opciones[:proteinas]}%"
      @pGrasas = "#{opciones[:grasas]}%"
      @pHidratos = "#{opciones[:hidratos]}%"
end

#titulo(titul) ⇒ Object



21
22
23
# File 'lib/menu/menudsl.rb', line 21

def titulo(titul)
  @tit = titul
end

#to_sObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/menu/menudsl.rb', line 41

def to_s
      i = 0 
      salida = "#{@tit} (#{@porcentaje})\n"
      while i < @platos.length do
          salida +=   @platos[i].to_s + "\n"
          i += 1
      end

      salida += "V.C.T. ( #{@vct} ) #{@pProteinas} - #{@pGrasas} - #{@pHidratos}"

      salida
end