diff options
author | icebaker <icebaker@proton.me> | 2023-05-11 19:24:50 -0300 |
---|---|---|
committer | icebaker <icebaker@proton.me> | 2023-05-11 19:24:50 -0300 |
commit | ec5e25547a401141586c87621266f9cd68c59e3c (patch) | |
tree | 547b3c7fa04c9e695785b9beeda0be5a4a77b006 /logic |
first commit
Diffstat (limited to 'logic')
-rw-r--r-- | logic/helpers/hash.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/logic/helpers/hash.rb b/logic/helpers/hash.rb new file mode 100644 index 0000000..52bd8d4 --- /dev/null +++ b/logic/helpers/hash.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module NanoBot + module Logic + module Helpers + module Hash + def self.symbolize_keys(object) + case object + when ::Hash + object.each_with_object({}) do |(key, value), result| + result[key.to_sym] = symbolize_keys(value) + end + when Array + object.map { |e| symbolize_keys(e) } + else + object + end + end + + def self.fetch(object, path) + node = object + + return nil unless node + + path.each do |key| + node = node[key] + break if node.nil? + end + + node + end + end + end + end +end |