This is a class-oriented Ruby library that parses LOC’s MARC 21 data.
This gem is developed using the MARC 21 Slim XSD schema.
require 'loc-marc'
# Single record under `<collection>`
LocMarc::Collection.from_xml(File.read("spec/fixtures/record_1.xml"))
# Full NIST Tech Pubs records
# https://github.com/usnistgov/NIST-Tech-Pubs/tree/nist-pages/xml
# The file has been split because of GitHub size limits
LocMarc::Collection.from_xml(File.read("reference/allrecords-1.xml"))
LocMarc::Collection.from_xml(File.read("reference/allrecords-2.xml"))
This gem also provides code lists provide by MARC 21.
require 'loc-marc'
LocMarc::Codes::Relator.lookup('wam')
=> {:code=>"wam", :description=>"Writer of accompanying material", :deprecated=>false}
LocMarc::Codes::Language.lookup('en')
=> {:code=>"en", :description=>"Europe, Northern", :deprecated=>false}
LocMarc::Codes::Country.lookup('us')
=> {:code=>"us", :description=>"United States", :deprecated=>true}
LocMarc::Codes::Country.lookup('us')
=>{:code=>"xxu", :description=>"United States", :deprecated=>false},
LocMarc::Codes::GeographicArea.lookup('a-cc-hk')
=> {:code=>"a-cc-hk", :description=>"Hong Kong (China)", :deprecated=>false}