module Dotpath
Constants
- DELIMITER
- VERSION
Public Class Methods
encode(key)
click to toggle source
# File lib/dotpath.rb, line 12 def self.encode(key) key = key.to_s key.include?(DELIMITER) ? "\"#{key}\"" : key end
value_at_path(object, json_path)
click to toggle source
Retrieve a value at a given JSON path for an Array or Hash.
@param object [Hash, Array] The object that can be navigated using JSON path. @param json_path [String] The JSON path for the requested value.
@return the value at JSON path.
# File lib/dotpath.rb, line 23 def self.value_at_path(object, json_path) raise ArgumentError, "#{object.class} does not support JSON path" unless object.respond_to?(:each_with_json_path) val = nil object.each_with_json_path do |path, value| if json_path == path val = value break end end val end