Home > 2-deed > Ruby helper classes for barcodes

Ruby helper classes for barcodes

December 23rd, 2009 Petros Leave a comment Go to comments

In my day job, I work a lot with barcodes. We develop Windows Mobile software for devices with barcode readers. From time to time, I need to do file manipulation chores. That is: colleagues give me text files that contain barcodes and ask me to transform these.

Yesterday, a colleague of mine asked me to take as input a file with 12 characters long barcodes and add a check digit assuming the barcodes are EAN13. I decided to do it and also start maintaining a set of barcode helper classes written in Ruby. I haven’t created a gem yet, cause the functionality is … lets say limited :-) , but I plan to do so later.

You can go to

http://github.com/amiridis/rbarcode

and just download the barcode.rb file.

Here is how I used the barcode.rb file in order to transform the file:

require "barcode"

file = File.open("apog.txt")

file.each do |line|
  bc = line.slice(0..11)
  bc13 = Barcode.new(bc).get_ean_13
  puts bc13 + line.slice(12..line.length)
end

file.close

The file had the following format:

520532435284;1;09
520532435285;1;09
520532463580;1;09

and for the three lines above it produces:

5205324352841;1;09
5205324352858;1;09
5205324635807;1;09

Update: I have changed this project to a gem. You can read about it in my PAbarcode gem post.

Categories: 2-deed Tags: , ,
  1. December 24th, 2009 at 00:35 | #1

    Thank you very much!

    Your assistance it was very helpful.

    It’ll be very helpful if your project can do the following specified steps:
    1. the name of the input text file
    2. the type of file i.e. a csv file, a delimited field or an Excel file
    3. the field that we want to check and change (of course the barcode field)
    4. the name of the output file
    5. the format of the output file i.e. a csv file, a delimited field or an Excel file

    Thank you again Petro

  2. December 24th, 2009 at 01:40 | #2

    You are welcome. The utility that I mention in the post is written in Ruby. Are you sure you would like what you describe written in Ruby?

  3. December 28th, 2009 at 23:47 | #3

    @Petros
    Why not my friend?

    I’m curious to see the solving method not the actual programming code.
    Then, i believe, it’s easy to implement it in another programming language.

    Best regards
    Happy Holidays!

  1. No trackbacks yet.