Class: Menu_dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/prct08/menu_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(etiqueta, &block) ⇒ Menu_dsl

Returns a new instance of Menu_dsl.



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

def initialize(etiqueta, &block)
    self.etiqueta = etiqueta
    self.titulo = ""
    self.ingestaIn = []
    self.platosIn = []
    self.porcentajeIn = []
    
    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/prct08/menu_dsl.rb', line 2

def etiqueta
  @etiqueta
end

#ingestaInObject

Returns the value of attribute ingestaIn.



2
3
4
# File 'lib/prct08/menu_dsl.rb', line 2

def ingestaIn
  @ingestaIn
end

#platosInObject

Returns the value of attribute platosIn.



2
3
4
# File 'lib/prct08/menu_dsl.rb', line 2

def platosIn
  @platosIn
end

#porcentajeInObject

Returns the value of attribute porcentajeIn.



2
3
4
# File 'lib/prct08/menu_dsl.rb', line 2

def porcentajeIn
  @porcentajeIn
end

#tituloObject

Returns the value of attribute titulo.



2
3
4
# File 'lib/prct08/menu_dsl.rb', line 2

def titulo
  @titulo
end

Instance Method Details

#ingesta(options = {}) ⇒ Object



24
25
26
27
# File 'lib/prct08/menu_dsl.rb', line 24

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

#platos(options = {}) ⇒ Object



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

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

#porcentajes(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/prct08/menu_dsl.rb', line 37

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

#titulos(options = {}) ⇒ Object



20
21
22
# File 'lib/prct08/menu_dsl.rb', line 20

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

#to_sObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/prct08/menu_dsl.rb', line 46

def to_s
    out = "#{titulo}"
    out << "\nMinima: #{ingestaIn[0]} % - Maximo: #{ingestaIn[1]} %"
    platosIn.each_with_index do |plato, index|
        out << "\n\tDescripcion: #{plato[0]} \n\tPorcion: #{plato[1]} \n\tGramos: #{plato[2]}\n"
    end
    porcentajeIn.each_with_index do |porcentaje, index| 
        out << "\n\tV.C.T: #{porcentaje[0]} \n\tProteinas: #{porcentaje[1]} \n\tGrasas: #{porcentaje[2]} \n\tHidratos:#{porcentaje[3]} \n"
    end
    out
end