marc4j4r

marc4j4r is some simple syntactic sugar on top of the java libary marc4j. It allows iteration via #each and implements many of the same convenience functions as ruby-marc.

Most of the good stuff is in RecordImpl and DataFieldImpl. They, along with the *Reader classes, now implement #each for their subparts as well as #[] where it makes sense. See the examples in the documentation for more information.

There's also a convenience module method, MARC4J4R.reader, to get a reader, as shown below.

Example

require 'rubygems'
require 'marc4j4r'

reader = MARC4J4R.reader('test.mrc')
#reader = MARC4J4R.reader('test.mrc', :strictmarc) # be explicit
#preader = MARC4J4R.reader('test.mrc', :permissivemarc)
#xmlreader = MARC4J4R.reader('test.xml', :marcxml)
# 
# Can also use an IO object
# reader = MARC4J4R.reader(File.new('test.mrc'))


reader.each do |r|
  lccn = r['010']['a'] if r['010']
  isSBns = r.find_by_tag(['020', '022']).map {|f| f['a']}
  first035 = r['035']
  fullTitle = r['245'].sub_values(['a', 'b', 'd', 'f', 'h']).join(' ')
  r['300'].each do |subfield|
    puts subfield.code + ' ' + subfield.value
  end
end

== Copyright

Copyright (c) 2010 BillDueber. See LICENSE for details.