Skip to content

Allow to compare hash to string #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/json-compare/comparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def compare_elements(old, new)
if old.kind_of? Hash
if new.kind_of? Array
diff_hash = compare_hash_array(old, new)
elsif new.kind_of? String
diff_hash = compare_hash_string(old, new)
else
diff_hash = compare_hashes(old, new)
end
Expand Down Expand Up @@ -76,6 +78,17 @@ def compare_arrays(old_array, new_array)
filter_results(result)
end

def compare_hash_string(old_hash, new_string)
result = get_diffs_struct
if (new_string.include? ",")
return compare_hash_array(old_hash,new_string.split(","))
else
result[:update][0] = new_string
result[:remove][0] = old_hash
end
filter_results(result)
end

def compare_hash_array(old_hash, new_array)
result = get_diffs_struct

Expand Down