<commit_before>module Gjman
  module PDF
    class Matcher < Base
      class << self

        def test(pdf_x, pdf_y)
          begin
            tmp_x, tmp_y = uncompress(pdf_x, pdf_y)
            [
              same_fonts?(tmp_x, tmp_y),
              same_images?(tmp_x, tmp_y),
              same_contents?(tmp_x, tmp_y),
            ].all?
          ensure
            FileSystem.trash_tmp_files
          end
        end

        private

          def uncompress(*pdfs)
            [pdfs].flatten.map do |pdf|
              tmp = FileSystem.tmp_file([Digest::MD5.hexdigest(pdf),'.pdf']).path
              PDF.uncompress(pdf, :to => tmp)
            end
          end

      end
    end
  end
end<commit_msg>Lazy evaluation to cut down on processing.<commit_after>module Gjman
  module PDF
    class Matcher < Base
      class << self

        def test(pdf_x, pdf_y)
          begin
            tmp_x, tmp_y = uncompress(pdf_x, pdf_y)
            ! [:same_fonts?, :same_images?, :same_contents?].
              any?{|test| !send(test, tmp_x, tmp_y) }
          ensure
            FileSystem.trash_tmp_files
          end
        end

        private

          def uncompress(*pdfs)
            [pdfs].flatten.map do |pdf|
              tmp = FileSystem.tmp_file([Digest::MD5.hexdigest(pdf),'.pdf']).path
              PDF.uncompress(pdf, :to => tmp)
            end
          end

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09597741707833451, 'fraction_numerical': 0.0014114326040931546, 'mean_word_length': 1.4660869565217391, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4977209', 'n_tokens_mistral': 450, 'n_tokens_neox': 439, 'n_words': 95}