Sha256: 486bacfef691a6aeb7b6a36de155c3064181023edcbec07cc43b41544d4c6de7
Contents?: true
Size: 1.06 KB
Versions: 18
Compression:
Stored size: 1.06 KB
Contents
module Ecoportal module API module Common module HashDiff ID_KEYS = %w[id] class << self def diff(a, b) return a if a.class != b.class case a when Hash {}.tap do |diffed| a.each do |key, a_value| b_value = b[key] next if a_value == b_value && !ID_KEYS.include?(key) diffed[key] = diff(a_value, b_value) diffed.delete(key) if diffed[key] == {} end # All keys are IDs, so it's actually blank if (diffed.keys - ID_KEYS).empty? return {} end end when Array return a unless a.length == b.length a.map.with_index do |a_value, idx| b_value = b[idx] diff(a_value, b_value) end.reject do |el| el == {} end else a end end end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems