Home > OS >  Barby gem not generating qr_code
Barby gem not generating qr_code

Time:05-31

Using the barby gem documentation, the following is not generating a qr code,

require 'barby'
require 'rqrcode'
require 'barby/barcode/qr_code'
require 'barby/outputter/png_outputter'
qr_string = "8076809574693\r\n8076809574693\r\n8076809574693\r\n4017100364013\r\n4017100364013\r\n3017760002707\r\n8076809517706\r\n8013355999488\r\n"
qr_output = Barby::PngOutputter.new(qr_string).to_png
File.open('qrcode.png', 'wb'){|f| f.write qr_output }

as it complains on the penultimate line for qr_output with NoMethodError (undefined method two_dimensional?' for #String:0x00007f903526c4c0)`
Installed gems

gem 'rqrcode', '~> 2.0'
gem 'barby', '~> 0.6.8'

Note: the raw data has all 13 characters of what are EAN-13 codes, when barby, for processing EAN-13 symbology only accepts 12 characters as input and generates the 13th character (control) itself.

What is mistaken in this approach?

CodePudding user response:

You can't pass a string directrly to PngOutputter. It must be processed by barby's qr code module first.

require 'barby'
require 'rqrcode'
require 'barby/barcode/qr_code'
require 'barby/outputter/png_outputter'
qr_string = "8076809574693\r\n8076809574693\r\n8076809574693\r\n4017100364013\r\n4017100364013\r\n3017760002707\r\n8076809517706\r\n8013355999488\r\n"
qr_data = Barby::QrCode.new(qr_string)
qr_output = Barby::PngOutputter.new(qr_data).to_png
File.open('qrcode.png', 'wb'){|f| f.write qr_output }
  • Related