Class: ZplRenderer::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/zpl_renderer/validation.rb

Overview

Static ZPL compatibility checks before rendering.

Reports unsupported commands, missing label boundaries, and barcode scanability risks without mutating the source ZPL.

Defined Under Namespace

Classes: Result

Constant Summary collapse

SUPPORTED_COMMANDS =
%w[
  XA XZ FO FT FD FS A CF FB FR FH FN FW FV
  BC BE B2 B3 B7 BO BX BQ BD BY
  GB GC GD GF GS IL XG
  PW PO LH LR CI MU DF XF
  PR PQ JM MD MN MT PM LL
].freeze
UNSUPPORTED_COMMANDS =
%w[
  RF IS ID JB KD KL KM KP
  WC WD WQ WR WS WT WV WW
  SN SF
].freeze
BARCODE_COMMANDS =
%w[BC BE B2 B3 B7 BO BX BQ BD].freeze
KNOWN_COMMANDS =
(
  SUPPORTED_COMMANDS + UNSUPPORTED_COMMANDS +
  %w[DG] # ~DG download graphic
).uniq.sort_by { |c| -c.length }.freeze
MIN_MODULE_WIDTH =

Minimum module width in dots for reliable scanning at each DPI.

{
  203 => 2,
  300 => 3,
  600 => 4
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zpl, options) ⇒ Validation

Returns a new instance of Validation.



46
47
48
49
50
51
# File 'lib/zpl_renderer/validation.rb', line 46

def initialize(zpl, options)
  @zpl = zpl.to_s
  @options = options
  @errors = []
  @warnings = []
end

Class Method Details

.validate!(zpl, options) ⇒ Object



65
66
67
# File 'lib/zpl_renderer/validation.rb', line 65

def self.validate!(zpl, options)
  new(zpl, options).call.raise_if_strict!(strict: options.strict)
end

Instance Method Details

#callObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/zpl_renderer/validation.rb', line 53

def call
  check_not_empty!
  check_label_bounds!
  check_malformed_origins!
  check_commands!
  check_barcode_module_width!
  check_qr_params!
  check_code128_data!

  Result.new(ok?: @errors.empty?, errors: @errors.dup, warnings: @warnings.dup)
end