marc-marc4j
Convert ruby-marc MARC::Record
objects to/from java marc4j org.marc4j.marc.Record
objects under JRuby.
Useful if you're working in JRuby and need to use a marc4j reader, or if you want to use a standard ruby-marc reader but spool some functionality out to java code that relies on marc4j obejcts.
Installation
chruby jruby # or however you use JRuby
gem install marc-marc4j
Creating a converter
You can load up the marc4j
jar file in three ways:
- Just require it yourself at the top of a file.
MARC::MARC4J
will detect that it's already been loaded and not try to load another copy.
require 'marc/marc4j'
require '../jarfiles/marc4j_2.5.jar'
converter = MARC::MARC4J.new # will use above jarfile
- Call
MARC::MARC4J.new(:jardir=>'/path/to/marc4j/jar/directory')
to state where your jar files live
require 'marc/marc4j'
converter = MARC::MARC4J.new(:jardir => '../jarfiles/') # Load all .jar files in ../jarfiles
- Call
MARC::MARC4J.new
without a:jarfile
argument to use the bundled marc4j jarfile.
require 'marc/marc4j'
converter = MARC::MARC4J.new # uses bundled marc4j jarfile unless marc4j is already loaded
Logging
You can also pass in a logger object, that responds to the normal debug
/warn
/etc.
require 'marc/marc4j'
require 'my/logging/library'
logger = My::Logging::Library.new(opts)
converter = MARC::MARC4J.new(:logger=>logger)
Doing the conversions
A converter only has two useful methods:
marc4j = converter.rubymarc_to_marc4j(r)
will convert a ruby-marcMARC::Record
object to a marc4j recordrmarc = converter.marc4j_to_rubymarc(j)
will convert a marc4j record to a rubyMARC::Record
object
Implementation details worth knowing
The converter doesn't do any caching at all, so if you want to only do the conversion once, you need to stick the result somewhere.
marc4j
records are built using a marc4j factory object. This defaults to aorg.marc4j.marc.MarcFactory
, but will use whatever class is in the java system propertyorg.marc4j.marc.MarcFactory
(as seen in the marc4j source code).
Copyright
Copyright (c) 2013 Bill Dueber
See LICENSE for details.