Class: NewDiet
- Inherits:
-
Object
- Object
- NewDiet
- Includes:
- Comparable
- Defined in:
- lib/practica6/practica10.rb
Instance Attribute Summary collapse
-
#ingesta(options = {}) ⇒ Object
readonly
Returns the value of attribute ingesta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#platos ⇒ Object
readonly
Returns the value of attribute platos.
-
#porcentajes(options = {}) ⇒ Object
readonly
Returns the value of attribute porcentajes.
-
#titulo(title) ⇒ Object
readonly
Returns the value of attribute titulo.
-
#vct ⇒ Object
readonly
Returns the value of attribute vct.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(name, &block) ⇒ NewDiet
constructor
A new instance of NewDiet.
- #plato(options = {}) ⇒ Object
-
#to_s ⇒ Object
@vct=options if options.
Constructor Details
#initialize(name, &block) ⇒ NewDiet
Returns a new instance of NewDiet.
4 5 6 7 8 9 10 |
# File 'lib/practica6/practica10.rb', line 4 def initialize(name,&block) @name=name @ingesta = "" @platos = [] @porcentajes = [] instance_eval(&block) end |
Instance Attribute Details
#ingesta(options = {}) ⇒ Object (readonly)
Returns the value of attribute ingesta.
3 4 5 |
# File 'lib/practica6/practica10.rb', line 3 def ingesta @ingesta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/practica6/practica10.rb', line 3 def name @name end |
#platos ⇒ Object (readonly)
Returns the value of attribute platos.
3 4 5 |
# File 'lib/practica6/practica10.rb', line 3 def platos @platos end |
#porcentajes(options = {}) ⇒ Object (readonly)
Returns the value of attribute porcentajes.
3 4 5 |
# File 'lib/practica6/practica10.rb', line 3 def porcentajes @porcentajes end |
#titulo(title) ⇒ Object (readonly)
Returns the value of attribute titulo.
3 4 5 |
# File 'lib/practica6/practica10.rb', line 3 def titulo @titulo end |
#vct ⇒ Object (readonly)
Returns the value of attribute vct.
3 4 5 |
# File 'lib/practica6/practica10.rb', line 3 def vct @vct end |
Instance Method Details
#<=>(other) ⇒ Object
12 13 14 |
# File 'lib/practica6/practica10.rb', line 12 def <=>(other) @porcentajes[0]<=>other.porcentajes[0] end |
#==(other) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/practica6/practica10.rb', line 15 def ==(other) @ingesta==other.ingesta @platos==other.platos @porcentajes==other.porcentajes @vct==other.vct end |
#plato(options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/practica6/practica10.rb', line 31 def plato( = {}) platos_tmp="" platos_tmp << "- #{[:descripcion]}, #{[:porcion]}, #{[:gramos]} gramos\n" if [:descripcion] && [:porcion] && [:gramos] @platos << platos_tmp end |
#to_s ⇒ Object
@vct=options if options
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/practica6/practica10.rb', line 45 def to_s s="#{@titulo} #{@ingesta}%\n" $i=0 for i in 0..platos.length s+="#{@platos[i]}" $i=$i+1 end s+="VCT #{@porcentajes[0]} | #{porcentajes[1]}" s end |