Module: MARC4J4R

Defined in:
lib/marc4j4r.rb

Defined Under Namespace

Classes: AlephSequentialReader

Constant Summary

NEWINIT = Add some sugar to the MarcReader interface.
"include Enumerable\nalias_method :oldinit, :initialize\ndef initialize(fromwhere)\nstream = nil\nif fromwhere.is_a? Java::JavaIO::InputStream or fromwhere.is_a? Java::JavaIO::ByteArrayInputStream\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)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/marc4j4r.rb', line 101

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