Skip to content

ruby-marc with pluggable readers

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:

   require 'marc'   require 'my_marc_stuff'    mbreader ='test.mrc') # => Stock marc binary reader   mbreader ='test.mrc' :readertype=>:marcstrict) # => ditto    MARC::Reader.register_parser(My::MARC::Parser, :marcstrict)   mbreader ='test.mrc') # => Uses My::MARC::Parser now    xmlreader ='test.xml', :readertype=>:marcxml)    # ...and maybe further on down the road    asreader ='test.seq', :readertype=>:alephsequential)   mjreader ='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.