Sha256: b9bcb3bcebd4bbabf58796b8f4df31e6762e93fe6745eb7d9c19e5e0f933195d

Contents?: true

Size: 732 Bytes

Versions: 1

Compression:

Stored size: 732 Bytes

Contents

module Similatron
  class DiffComparisonEngine < ComparisonEngine

    def can_handle_mime?(mime_type)
      mime_type !~ /charset=binary/
    end

    private

    def command(expected, actual, _diff_path)
      "#{executable_path} #{expected} #{actual}"
    end

    def default_executable_path
      "diff"
    end

    def diff_extension
      "diff"
    end

    def diff(exec_result)
      if exec_result.status != 0
        File.write(diff_path, exec_result.out)
        diff_path
      else # rubocop:disable Style/EmptyElse
        nil
      end
    end

    def score(exec_result)
      return 0 if exec_result.status.zero?

      lines = exec_result.out.split("\n")
      lines.grep(/^>|</).size / 2.0
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
similatron-0.2.0 lib/similatron/diff_comparison_engine.rb