Class: Item::DataMatrixBarcode

Inherits:
BaseService show all
Defined in:
app/services/item/data_matrix_barcode.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#process(data, file_path: nil, xdim: 2) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/item/data_matrix_barcode.rb', line 8

def process(data, file_path: nil, xdim: 2)
  require 'barby'
  require 'barby/barcode/data_matrix'
  require 'barby/outputter/png_outputter'

  barcode = Barby::DataMatrix.new(data)
  barcode_output = barcode.to_png(xdim:)

  return Result.new(output: barcode_output) unless file_path

  File.open(file_path, 'wb') do |f|
    f.write barcode_output
    f.flush
    f.fsync
  end
  Result.new(output: file_path)
end