Class: Ucode::CodeChart::Verifier::Strategy
- Inherits:
-
Object
- Object
- Ucode::CodeChart::Verifier::Strategy
- Defined in:
- lib/ucode/code_chart/verifier/strategy.rb
Overview
Abstract base for one verification-renderer strategy. Each subclass owns ONE external CLI tool (resvg, mutool, etc.) and implements the three primitives the Ucode::CodeChart::Verifier needs.
Subclasses must implement:
* {#available?} — is the underlying tool installed?
* {#render_svg} — render an SVG to a PNG at the given scale.
* {#render_pdf_region} — render a rectangular region of one
PDF page to a PNG at the given scale.
* {#diff} — pixel-diff percentage between two PNGs.
Adding a new renderer = one subclass + one entry in Builder. No edit to Ucode::CodeChart::Verifier.
Direct Known Subclasses
Constant Summary collapse
- FAIL_THRESHOLD =
Diff percentage at or above which a glyph is considered visually different from the source. Tuned to absorb anti-aliasing differences across renderers; callers can override via the Ucode::CodeChart::Verifier constructor.
1.0
Instance Method Summary collapse
-
#available? ⇒ Boolean
True iff the underlying tool is on PATH.
-
#diff(_png_a, _png_b) ⇒ Float
Percentage of differing pixels (0.0–100.0).
- #render_pdf_region(_pdf_path, _page, _rect, _png_path, scale: 2.0) ⇒ Pathname
-
#render_svg(_svg_path, _png_path, scale: 2.0) ⇒ Pathname
The written PNG path.
-
#write_diff_artifact(_png_a, _png_b, _dest) ⇒ Pathname?
Optional: produce a visual diff artifact (e.g. side-by-side or red/blue overlay).
Instance Method Details
#available? ⇒ Boolean
Returns true iff the underlying tool is on PATH.
29 30 31 |
# File 'lib/ucode/code_chart/verifier/strategy.rb', line 29 def available? raise NotImplementedError end |
#diff(_png_a, _png_b) ⇒ Float
Returns percentage of differing pixels (0.0–100.0).
55 56 57 |
# File 'lib/ucode/code_chart/verifier/strategy.rb', line 55 def diff(_png_a, _png_b) raise NotImplementedError end |
#render_pdf_region(_pdf_path, _page, _rect, _png_path, scale: 2.0) ⇒ Pathname
48 49 50 |
# File 'lib/ucode/code_chart/verifier/strategy.rb', line 48 def render_pdf_region(_pdf_path, _page, _rect, _png_path, scale: 2.0) raise NotImplementedError end |
#render_svg(_svg_path, _png_path, scale: 2.0) ⇒ Pathname
Returns the written PNG path.
37 38 39 |
# File 'lib/ucode/code_chart/verifier/strategy.rb', line 37 def render_svg(_svg_path, _png_path, scale: 2.0) raise NotImplementedError end |
#write_diff_artifact(_png_a, _png_b, _dest) ⇒ Pathname?
Optional: produce a visual diff artifact (e.g. side-by-side or red/blue overlay). When unsupported, returns nil and the Ucode::CodeChart::Verifier skips writing the artifact.
67 68 69 |
# File 'lib/ucode/code_chart/verifier/strategy.rb', line 67 def write_diff_artifact(_png_a, _png_b, _dest) nil end |