Home > Uncategorized > ruby-marc with pluggable readers

ruby-marc with pluggable readers

March 2, 2010 3 Comments »

I’ve been messing with easier ways of adding parsers to ruby-marc’s MARC::Reader object. The idea is that you can do this:

  1.   require 'marc'
  2.   require 'my_marc_stuff'
  3.  
  4.   mbreader = MARC::Reader.new('test.mrc') # => Stock marc binary reader
  5.   mbreader = MARC::Reader.new('test.mrc' :readertype=>:marcstrict) # => ditto
  6.  
  7.   MARC::Reader.register_parser(My::MARC::Parser, :marcstrict)
  8.   mbreader = MARC::Reader.new('test.mrc') # => Uses My::MARC::Parser now
  9.  
  10.   xmlreader = MARC::Reader.new('test.xml', :readertype=>:marcxml)
  11.  
  12.   # …and maybe further on down the road
  13.  
  14.   asreader = MARC::Reader.new('test.seq', :readertype=>:alephsequential)
  15.   mjreader = MARC::Reader.new('test.json', :readertype=>:marchashjson)

A parser need only implement #each and a module-level method #decode_from_string.

Read all about it on the github page.

Tags:

Comments:3

Leave my own
  1. adam
    March 2, 2010 at 5:07 pm

    Bill, How is the performance as compared to other languages?

    • adam
  2. Bill
    March 2, 2010 at 5:23 pm

    Adam — not sure what you’re asking. Ruby vs. Perl? MARC-HASH-JSON vs. MARC-HASH-YAML?

  3. adam
    March 2, 2010 at 6:19 pm

    I was thinking ruby vs. perl vs. java

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>