class Differz::Comparer

Public Class Methods

new(file1, file2) click to toggle source
# File lib/differz/comparer.rb, line 5
def initialize(file1, file2)
  @file1 = file1
  @file2 = file2
end

Public Instance Methods

show_diff() click to toggle source
# File lib/differz/comparer.rb, line 10
def show_diff
  get_diffs.each do |diff|
    puts diff.join(' -> ')
  end
  nil
end

Private Instance Methods

get_diffs() click to toggle source
# File lib/differz/comparer.rb, line 19
def get_diffs
  hash_diff(read_yaml(@file1), read_yaml(@file2))
end
hash?(var) click to toggle source
# File lib/differz/comparer.rb, line 39
def hash?(var)
  var.is_a?(Hash)
end
hash_diff(h1, h2, path = []) click to toggle source
# File lib/differz/comparer.rb, line 27
def hash_diff(h1, h2, path = [])
  diff = []
  h1.each do |k, v|
    if hash?(v)
      diff += hash_diff(v, hash?(h2[k]) ? h2[k] : {}, path + [k])
    elsif !h2.key?(k)
      diff << path + [k]
    end
  end
  diff
end
read_yaml(file_path) click to toggle source
# File lib/differz/comparer.rb, line 23
def read_yaml(file_path)
  YAML.load(File.read(file_path))
end