How to generate EAN13 barcode with any number of digits from 1 to 12

92 views
Skip to first unread message

Evgeniy Martynenko

unread,
May 14, 2019, 12:33:13 PM5/14/19
to Barby
I want to use the 'barby' gem in my application and I need to generate barcode from any number of digits from 1 to 12.
How can I do that?
Thank you!

Regards Evgeniy.

Tore Darell

unread,
May 14, 2019, 1:04:51 PM5/14/19
to ruby-...@googlegroups.com
EAN-13 must have 12 digits, so you'll have to zero-pad your numbers.

--
You received this message because you are subscribed to the Google Groups "Barby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-barby+...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ruby-barby.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-barby/12d91395-7907-484c-8381-3cdd9a5b57ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evgeniy Martynenko

unread,
May 14, 2019, 1:30:21 PM5/14/19
to Barby
I know, but this barcode will have used for own purposes of customer.
I tried to modify ean_13.rb in such way:
---------------------
FORMAT = /^\d{1,12}$/
---------------------
def left_numbers
    numbers.length == 12 ? numbers[1,6] : numbers[0,(numbers.length/2.0).ceil]
end
---------------------
def right_numbers
    numbers.length == 12 ? numbers_with_checksum[7,6] : numbers_with_checksum[numbers.length/2, numbers.length]
end
---------------------
But it seems to work a bit wrong for odd number of digits.
How can I change code else for more or less right generator working?

вторник, 14 мая 2019 г., 20:04:51 UTC+3 пользователь Tore Darell написал:
EAN-13 must have 12 digits, so you'll have to zero-pad your numbers.

On Tue, May 14, 2019 at 6:33 PM Evgeniy Martynenko <mspru...@gmail.com> wrote:
I want to use the 'barby' gem in my application and I need to generate barcode from any number of digits from 1 to 12.
How can I do that?
Thank you!

Regards Evgeniy.

--
You received this message because you are subscribed to the Google Groups "Barby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-...@googlegroups.com.

Tore Darell

unread,
May 14, 2019, 1:32:43 PM5/14/19
to ruby-...@googlegroups.com
You can't, it must be 12 digits or it's not EAN-13. If you explain why you're trying to do this maybe I can suggest a different solution.

To unsubscribe from this group and stop receiving emails from it, send an email to ruby-barby+...@googlegroups.com.

To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ruby-barby.
Reply all
Reply to author
Forward
0 new messages