Class: Fable::Pointer

Inherits:
Object
  • Object
show all
Defined in:
lib/fable/pointer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, index) ⇒ Pointer

Returns a new instance of Pointer.



13
14
15
16
# File 'lib/fable/pointer.rb', line 13

def initialize(container, index)
  self.container = container
  self.index = index
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



3
4
5
# File 'lib/fable/pointer.rb', line 3

def container
  @container
end

#indexObject

Returns the value of attribute index.



3
4
5
# File 'lib/fable/pointer.rb', line 3

def index
  @index
end

Class Method Details

.null_pointerObject



9
10
11
# File 'lib/fable/pointer.rb', line 9

def self.null_pointer
  self.new(nil, -1)
end

.start_of(container) ⇒ Object



5
6
7
# File 'lib/fable/pointer.rb', line 5

def self.start_of(container)
  self.new(container, 0)
end

Instance Method Details

#cloneObject



25
26
27
# File 'lib/fable/pointer.rb', line 25

def clone
  self.class.new(self.container, self.index)
end

#null_pointer?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fable/pointer.rb', line 29

def null_pointer?
  container.nil?
end

#pathObject



33
34
35
36
37
38
39
40
# File 'lib/fable/pointer.rb', line 33

def path
  return nil if null_pointer?
  if index > 0
    return container.path.path_by_appending_component(index)
  else
    return container.path
  end
end

#resolve!Object



18
19
20
21
22
23
# File 'lib/fable/pointer.rb', line 18

def resolve!
  return container if index < 0
  return nil if container.nil?
  return container if container.content.empty?
  return container.content[index]
end