class AnalDiffist::DiffSet

Public Class Methods

new(before, after) click to toggle source
# File lib/analdiffist/diff_set.rb, line 3
def initialize before, after
  @before = before
  @after = after
end

Public Instance Methods

added_problems() click to toggle source
# File lib/analdiffist/diff_set.rb, line 8
def added_problems
  differences.select {|difference| difference.score > 0 }
end
removed_problems() click to toggle source
# File lib/analdiffist/diff_set.rb, line 12
def removed_problems
  differences.select {|difference| difference.score < 0 }
end

Private Instance Methods

calculate_differences() click to toggle source
# File lib/analdiffist/diff_set.rb, line 21
def calculate_differences
  diffs = []
  before_by_context = @before.group_by {|b| [b.type, b.context]}
  after_by_context = @after.group_by {|b| [b.type, b.context]}
  all_contexts = (before_by_context.keys + after_by_context.keys).uniq

  all_contexts.each do |context|

    before = before_by_context[context] || []
    after = after_by_context[context] || []

    diffs.concat(calculate_diffs_for_a_context(before, after))
  end
  diffs.reject(&:nil?)
end
calculate_diffs_for_a_context(before, after) click to toggle source
# File lib/analdiffist/diff_set.rb, line 37
def calculate_diffs_for_a_context before, after
  diffs = []
  while before.any? || after.any? do
    diff = get_diff(before.pop, after.pop)
    diffs << diff unless diff.nil?
  end
  diffs
end
differences() click to toggle source
# File lib/analdiffist/diff_set.rb, line 17
def differences
  @differences ||= calculate_differences
end
get_diff(before, after) click to toggle source
# File lib/analdiffist/diff_set.rb, line 46
def get_diff before, after
  return after.diff(before) unless after.nil?
  diff = before.diff(after)
  return nil if diff.nil?
  InvertedDiff.new(diff)
end