Class: Hypostasis::KeyPath
- Inherits:
-
Object
- Object
- Hypostasis::KeyPath
- Defined in:
- lib/hypostasis/key_path.rb
Instance Method Summary collapse
- #extend_path(*extension) ⇒ Object
-
#initialize(*path) ⇒ KeyPath
constructor
A new instance of KeyPath.
- #move_up(count = 0) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*path) ⇒ KeyPath
Returns a new instance of KeyPath.
2 3 4 5 6 |
# File 'lib/hypostasis/key_path.rb', line 2 def initialize(*path) @path = path.to_a.flatten raise Hypostasis::Errors::InvalidKeyPath if @path.empty? self end |
Instance Method Details
#extend_path(*extension) ⇒ Object
16 17 18 19 20 |
# File 'lib/hypostasis/key_path.rb', line 16 def extend_path(*extension) return self if extension.empty? extended_path = @path + extension.to_a Hypostasis::KeyPath.new(extended_path) end |
#move_up(count = 0) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/hypostasis/key_path.rb', line 22 def move_up(count = 0) return self if count <= 0 raise Hypostasis::Errors::KeyPathExhausted if count >= @path.size new_path = @path new_path.pop(count) Hypostasis::KeyPath.new(new_path) end |
#to_a ⇒ Object
12 13 14 |
# File 'lib/hypostasis/key_path.rb', line 12 def to_a @path end |
#to_s ⇒ Object
8 9 10 |
# File 'lib/hypostasis/key_path.rb', line 8 def to_s @path.join('\\') end |