Class: Dsl::MenuDsl

Inherits:
Object
  • Object
show all
Includes:
List
Defined in:
lib/alimentos/dslmenu.rb

Constant Summary

Constants included from List

List::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &block) ⇒ MenuDsl

Returns a new instance of MenuDsl.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/alimentos/dslmenu.rb', line 5

def initialize(nombre, &block)
    @nombre = nombre
    @precios = List.new()
    @platos = List.new()
    if block_given?
        if block.arity == 1
            yield self
        else
            instance_eval(&block)
        end
    end
end

Instance Attribute Details

#nombreObject

Returns the value of attribute nombre.



3
4
5
# File 'lib/alimentos/dslmenu.rb', line 3

def nombre
  @nombre
end

#platosObject

Returns the value of attribute platos.



3
4
5
# File 'lib/alimentos/dslmenu.rb', line 3

def platos
  @platos
end

#preciosObject

Returns the value of attribute precios.



3
4
5
# File 'lib/alimentos/dslmenu.rb', line 3

def precios
  @precios
end

Instance Method Details

#emisionesObject



40
41
42
# File 'lib/alimentos/dslmenu.rb', line 40

def emisiones()
    @platos.collect{|x| x.emisiones()}.sum
end

#energeticoObject



25
26
27
# File 'lib/alimentos/dslmenu.rb', line 25

def energetico()
    @platos.collect{|x| x.kcal}.sum
end

#m2Object



37
38
39
# File 'lib/alimentos/dslmenu.rb', line 37

def m2()
    @platos.collect{|x| x.m2()}.sum
end

#plato(plate, options = {}) ⇒ Object



18
19
20
21
# File 'lib/alimentos/dslmenu.rb', line 18

def plato(plate,options={})
    @platos.push(plate)
    @precios.push(options[:price]) if options[:price]
end

#porcarbohidratosObject



34
35
36
# File 'lib/alimentos/dslmenu.rb', line 34

def porcarbohidratos()
    @platos.collect{|x| x.porcarbohidratos()}.sum
end

#porlipidosObject



31
32
33
# File 'lib/alimentos/dslmenu.rb', line 31

def porlipidos()
    @platos.collect{|x| x.porlipidos()}.sum
end

#porproteinasObject



28
29
30
# File 'lib/alimentos/dslmenu.rb', line 28

def porproteinas()
    @platos.collect{|x| x.porproteinas()}.sum
end

#precioObject



22
23
24
# File 'lib/alimentos/dslmenu.rb', line 22

def precio()
    @precios.collect{|x| x}.sum
end

#to_sObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/alimentos/dslmenu.rb', line 43

def to_s()
    output = "#{@nombre}"
    output << ":\n"
    @platos.zip(@precios).each do |plato,precio|
        output << "\t#{plato}\n"
    end
    output<< "Precio: #{precio()}\n"
    output<< "Proteinas: #{porproteinas()}g\n"
    output<< "Lipidos: #{porlipidos()}g\n"
    output<< "Carbohidratos: #{porcarbohidratos()}g\n"
    output<< "Kcal: #{energetico()}\n"
    output<< "M2: #{m2()}\n"
    output<< "Emisiones: #{emisiones()}\n"
    output
end