Class: MARC4J4R::Reader
- Inherits:
-
Object
- Object
- MARC4J4R::Reader
- Defined in:
- lib/marc4j4r/reader.rb
Constant Summary collapse
- ENCODINGS =
['UTF-8', 'ISO-8859-1', 'MARC-8']
- ENCODING_ALIASES =
{:utf8 => 'UTF-8', :marc8 => 'MARC-8', :iso => 'ISO-8859-1'}
Instance Attribute Summary collapse
- #handle ⇒ Object readonly
Class Method Summary collapse
-
.new(input, type = :strictmarc, encoding = nil) ⇒ MarcReader
Get a marc reader of the appropriate type.
Instance Attribute Details
#handle ⇒ Object (readonly)
67 68 69 |
# File 'lib/marc4j4r/reader.rb', line 67 def handle @handle end |
Class Method Details
.new(input, type = :strictmarc, encoding = nil) ⇒ MarcReader
Get a marc reader of the appropriate type
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/marc4j4r/reader.rb', line 93 def self.new(input, type = :strictmarc, encoding = nil) if encoding encoding = ENCODING_ALIASES[encoding] if ENCODING_ALIASES[encoding] unless ENCODINGS.include? encoding raise ArgumentError, "Encoding must be in [#{ENCODINGS.map {|x| '"' + x + '"'}.join(', ')}], not \"#{encoding}\"" end end @handle = IOConvert.byteinstream(input) case type when :strictmarc then Java::org.marc4j.MarcStreamReader.send(:include, Enumerable) return Java::org.marc4j.MarcStreamReader.new(@handle, encoding) when :permissivemarc then encoding ||= 'BESTGUESS' Java::org.marc4j.MarcPermissiveStreamReader.send(:include, Enumerable) Java::org.marc4j.MarcPermissiveStreamReader.send(:include, JLogger::Simple) Java::org.marc4j.MarcPermissiveStreamReader.send(:include, MarcReader::LoggingNextRecord) return Java::org.marc4j.MarcPermissiveStreamReader.new(@handle, true, true, encoding) when :marcxml then Java::org.marc4j.MarcXmlReader.send(:include, Enumerable) Java::org.marc4j.MarcXmlReader.send(:include, JLogger::Simple) return Java::org.marc4j.MarcXmlReader.new(@handle) when :alephsequential then Java::org.marc4j.MarcAlephSequentialReader.send(:include, Enumerable) Java::org.marc4j.MarcAlephSequentialReader.send(:include, JLogger::Simple) Java::org.marc4j.MarcAlephSequentialReader.send(:include, MarcReader::LoggingNextRecord) return Java::org.marc4j.MarcAlephSequentialReader.new(@handle) when :json then Java::org.marc4j.MarcJsonReader.send(:include, Enumerable) Java::org.marc4j.MarcJsonReader.send(:include, JLogger::Simple) return Java::org.marc4j.MarcJsonReader.new(@handle) else raise ArgumentError, "Reader type #{type} illegal: must be :strictmarc, :permissivemarc, :marcxml, or :alephsequential" end end |