Class: Linked
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
- #add(value) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #ex_1er_elemento ⇒ Object
- #extract_tail ⇒ Object
-
#initialize ⇒ Linked
constructor
A new instance of Linked.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Linked
Returns a new instance of Linked
9 10 11 12 |
# File 'linked.rb', line 9 def initialize @head = @tail = nil @contador=0 end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head
7 8 9 |
# File 'linked.rb', line 7 def head @head end |
#prev ⇒ Object
Returns the value of attribute prev
7 8 9 |
# File 'linked.rb', line 7 def prev @prev end |
#tail ⇒ Object
Returns the value of attribute tail
7 8 9 |
# File 'linked.rb', line 7 def tail @tail end |
Instance Method Details
#add(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'linked.rb', line 14 def add(value) node = Node.new(value) @head = node if @head.nil? if(@tail!=nil) @tail.next = node node.prev = @tail @contador=@contador+1 end @tail = node #@contador=@contador+1 end |
#each ⇒ Object
117 118 119 120 121 122 123 |
# File 'linked.rb', line 117 def each nodo = head while(nodo != nil) yield nodo.value[1][3] nodo = nodo.next end end |
#empty? ⇒ Boolean
94 95 96 97 98 99 100 101 |
# File 'linked.rb', line 94 def empty? if @head.nil? return true else return false end end |
#ex_1er_elemento ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'linked.rb', line 83 def ex_1er_elemento() if @head.nil? return false end @aux3=head @head = @head.next @aux3.next=nil end |
#extract_tail ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'linked.rb', line 103 def extract_tail() aux="" if(@tail == nil) return false else aux = @tail.value @tail = @tail.prev return aux end end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'linked.rb', line 30 def to_s @aux=head #@tam=@aux.value.length aux2="" while @aux != nil do @nomb=@aux.value[0][0] @porc=@aux.value[0][1] @comida = @aux.value[1][0] @prop_aprox = @aux.value[1][1] @prop_exact = @aux.value[1][2] @kcal = @aux.value[1][3] @por = @aux.value[1][4] if (@aux.value[1][5]==nil) ob_diet=Dieta.new(@nomb,@porc,@comida,@prop_aprox,@prop_exact,@kcal,@por) #ob_raci=Raciones.new(@comida,@prop_aprox,@prop_exact,@kcal,@por) aux2+="\n#{ob_diet.m_nombre()}\n" aux2+="#{ob_diet.comidayprop()}\n" aux2+="#{ob_diet.vct()}\n" @aux=@aux.next else if (@aux.value[1][6]==nil) @tipo = @aux.value[1][5] ob_alimentos=Alimentos.new(@nomb,@porc,@comida,@prop_aprox,@prop_exact,@kcal,@por,@tipo) aux2+="#{ob_alimentos.to_s()}\n" @aux=@aux.next else @desde = @aux.value[1][5] @hasta = @aux.value[1][6] ob_edad=Edad.new(@nomb,@porc,@comida,@prop_aprox,@prop_exact,@kcal,@por,@desde,@hasta) aux2+="#{ob_edad.to_s()}\n" @aux=@aux.next end end end "#{aux2}" end |