Class: Menu_DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/dieta/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Menu_DSL

Returns a new instance of Menu_DSL.



4
5
6
7
8
9
10
11
12
13
# File 'lib/dieta/dsl.rb', line 4

def initialize(name, &block)
  self.name = name
  self.ntitulo = []
  self.ingestas = []
  self.platos = []
  self.instructions = []
  self.porcientos = []

  instance_eval &block
end

Instance Attribute Details

#ingestasObject

Returns the value of attribute ingestas.



2
3
4
# File 'lib/dieta/dsl.rb', line 2

def ingestas
  @ingestas
end

#instructionsObject

Returns the value of attribute instructions.



2
3
4
# File 'lib/dieta/dsl.rb', line 2

def instructions
  @instructions
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/dieta/dsl.rb', line 2

def name
  @name
end

#ntituloObject

Returns the value of attribute ntitulo.



2
3
4
# File 'lib/dieta/dsl.rb', line 2

def ntitulo
  @ntitulo
end

#platosObject

Returns the value of attribute platos.



2
3
4
# File 'lib/dieta/dsl.rb', line 2

def platos
  @platos
end

#porcientosObject

Returns the value of attribute porcientos.



2
3
4
# File 'lib/dieta/dsl.rb', line 2

def porcientos
  @porcientos
end

Instance Method Details

#ingesta(options = {}) ⇒ Object



19
20
21
22
# File 'lib/dieta/dsl.rb', line 19

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

#plato(options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/dieta/dsl.rb', line 24

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

#porcentajes(options = {}) ⇒ Object



30
31
32
33
34
35
# File 'lib/dieta/dsl.rb', line 30

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

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



15
16
17
# File 'lib/dieta/dsl.rb', line 15

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

#to_sObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dieta/dsl.rb', line 37

def to_s
  output = ""
  output << "#{ntitulo.join(', ')}"
  output << "\n#{'=' * name.size}\n\n"
  output << "min: #{ingestas[0]} max: #{ingestas[1]}\n"

  output << "\nPlatos:\n"

  platos.each_with_index do |plato, index|
    output << "#{plato}"
    if index>0
       if (index-1) % 3 == 1
          output << "\n"
       end
    end
  end

  output << "\nPorcientos: vct:#{porcientos[0]}, proteinas:#{porcientos[1]} grasas:#{porcientos[2]} hidratos:#{porcientos[3]}\n"

  output
end