Class: BibframeRuby::MarcConverter
- Inherits:
-
Object
- Object
- BibframeRuby::MarcConverter
- Defined in:
- lib/bibframe_ruby/marc_converter.rb
Overview
Converts MARC (binary or MARCXML) to BIBFRAME RDF/XML using the vendored marc2bibframe2 XSLT.
Constant Summary collapse
- XSL_DIR =
File.("../../vendor/marc2bibframe2/xsl", __dir__)
- XSL_PATH =
File.join(XSL_DIR, "marc2bibframe2.xsl")
- CHDIR_MUTEX =
Mutex to serialise Dir.chdir calls — Dir.chdir is process-global and not thread-safe.
Mutex.new
Class Method Summary collapse
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(input, baseuri: "http://example.org/", idsource: "http://id.loc.gov/vocabulary/organizations/dlc") ⇒ MarcConverter
constructor
A new instance of MarcConverter.
Constructor Details
#initialize(input, baseuri: "http://example.org/", idsource: "http://id.loc.gov/vocabulary/organizations/dlc") ⇒ MarcConverter
Returns a new instance of MarcConverter.
17 18 19 20 21 |
# File 'lib/bibframe_ruby/marc_converter.rb', line 17 def initialize(input, baseuri: "http://example.org/", idsource: "http://id.loc.gov/vocabulary/organizations/dlc") @input = input @baseuri = baseuri @idsource = idsource end |
Class Method Details
.marcxml?(input) ⇒ Boolean
30 31 32 |
# File 'lib/bibframe_ruby/marc_converter.rb', line 30 def self.marcxml?(input) input.lstrip.start_with?("<") end |
.stylesheet ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/bibframe_ruby/marc_converter.rb', line 59 def self.stylesheet @stylesheet ||= CHDIR_MUTEX.synchronize do Dir.chdir(XSL_DIR) do Nokogiri::XSLT(File.read(XSL_PATH)) end end end |
Instance Method Details
#convert ⇒ Object
23 24 25 26 27 28 |
# File 'lib/bibframe_ruby/marc_converter.rb', line 23 def convert xml = self.class.marcxml?(@input) ? @input : binary_to_marcxml(@input) doc = Nokogiri::XML(xml) rdfxml = transform(doc) rdfxml.to_xml end |