Class: Comida::Plato_bloque

Inherits:
Object
  • Object
show all
Defined in:
lib/comida/palto_bloque.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Plato_bloque

Returns a new instance of Plato_bloque.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/comida/palto_bloque.rb', line 22

def initialize(name, &block)
  @nombre = name
  @alimentos = []

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

Instance Attribute Details

#alimentosObject (readonly)

Returns the value of attribute alimentos.



20
21
22
# File 'lib/comida/palto_bloque.rb', line 20

def alimentos
  @alimentos
end

#descripcion(descrip) ⇒ Object (readonly)

Returns the value of attribute descripcion.



20
21
22
# File 'lib/comida/palto_bloque.rb', line 20

def descripcion
  @descripcion
end

#nombreObject (readonly)

Returns the value of attribute nombre.



20
21
22
# File 'lib/comida/palto_bloque.rb', line 20

def nombre
  @nombre
end

Instance Method Details

#alimento(descripcion, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/comida/palto_bloque.rb', line 39

def alimento(descripcion, options = {})
  descripcion << "(#{options[:description]})" if options[:description]
  descripcion << "(#{options[:gramos]})" if options[:gramos]

  @alimentos << descripcion
end

#to_sObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/comida/palto_bloque.rb', line 46

def to_s
  output = @nombre
  output << "\n#{'=' * @nombre.size}\n\n"
  output << "Platos : \n\n"

  @alimentos.each_with_index do |alimento, index|
    output << "#{index + 1}) #{alimento[:descripcion]}, #{alimento[:gramos]}\n"
  end

  output
end