Class: Hocon::Impl::ResolveSource::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/hocon/impl/resolve_source.rb

Overview

a persistent list

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, next_node = nil) ⇒ Node

Returns a new instance of Node.



199
200
201
202
# File 'lib/hocon/impl/resolve_source.rb', line 199

def initialize(value, next_node = nil)
  @value = value
  @next_node = next_node
end

Instance Attribute Details

#next_nodeObject (readonly)

Returns the value of attribute next_node.



197
198
199
# File 'lib/hocon/impl/resolve_source.rb', line 197

def next_node
  @next_node
end

#valueObject (readonly)

Returns the value of attribute value.



197
198
199
# File 'lib/hocon/impl/resolve_source.rb', line 197

def value
  @value
end

Instance Method Details

#headObject



208
209
210
# File 'lib/hocon/impl/resolve_source.rb', line 208

def head
  @value
end

#lastObject



216
217
218
219
220
221
222
# File 'lib/hocon/impl/resolve_source.rb', line 216

def last
  i = self
  while i.next_node != nil
    i = i.next_node
  end
  i.value
end

#prepend(value) ⇒ Object



204
205
206
# File 'lib/hocon/impl/resolve_source.rb', line 204

def prepend(value)
  Node.new(value, self)
end

#reverseObject



224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/hocon/impl/resolve_source.rb', line 224

def reverse
  if @next_node == nil
    self
  else
    reversed = Node.new(@value)
    i = @next_node
    while i != nil
      reversed = reversed.prepend(i.value)
      i = i.next_node
    end
    reversed
  end
end

#tailObject



212
213
214
# File 'lib/hocon/impl/resolve_source.rb', line 212

def tail
  @next_node
end

#to_sObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/hocon/impl/resolve_source.rb', line 238

def to_s
  sb = ""
  sb << "["
  to_append_value = self.reverse
  while to_append_value != nil
    sb << to_append_value.value.to_s
    if to_append_value.next_node != nil
      sb << " <= "
    end
    to_append_value = to_append_value.next_node
  end
  sb << "]"
  sb
end