Created
January 29, 2012 00:20
-
-
Save chumpy/1696390 to your computer and use it in GitHub Desktop.
compare two yaml files in ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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