module MARC::NokogiriReader
NokogiriReader
uses the Nokogiri SAX Parser to quickly read a MARCXML document. Because dynamically subclassing MARC::XMLReader
is a little ugly, we need to recreate all of the SAX event methods from Nokogiri::XML::SAX::Document here rather than subclassing.
Constants
- SAX_METHODS
Public Class Methods
extended(receiver)
click to toggle source
# File lib/marc/xml_parsers.rb, line 132 def self.extended(receiver) require "nokogiri" receiver.init end
Public Instance Methods
each(&block)
click to toggle source
Loop through the MARC
records in the XML document
# File lib/marc/xml_parsers.rb, line 144 def each(&block) if block @block = block @parser.parse(@handle) else enum_for(:each) end end
error(evt)
click to toggle source
# File lib/marc/xml_parsers.rb, line 153 def error(evt) raise(XMLParseError, "XML parsing error: #{evt}") end
init()
click to toggle source
Sets our instance variables for SAX parsing in Nokogiri and parser
Calls superclass method
MARC::GenericPullParser#init
# File lib/marc/xml_parsers.rb, line 138 def init super @parser = Nokogiri::XML::SAX::Parser.new(self) end
method_missing(method_name, *args)
click to toggle source
# File lib/marc/xml_parsers.rb, line 160 def method_missing(method_name, *args) unless SAX_METHODS.include?(method_name) raise NoMethodError.new("undefined method '#{method_name} for #{self}", "no_meth") end end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/marc/xml_parsers.rb, line 166 def respond_to_missing?(method_name, include_private = false) SAX_METHODS.include?(method_name) || super end
Private Instance Methods
attributes_to_hash(attributes)
click to toggle source
# File lib/marc/xml_parsers.rb, line 172 def attributes_to_hash(attributes) hash = {} attributes.each do |att| hash[att.localname] = att.value end hash end