Class: MARC4J4R::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/marc4j4r/writer.rb

Overview

Add some sugar to the MarcWriter interface

Adjust the interface so that a #new call to any implementations that implement it can take a java.io.InputStream, ruby IO object, or String (that will be interpreted as a filename) without complaining.

The mechanism -- running module_eval on a string-representation of the new method in each of the hard-coded implementations -- is ugly and deeply unsettling.

Author:

  • Bill Dueber

Class Method Summary collapse

Class Method Details

.new(output, type = :strictmarc) ⇒ Object

A simple factory to return the correct type of writer



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/marc4j4r/writer.rb', line 18

def self.new output, type = :strictmarc
  @handle = IOConvert.byteoutstream(output)
  if type == :strictmarc
    return Java::org.marc4j.MarcStreamWriter.new(@handle)
  elsif type == :marcxml
    writer =  Java::org.marc4j.MarcXmlWriter.new(@handle)
    writer.setUnicodeNormalization(true)
    return writer
  elsif type == :json
    writer = Java::org.marc4j.MarcJsonWriter.new(@handle)
    return writer
  else
    raise ArgumentError.new("#{type} must be :strictmarc, :marcxml, or :json")
  end
end