Skip to content

Instantly share code, notes, and snippets.

@chumpy
Created January 29, 2012 00:20
Show Gist options
  • Save chumpy/1696390 to your computer and use it in GitHub Desktop.
Save chumpy/1696390 to your computer and use it in GitHub Desktop.
compare two yaml files in ruby
#require 'active_support/core_ext'
class YamlCompare
def self.compare_keys first_file_info, second_file_info, results_location
first_file = Hash.new
second_file = Hash.new
deltas_file = Hash.new
File.open( first_file_info[:file_location] ) { |yf| first_file = YAML.load( yf ) }
File.open( second_file_info[:file_location] ) { |yf| second_file = YAML.load( yf ) }
first_file[first_file_info[:root]].each_pair do |k,v|
test_read = second_file[second_file_info[:root]][k]
puts test_read
if test_read.nil? || test_read.eql?('nil')
deltas_file[k] = v
end
end
File.open( results_location, 'w' ) { |f| f.write( deltas_file.to_yaml )}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment