While attempting to render in HTML a collection of article barcodes and proceeding incrementally to view the data (relative to other objects on tha page), the controller
require 'barby/outputter/html_outputter'
require 'barby/barcode/ean_13'
and the view invokes
<%= this_barcode = article.barcodes.first.barcode %>
<%= this_barcode.class %>
<%# barcode = Barby::EAN13.new(this_barcode) %>
<%# outputter = Barby::HtmlOutputter.new(barcode) %>
<%# barcode.to_html.html_safe %>
[returns as expected]
8001300303466 String
however, when wanting to get the barcode and uncommenting that element it fails to process because data not valid
for the line barcode = Barby::EAN13.new(this_barcode)
(also occurs with barcode = Barby::EAN13.new(this_barcode.to_i)
)
note possibly on garden path here, as there is confusion with what the wiki suggests with
barcode = Barby::DataMatrix.new(number)
as that would generate the error
uninitialized constant Barby::DataMatrix
How does one ensure the data is correct for proper rendering?
CodePudding user response:
Here's the issue:
8001300303466
has 13 characters. It is the correct barcode.
I was assuming one could submit a correct barcode. However line 54 of the gem's ean_13.rb file
allows a 12 character data element FORMAT = /^\d{12}$/
and proceeds to calculate the check digit.
Thus,
<%= barcode = Barby::EAN13.new(this_barcode[0...-1]) %>
will end up processing the data correctly.