Class: Menu_DSL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dia, &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
19
20
21
# File 'lib/menu/codigo_menu_dsl.rb', line 4

def initialize(dia, &block)
	self.dia = dia
	self.titu = ""
	self.porc = []
	self.plat = []
	self.vct = nil
	self.prot = nil
	self.gras = nil
	self.hidr = nil

	if block_given?
		if block.arity == 1
			yield self
		else
			instance_eval(&block)
		end
	end
end

Instance Attribute Details

#diaObject

Returns the value of attribute dia.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def dia
  @dia
end

#grasObject

Returns the value of attribute gras.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def gras
  @gras
end

#hidrObject

Returns the value of attribute hidr.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def hidr
  @hidr
end

#platObject

Returns the value of attribute plat.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def plat
  @plat
end

#porcObject

Returns the value of attribute porc.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def porc
  @porc
end

#protObject

Returns the value of attribute prot.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def prot
  @prot
end

#tituObject

Returns the value of attribute titu.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def titu
  @titu
end

#vctObject

Returns the value of attribute vct.



2
3
4
# File 'lib/menu/codigo_menu_dsl.rb', line 2

def vct
  @vct
end

Instance Method Details

#ingesta(options = {}) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/menu/codigo_menu_dsl.rb', line 47

def ingesta (options = {})
	porcentaje = []
	porcentaje << options[:min] if options[:min]
	porcentaje << options[:max] if options[:max]

	porc << porcentaje
end

#plato(options = {}) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/menu/codigo_menu_dsl.rb', line 55

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

	plat << platos
end

#porcentajes(options = {}) ⇒ Object



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

def porcentajes (options = {})
	@vct = options[:kcals] if options[:kcals]
	@prot = options[:proteinas] if options[:proteinas]
	@gras = options[:grasas] if options[:grasas]
	@hidr = options[:hidratos] if options[:hidratos]
end

#titulo(titul) ⇒ Object



43
44
45
# File 'lib/menu/codigo_menu_dsl.rb', line 43

def titulo (titul)
	titu << titul
end

#to_sObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/menu/codigo_menu_dsl.rb', line 23

def to_s
	output = "\n#{dia}"
	output << "\n#{'=' * dia.size}\n\n"
	output << "#{titu} | (#{porc.join(' - ')})%\n"
	plat.each_with_index do |platos|
		output << "- "
		platos.each_with_index do |plato, index|
			output << "#{plato}"
			if index+1 != platos.size
				output << ", "
			end
		end
		output << "\n"
	end
	output << "V.C.T | %\t#{vct} kcal | "
	output << "#{prot}% - #{gras}% - #{hidr}%"

	output
end