Class: NewDiet

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/practica6/practica10.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/practica6/practica10.rb', line 3

def name
  @name
end

#platosObject (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

#vctObject (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(options = {})
	platos_tmp=""
	platos_tmp << "- #{options[:descripcion]}, #{options[:porcion]}, #{options[:gramos]} gramos\n" if options[:descripcion] && options[:porcion] && options[:gramos]
	@platos << platos_tmp
end

#to_sObject



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