Class: Item::AmazonFnskuBarcode
- Inherits:
-
BaseService
- Object
- BaseService
- Item::AmazonFnskuBarcode
- Defined in:
- app/services/item/amazon_fnsku_barcode.rb
Overview
This will generate a FNSKU Barcode
30336 compatible Dymo labels (2.125" x 1") - This is paper size 'w72h154' in PrintNode
To make this work you will need a Dymo labelwriter 400 series with the right label and the PrintNode server running
- Go to localhost:631, manage printers, select the dymo
- Select "Set Default options"
- Select Media Size 30336, Continuous paper: false, output resolution 300x600, print quality barcode and graphics, media source auto
- In print node options, next to the printer, page width set to 1.0, page height set to 2.13
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(fnsku, file_path: nil, output_format: nil, xdim: 2, height: 50) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/item/amazon_fnsku_barcode.rb', line 15 def process(fnsku, file_path: nil, output_format: nil, xdim: 2, height: 50) require 'barby' require 'barby/barcode/code_128' require 'barby/outputter/png_outputter' output_format ||= :png return Result.new(success: false, message: "Unsupported format: #{output_format}, only png supported at this time") unless output_format == :png return Result.new(success: false, message: "Invalid FNSKU #{AmazonFnskuValidator::MESSAGE}") unless AmazonFnskuValidator.valid?(fnsku) = Barby::Code128B.new(fnsku) outputter = Barby::PngOutputter.new() outputter.height = height # Set the height of the barcode (in pixels) outputter.xdim = xdim # Set the width of each bar = outputter.to_png return Result.new(success: true, output: , fnsku:, output_format:, identifier_type: 'FNSKU', identifier_formatted: fnsku) unless file_path File.open(file_path, 'wb') do |f| f.write f.flush f.fsync end Result.new(success: true, output: file_path, fnsku:, output_format:) end |