mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-24 15:51:31 +00:00
27 lines
No EOL
700 B
Ruby
27 lines
No EOL
700 B
Ruby
require 'jsonpath'
|
|
|
|
module Utils
|
|
# Unindents if the indentation is 2 or more characters.
|
|
def self.unindent(s)
|
|
s.gsub(/^#{s.scan(/^\s+/).select {|i| i.length > 1 }.min_by{|l|l.length}}/, "")
|
|
end
|
|
|
|
def self.recursively_symbolize_keys(object)
|
|
case object
|
|
when Hash
|
|
object.inject({}) {|memo, (k, v)| memo[String === k ? k.to_sym : k] = recursively_symbolize_keys(v); memo }
|
|
when Array
|
|
object.map { |item| recursively_symbolize_keys item }
|
|
else
|
|
object
|
|
end
|
|
end
|
|
|
|
def self.value_at(data, path)
|
|
values_at(data, path).first
|
|
end
|
|
|
|
def self.values_at(data, path)
|
|
JsonPath.new(path).on(data.is_a?(String) ? data : data.to_json)
|
|
end
|
|
end |