Class: Harvard_DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/alimentos/harvard_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Harvard_DSL

Returns a new instance of Harvard_DSL.



4
5
6
7
8
9
# File 'lib/alimentos/harvard_dsl.rb', line 4

def initialize(name, &block)
  self.name = name
  self.platos = []

  instance_eval &block
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/alimentos/harvard_dsl.rb', line 2

def name
  @name
end

#platosObject

Returns the value of attribute platos.



2
3
4
# File 'lib/alimentos/harvard_dsl.rb', line 2

def platos
  @platos
end

Instance Method Details

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



39
40
41
42
43
44
# File 'lib/alimentos/harvard_dsl.rb', line 39

def aceite(titulo,options = {})
  platos << titulo
  platos << " (#{options[:porcion]})" if options[:porcion]
  platos << " (#{options[:gramos]})" if options[:gramos]
  platos << "\n"
end

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



25
26
27
28
29
30
# File 'lib/alimentos/harvard_dsl.rb', line 25

def cereal(titulo,options = {})
  platos << titulo
  platos << " (#{options[:porcion]})" if options[:porcion]
  platos << " (#{options[:gramos]})" if options[:gramos]
  platos << "\n"
end

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



18
19
20
21
22
23
# File 'lib/alimentos/harvard_dsl.rb', line 18

def fruta(titulo,options = {})
  platos << titulo
  platos << " (#{options[:porcion]})" if options[:porcion]
  platos << " (#{options[:gramos]})" if options[:gramos]
  platos << "\n"
end

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



32
33
34
35
36
37
# File 'lib/alimentos/harvard_dsl.rb', line 32

def proteina(titulo,options = {})
  platos << titulo
  platos << " (#{options[:porcion]})" if options[:porcion]
  platos << " (#{options[:gramos]})" if options[:gramos]
  platos << "\n"
end

#to_sObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/alimentos/harvard_dsl.rb', line 46

def to_s
  output = ""
  output << name
  output << "\n"
  for i in 0..name.size-1 do
	output << "="
  end
  output << "\n"
  output << "\nComposiciĆ³n nutricional:\n"    
  output << "\n"
  platos.each_with_index do |plato, index|
    output << "#{plato}"
    if index>0
       if (index-1) % 3 == 1
          output << "\n"
       end
    end
  end

  output
end

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



11
12
13
14
15
16
# File 'lib/alimentos/harvard_dsl.rb', line 11

def vegetal(titulo, options = {})
  platos << titulo
  platos << " (#{options[:porcion]})" if options[:porcion]
  platos << " (#{options[:gramos]})" if options[:gramos]
  platos << "\n"
end