Module: MARC4J4R

Defined in:
lib/marc4j4r.rb

Constant Summary

NEWINIT = A string used to override the initializer for each stream reader Need to do it this ugly way because of the way java and ruby interact; can’t just add it to the MarcReader interface the way I wanted to.
"alias_method :oldinit, :initialize\ndef initialize(fromwhere)\nstream = nil\nif fromwhere.is_a? Java::JavaIO::InputStream\nstream = fromwhere\nelsif fromwhere.is_a? IO\nstream = fromwhere.to_inputstream\nelse\nstream = java.io.FileInputStream.new(fromwhere.to_java_string)\nend\nif self.class == Java::org.marc4j.MarcPermissiveStreamReader\nself.oldinit(stream, true, true)\nelse\nself.oldinit(stream)\nend\nend\n"

Instance Method Summary

Instance Method Details

- (MarcReader) reader(input, type = :strictmarc)

Get a marc reader of the appropriate type

Examples:

Get a strict binary MARC reader for the file ‘test.mrc’

 reader = MARC4J4R.reader('test.mrc')

Get a permissive binary MARC reader

 reader = MARC4J4R.reader('test.mrc', :permissivemarc)

Get a reader for an xml file

 reader = MARC4J4R.reader('test.xml', :marcxml)

Get a reader based on an existing IO object

  require 'open-uri'
  infile = open('http://my.machine.com/test.mrc')
  reader = MARC4J4R.reader(infile)

Parameters:

  • (String, IO, java.io.InputStream) input — The IO stream (or filename) from which you want to read
  • (:strictmarc, :permissivemarc, :marcxml) The — type of MARC reader you want.

Returns:

  • (MarcReader) — A MarcReader object with the syntactic sugar added in this file (e.g, each)


76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/marc4j4r.rb', line 76

def reader(input, type  = :strictmarc)
  case type
  when :strictmarc
    return Java::org.marc4j.MarcStreamReader.new(input)
  when :permissivemarc
    return Java::org.marc4j.MarcPermissiveStreamReader.new(input)
  when :marcxml
    return Java::org.marc4j.MarcXmlReader.new(input)
  else
    raise ArgumentError, "Reader type must be :strictmarc, :permissivemarc, or :marcxml"
  end
end