Class: MenuDSL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &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(name,&block)
    self.name = name
    self.titul = []
    self.ingest = []
    self.plato = []
    self.porcent = []
    
    if block_given?
        if block.arity == 1
            yield self
        else
            instance_eval &block
        end
    end
end

Instance Attribute Details

#ingestObject

Returns the value of attribute ingest.



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

def ingest
  @ingest
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#platoObject

Returns the value of attribute plato.



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

def plato
  @plato
end

#porcentObject

Returns the value of attribute porcent.



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

def porcent
  @porcent
end

#titulObject

Returns the value of attribute titul.



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

def titul
  @titul
end

Instance Method Details

#ingesta(text, options = {}) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/menu/menudsl.rb', line 63

def ingesta(text, options = {})
    ing = text
    ing << "#{options[:min]} -" if options[:min]
    ing << " #{options[:max]} %" if options[:max]
    
    ingest << ing
end

#platos(text, options = {}) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/menu/menudsl.rb', line 71

def platos(text, options = {})
    plat = text
    plat << "#{options[:description]}, " if options[:description]
    plat << "#{options[:porcion]}, " if options[:porcion]
    plat << "#{options[:gramos]}" if options[:gramos]
    
    plato << plat
end

#porcentajes(text, options = {}) ⇒ Object



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

def porcentajes(text,options = {})
    porcentaje = text
    porcentaje << "#{options[:vct]} kcal | " if options[:vct]
    porcentaje << "#{options[:proteinas]}% - " if options[:proteinas]
    porcentaje << "#{options[:grasas]}% - " if options[:grasas]
    porcentaje << "#{options[:hidratos]}%" if options[:hidratos]
    
    porcent << porcentaje
end

#titulo(text, options = {}) ⇒ Object



47
48
49
50
51
# File 'lib/menu/menudsl.rb', line 47

def titulo(text, options = {})
    title = text
    
    titul << title
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/menu/menudsl.rb', line 21

def to_s

    output = "#{name}\n"
    titul.each do |title|
        output << "#{title}"
        output << "\n#{'=' * title.size}\n"
    end
    
    ingest.each do |ing|
        output << "#{ing}"
    end

    plato.each_with_index do |plat, index|
        output << "\n#{index + 1})#{plat}"
    end
    
    output << "\nV.C.T | % "
    
    porcent.each do |porcentaje|
        output << "#{porcentaje}"
    end
    output << "\n"
    
    output
end