Module: MARC::MagicReader

Defined in:
lib/marc/xml_parsers.rb

Overview

The MagicReader will try to use the best available XML Parser at the time of initialization.

The order is currently:

* Nokogiri
* jrexml (JRuby only)
* rexml

With the idea that other parsers could be added as their modules are added. Realistically, this list should be limited to stream-based parsers. The magic should be used selectively, however. After all, one project’s definition of ‘best’ might not apply universally. It is arguable which is “best” on JRuby: Nokogiri or jrexml.

Class Method Summary collapse

Class Method Details

.extended(receiver) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/marc/xml_parsers.rb', line 15

def self.extended(receiver)
  # Start with a Nokogiri check
  begin
    require 'nokogiri'
    receiver.extend(NokogiriReader)
  rescue LoadError
    if RUBY_PLATFORM =~ /java/
      # If using JRuby, use JREXML if it's there
      begin
        receiver.extend(JREXMLReader)
        return
      rescue LoadError
      end
    end       
    # If you're here, you're stuck with lowly REXML
    receiver.extend(REXMLReader) 
  end        
end