Class: Plato

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/Dieta/plato.rb

Overview

Plato de comida

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Plato

Returns a new instance of Plato.

Parameters:

  • porcion_recomendada (String)

    Porción recomendada

  • cantidad_ingesta (String)

    Cantidad a ingerir



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/Dieta/plato.rb', line 19

def initialize (&block)
	# Inicializar variables
	if block_given?  
		# Recibimos un bloque
           if block.arity == 1
               yield self
           else
               instance_eval &block 
           end
       end
end

Instance Attribute Details

#cantidad_ingestaString (readonly)

Cantidad a ingerir

Returns:

  • (String)

    the current value of cantidad_ingesta



11
12
13
# File 'lib/Dieta/plato.rb', line 11

def cantidad_ingesta
  @cantidad_ingesta
end

#descripcionString (readonly)

Descripción del plato

Returns:

  • (String)

    the current value of descripcion



11
12
13
# File 'lib/Dieta/plato.rb', line 11

def descripcion
  @descripcion
end

#porcion_recomendadaString (readonly)

Porción recomendada

Returns:

  • (String)

    the current value of porcion_recomendada



11
12
13
# File 'lib/Dieta/plato.rb', line 11

def porcion_recomendada
  @porcion_recomendada
end

Instance Method Details

#<=>(other) ⇒ Object

Función de comparación para Mixin Comparable



62
63
64
65
66
67
68
69
# File 'lib/Dieta/plato.rb', line 62

def <=> (other)
	# devolvemos nil si no son del tipo Plato
       	return nil unless other.is_a? Plato
       	# realizamos las comparaciones necesarias
	return @descripcion <=> other.descripcion unless @descripcion == other.descripcion
	return @porcion_recomendada <=> other.porcion_recomendada unless @porcion_recomendada == other.porcion_recomendada
       return @cantidad_ingesta <=> other.cantidad_ingesta
end

#cantidad(valor) ⇒ Object

Asigna la cantidad de ingesta

Parameters:

  • valor (String)

    cantidad de ingesta

Raises:

  • (ArgumentError)


47
48
49
50
# File 'lib/Dieta/plato.rb', line 47

def cantidad(valor)
	raise ArgumentError.new("Cantidad Ingesta no es un String") if !valor.instance_of?(String)
	@cantidad_ingesta = valor
end

#description(valor) ⇒ Object

Asigna la descripcion

Parameters:

  • valor (String)

    Descripcion

Raises:

  • (ArgumentError)


33
34
35
36
# File 'lib/Dieta/plato.rb', line 33

def description(valor)
	raise ArgumentError.new("Porcion Recomendada no es un String") if !valor.instance_of?(String)
	@descripcion = valor
end

#porcion(cantidad) ⇒ Object

Asigna la porción recomendada

Parameters:

  • cantidad (String)

    Porción recomendada

Raises:

  • (ArgumentError)


40
41
42
43
# File 'lib/Dieta/plato.rb', line 40

def porcion(cantidad)
	raise ArgumentError.new("Porcion Recomendada no es un String") if !cantidad.instance_of?(String)
	@porcion_recomendada = cantidad
end

#to_sObject

Devuelve una cadena de texto que representa al plato



53
54
55
56
57
58
59
# File 'lib/Dieta/plato.rb', line 53

def to_s
	s = "#{@descripcion}, "
	if @porcion_recomendada != ""
		s << "#{@porcion_recomendada}, "
	end
	s << "#{@cantidad_ingesta}\n"
end