Class: DslDieta

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/prct06/dslDieta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(titulo, &block) ⇒ DslDieta

Returns a new instance of DslDieta

Parameters:

  • Título, (String)
    Block

    Block



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/prct06/dslDieta.rb', line 13

def initialize(titulo,&block)
	self.titulo=titulo
	self.platos =[]
	if block_given?
		if block.arity == 1
			yield self
		else
			instance_eval(&block)
		end
	end
end

Instance Attribute Details

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def grasas
  @grasas
end

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def hidratos
  @hidratos
end

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def max
  @max
end

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def min
  @min
end

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def platos
  @platos
end

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def proteinas
  @proteinas
end

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def titulo
  @titulo
end

#MObject



10
11
12
# File 'lib/prct06/dslDieta.rb', line 10

def vct
  @vct
end

Instance Method Details

#<=>(other) ⇒ Int

Note:

Función que permite comparar dos dietas en función de sus valor calorífico.

Returns 1 if self>other, 0 if self == other, -1 if self<other

Parameters:

  • Menú (Diet)

    a comparar

Returns:

  • (Int)

    1 if self>other, 0 if self == other, -1 if self<other



39
40
41
# File 'lib/prct06/dslDieta.rb', line 39

def <=>(other)
	self.vct<=>other.vct
end

#ingesta(args = {}) ⇒ Object

Note:

Función que permite asignar valor a los atributos max y min.

Parameters:

  • Parámetro (Hash)

    min y max



44
45
46
47
# File 'lib/prct06/dslDieta.rb', line 44

def ingesta(args = {})
	self.max="#{args[:max]}" if args[:max]
	self.min="#{args[:min]}" if args[:min]
end

#plato(args = {}) ⇒ Object

Note:

Función que permite añadir un nuevo plato a la dieta.

Parameters:

  • Parámetros (Hash)

    descripcion, porcion y gramos



50
51
52
53
54
55
# File 'lib/prct06/dslDieta.rb', line 50

def plato(args = {})
	input = "  -#{args[:descripcion]}" if args[:descripcion] 
	input += ", #{args[:porcion]}" if args[:porcion]
	input += ", #{args[:gramos]} gramos" if args[:gramos]
	self.platos << "#{input}"
end

#porcentajes(args = {}) ⇒ Object

Note:

Función que permite asignar valor a los parámetros: vct, proteinas, grasas y hidratos.

Parameters:

  • Parámetros (Hash)

    descripcion, porcion y gramos



58
59
60
61
62
63
# File 'lib/prct06/dslDieta.rb', line 58

def porcentajes(args = {})
	self.vct="#{args[:vct]}" if args[:vct]
	self.proteinas="#{args[:proteinas]}" if args[:proteinas]
	self.grasas="#{args[:grasas]}" if args[:grasas]
	self.hidratos="#{args[:hidratos]}" if args[:hidratos]
end

#to_sString

Returns String con el contenido de la lista

Returns:

  • (String)

    String con el contenido de la lista



26
27
28
29
30
31
32
33
34
35
# File 'lib/prct06/dslDieta.rb', line 26

def  to_s
	output = "#{titulo} (#{min}-#{max}%):\n"
	i=0
	begin
		output+="#{platos[i]}\n"
		i+=1
	end while (i<platos.length)
	output += "V.C.T. | %      #{vct} kcal | #{proteinas}% - #{grasas}% - #{hidratos}%\n"
	"#{output}"
end