lib/pdf_matcher/matcher.rb in pdf_matcher-1.0.1 vs lib/pdf_matcher/matcher.rb in pdf_matcher-2.0.0

- old
+ new

@@ -12,10 +12,21 @@ @output_diff_path = output_diff ? Pathname(output_diff) : nil @diff_pdf_opts = diff_pdf_opts || PdfMatcher.config.diff_pdf_opts end def match - @result ||= MatchResult.new(match_pdfs, pdf1, pdf2, output_diff_path) + @result ||= begin + matched = match_pdfs + + if matched + # [NOTE] The diff-pdf command will generate a diff PDF file + # regardless of the result if the `--output_diff` option is given. + output_diff_path.unlink if output_diff_path&.exist? + MatchResult.new(matched, pdf1, pdf2, nil) + else + MatchResult.new(matched, pdf1, pdf2, output_diff_path) + end + end end private attr_reader :pdf1, :pdf2, :output_diff_path, :diff_pdf_opts