Sha256: 902549ca03f8a0b7635fa8ae25c9390b88fad6091b9092a01caa2451cf634899

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

module MARC4J4R
  # 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 Writer
  
    # A simple factory to return the correct type of writer
    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
      else
        raise ArgumentError.new("#{type} must be :strictmarc or :marcxml")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
marc4j4r-1.4.1 lib/marc4j4r/writer.rb