lib/similatron/run.rb in similatron-0.1.1 vs lib/similatron/run.rb in similatron-0.2.0
- old
+ new
@@ -5,15 +5,11 @@
def start(base_path: "tmp")
run_id = SecureRandom.urlsafe_base64(8)
@run_path = File.join(base_path, "run_#{run_id}")
- @engines = [
- ImagemagickComparisonEngine.new(diffs_path: run_path),
- DiffComparisonEngine.new(diffs_path: run_path),
- BinaryDiffComparisonEngine.new(diffs_path: run_path)
- ]
+ @engines = build_engines
@comparisons = []
FileUtils.mkdir_p(run_path)
end
@@ -75,10 +71,22 @@
actual: actual,
score: 0
)
end
+ def build_engines
+ engine_classes = [
+ PdfComparisonEngine,
+ ImagemagickComparisonEngine,
+ DiffComparisonEngine,
+ BinaryDiffComparisonEngine
+ ]
+ engine_classes.map do |engine_class|
+ engine_class.new(diffs_path: run_path)
+ end
+ end
+
def best_engine(file)
mime_type = `file --mime -b #{file}`.chomp
engines.detect { |engine| engine.can_handle_mime?(mime_type) }
end
@@ -94,11 +102,10 @@
def to_json
comparisons.map(&:as_json).to_json
end
def to_html
- template = ERB.new(File.read("lib/assets/report.html.erb"))
- template.result(binding)
+ HtmlReport.new(self).render
end
def write_reports
File.write(html_report_path, to_html)
File.write(json_report_path, to_json)