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 Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/item/amazon_fnsku_barcode.rb', line 16 def process(fnsku, file_path: nil, output_format: nil, xdim: 2, height: 50) require 'zint' 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) = Zint::Barcode.new(value: fnsku, symbology: Zint::Constants::Symbologies::BARCODE_CODE128) .scale = xdim # width of each bar, in pixels .height = (height.to_f / xdim).round # zint counts height in bar-width units .show_hrt = 0 # barby rendered bars only; keep it that way = .to_memory_file(extension: '.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 |