Sha256: 7e773424fdffb176646d65fe57a518a96dd4b6753f4d7f53929df7757df724f0
Contents?: true
Size: 780 Bytes
Versions: 2
Compression:
Stored size: 780 Bytes
Contents
require 'subtle' module Contrast class Detective def initialize(*args) @fields = args end def examine(a, b) Hash[fields_that_do_not_match(a, b).map do |key| [key, { :actual_value => get_the_value(a, key), :expected_value => get_the_value(b, key) }] end] end private def fields_that_do_not_match(a, b) @fields.select do |field| first = get_the_value(a, field) second = get_the_value(b, field) the_values_the_do_not_match(first, second) end end def get_the_value(object, field) begin object[field] rescue object.send(field) end end def the_values_the_do_not_match(a, b) a != b && a.to_s != b.to_s end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
contrast-1.1.0 | lib/contrast/detective.rb |
contrast-1.0.0 | lib/contrast/detective.rb |