Skip to content

Ruby DSL for parsing and building fixed width fields

License

Notifications You must be signed in to change notification settings

signaturelabs/pixxxer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pixxxer

Installation

Installation is super easy. Gems work like that.

gem install pixxxer

Usage

Pixxxer provide a simple DSL for defining fixed with data and then extensions to String and Hash to build and parse those records. It can handle floats, integers, and strings.

Assuming a record like this:

Title     Author    Qty  Price
-----     ------    ---  -----
Dune      Herbert   0012001295
012345678901234567890123456789
          1         2         

You can define the follwing template:

define_pixxx_template(:book)
	.add_field(:title).as_string.at_position(0).with_width(10).and
	.add_field(:author).as_string.at_position(10).with_width(10).and
	.add_field(:quantity).as_integer.at_position(20).with_width(5).and
	.add_field(:price).as_float.at_position(25).with_width(5).with_precision(2)

To use the template to parse:

record = 'Dune      Herbert   0012001295'.depixxxit(:book)
record[:title].should == 'Dune      '
record[:author].should == 'Herbert    '
record[:quantity].should == 120
record[:price].should == 12.95

To use the template to build a record:

s = record.pixxxit(:book)
s.should == 'Dune      Herbert   0012001295'

Notes: Most things default to zero. Fields default to strings. at_position is zero-based

Copyright

Copyright(c) 2011 Guy Royse & Alyssa Diaz. See LICENSE for further details.

About

Ruby DSL for parsing and building fixed width fields

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%