Module: MARCExtensions::XMLReaderExtensions

Included in:
MARC::XMLReader
Defined in:
lib/marc_extensions/xml_reader.rb

Overview

Extends MARC::XMLReader.

Instance Method Summary collapse

Instance Method Details

#initialize(file, options) ⇒ Object #initialize(file, parser: 'rexml', freeze: false) ⇒ Object

Adds a :freeze option to MARC::XMLReader which freezes each record as it's constructed:

reader = MARC::XMLReader.new('marc.xml', { freeze: true })
record = reader.first
record.frozen?
# => true

Overloads:

  • #initialize(file, options) ⇒ Object

    Parameters:

    • file (String, IO)

      a string file path, or an IO object

    Options Hash (options):

    • parser (String) — default: 'rexml'

      which parser to use

    • freeze (Boolean) — default: false

      whether to freeze records as they're created

  • #initialize(file, parser: 'rexml', freeze: false) ⇒ Object

    Parameters:

    • file (String, IO)

      a string file path, or an IO object

    • parser (String) (defaults to: 'rexml')

      ('rexml') which parser to use

    • freeze (Boolean) (defaults to: false)

      (false) whether to freeze records as they're created

See Also:



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/marc_extensions/xml_reader.rb', line 26

def initialize(*args)
  file, options, @freeze = destructure_args(args)
  super(file, options)

  # It's surprisingly tricky to get these into the general superclass
  # chain, so instead we just prepend them to the eigenclass
  if respond_to?(:yield_record)
    class << self; prepend(MARCExtensions::YieldFrozenRecord); end
  elsif respond_to?(:build_record, true)
    class << self; prepend(MARCExtensions::BuildFrozenRecord); end
  end
end