Class: ZplRenderer::Decoder
- Inherits:
-
Object
- Object
- ZplRenderer::Decoder
- Defined in:
- lib/zpl_renderer/decoder.rb
Overview
Independent barcode/QR decoder used by tests and optional QA hooks.
Defined Under Namespace
Classes: Hit
Instance Method Summary collapse
- #decode_png(png_bytes) ⇒ Object
-
#initialize(binary_path: nil) ⇒ Decoder
constructor
A new instance of Decoder.
Constructor Details
#initialize(binary_path: nil) ⇒ Decoder
Returns a new instance of Decoder.
11 12 13 |
# File 'lib/zpl_renderer/decoder.rb', line 11 def initialize(binary_path: nil) @binary_path = binary_path end |
Instance Method Details
#decode_png(png_bytes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/zpl_renderer/decoder.rb', line 15 def decode_png(png_bytes) stdout, stderr, status = Open3.capture3( binary_path, "--decode", stdin_data: png_bytes, binmode: true ) unless status.success? = stderr.to_s.strip = "decode failed with status #{status.exitstatus}" if .empty? raise RenderError, end JSON.parse(stdout).map do |row| Hit.new(symbology: row.fetch("format"), text: row.fetch("text")) end rescue Errno::ENOENT raise BinaryMissingError, Binary. end |