Class: Plato
Overview
Plato de comida
Instance Attribute Summary collapse
-
#cantidad_ingesta ⇒ String
readonly
Cantidad a ingerir.
-
#descripcion ⇒ String
readonly
Descripción del plato.
-
#porcion_recomendada ⇒ String
readonly
Porción recomendada.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Función de comparación para Mixin Comparable.
-
#cantidad(valor) ⇒ Object
Asigna la cantidad de ingesta.
-
#description(valor) ⇒ Object
Asigna la descripcion.
-
#initialize(&block) ⇒ Plato
constructor
A new instance of Plato.
-
#porcion(cantidad) ⇒ Object
Asigna la porción recomendada.
-
#to_s ⇒ Object
Devuelve una cadena de texto que representa al plato.
Constructor Details
#initialize(&block) ⇒ Plato
Returns a new instance of Plato.
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_ingesta ⇒ String (readonly)
Cantidad a ingerir
11 12 13 |
# File 'lib/Dieta/plato.rb', line 11 def cantidad_ingesta @cantidad_ingesta end |
#descripcion ⇒ String (readonly)
Descripción del plato
11 12 13 |
# File 'lib/Dieta/plato.rb', line 11 def descripcion @descripcion end |
#porcion_recomendada ⇒ String (readonly)
Porción 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
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
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
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_s ⇒ Object
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 |