Class: Hana::Pointer
Constant Summary collapse
- ESC =
:nodoc:
{'^/' => '/', '^^' => '^', '~0' => '~', '~1' => '/'}
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #eval(object) ⇒ Object
-
#initialize(path) ⇒ Pointer
constructor
A new instance of Pointer.
Constructor Details
Class Method Details
.eval(list, object) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hana.rb', line 19 def self.eval list, object list.inject(object) { |o, part| return nil unless o if Array === o raise Patch::IndexError unless part =~ /\A\d+\Z/ part = part.to_i end o[part] } end |
.parse(path) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/hana.rb', line 31 def self.parse path return [''] if path == '/' path.sub(/^\//, '').split(/(?<!\^)\//).each { |part| part.gsub!(/\^[\/^]|~[01]/) { |m| ESC[m] } } end |