Module: BerkeleyLibrary::AV::Marc
- Defined in:
- lib/berkeley_library/av/marc.rb,
lib/berkeley_library/av/marc/util.rb
Defined Under Namespace
Modules: Util
Class Method Summary collapse
-
.all_from_xml(xml) ⇒ MARC::XMLReader
Parses MARCXML.
-
.from_xml(xml) ⇒ MARC::Record?
Parses MARCXML.
-
.read(marc_path, external_encoding: 'MARC-8') ⇒ MARC::Record
Returns a MARC record read from the specified file (or the first record if the file contains multiple records).
-
.reader_for(marc_path, external_encoding: 'MARC-8') ⇒ MARC::XMLReader, MARC::Reader
Returns a reader for the specified MARC file.
Class Method Details
.all_from_xml(xml) ⇒ MARC::XMLReader
Parses MARCXML.
20 21 22 23 |
# File 'lib/berkeley_library/av/marc.rb', line 20 def all_from_xml(xml) input = StringIO.new(xml.scrub) MARC::XMLReader.new(input) end |
.from_xml(xml) ⇒ MARC::Record?
Parses MARCXML.
11 12 13 14 |
# File 'lib/berkeley_library/av/marc.rb', line 11 def from_xml(xml) # noinspection RubyYardReturnMatch,RubyMismatchedReturnType all_from_xml(xml).first end |
.read(marc_path, external_encoding: 'MARC-8') ⇒ MARC::Record
Returns a MARC record read from the specified file (or the first record if the file contains multiple records).
45 46 47 48 |
# File 'lib/berkeley_library/av/marc.rb', line 45 def read(marc_path, external_encoding: 'MARC-8') # noinspection RubyYardReturnMatch reader_for(marc_path, external_encoding:).first end |
.reader_for(marc_path, external_encoding: 'MARC-8') ⇒ MARC::XMLReader, MARC::Reader
Returns a reader for the specified MARC file.
31 32 33 34 35 36 37 |
# File 'lib/berkeley_library/av/marc.rb', line 31 def reader_for(marc_path, external_encoding: 'MARC-8') downcased_path = marc_path.downcase return MARC::XMLReader.new(marc_path) if downcased_path.end_with?('.xml') return MARC::Reader.new(marc_path, external_encoding:) if downcased_path.end_with?('.mrc') raise ArgumentError, "Unable to determine reader needed for MARC file #{marc_path.inspect}" end |