Class: Teton::KeyPointer
- Inherits:
-
Object
- Object
- Teton::KeyPointer
- 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
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #entry? ⇒ Boolean
-
#initialize(key, index) ⇒ KeyPointer
constructor
A new instance of KeyPointer.
- #last? ⇒ Boolean
- #not_last? ⇒ Boolean
- #resource? ⇒ Boolean
- #value ⇒ Object
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
6 7 8 |
# File 'lib/teton/key_pointer.rb', line 6 def index @index end |
#key ⇒ Object (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
27 28 29 |
# File 'lib/teton/key_pointer.rb', line 27 def entry? index.odd? end |
#last? ⇒ Boolean
23 24 25 |
# File 'lib/teton/key_pointer.rb', line 23 def last? index == key.parts.length - 1 end |
#not_last? ⇒ Boolean
19 20 21 |
# File 'lib/teton/key_pointer.rb', line 19 def not_last? !last? end |
#resource? ⇒ Boolean
31 32 33 |
# File 'lib/teton/key_pointer.rb', line 31 def resource? index.even? || index.zero? end |
#value ⇒ Object
15 16 17 |
# File 'lib/teton/key_pointer.rb', line 15 def value key.parts[index] end |