Class: Teton::KeyPointer

Inherits:
Object
  • Object
show all
Defined in:
lib/teton/key_pointer.rb

Overview

Points to a section within a key’s parts. A section can either be a resource or an entry.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, index) ⇒ KeyPointer

Returns a new instance of KeyPointer.



8
9
10
11
12
13
# File 'lib/teton/key_pointer.rb', line 8

def initialize(key, index)
  @key   = key
  @index = index.to_i

  freeze
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/teton/key_pointer.rb', line 6

def index
  @index
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/teton/key_pointer.rb', line 6

def key
  @key
end

Instance Method Details

#entry?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/teton/key_pointer.rb', line 27

def entry?
  index.odd?
end

#last?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/teton/key_pointer.rb', line 23

def last?
  index == key.parts.length - 1
end

#not_last?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/teton/key_pointer.rb', line 19

def not_last?
  !last?
end

#resource?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/teton/key_pointer.rb', line 31

def resource?
  index.even? || index.zero?
end

#valueObject



15
16
17
# File 'lib/teton/key_pointer.rb', line 15

def value
  key.parts[index]
end