module MARC::GenericPullParser
Constants
- CF_TAG
- DF_TAG
- LEAD_TAG
- REC_TAG
Submodules must include
self.extended() init() attributes_to_hash(attributes) each
- SF_TAG
Public Instance Methods
characters(text)
click to toggle source
# File lib/marc/xml_parsers.rb, line 95 def characters(text) case @current_element when :subfield then @record[:subfield].value << text when :field then @record[:field].value << text when :leader then @record[:leader] << text end end
end_element_namespace(name, prefix = nil, uri = nil)
click to toggle source
# File lib/marc/xml_parsers.rb, line 103 def end_element_namespace(name, prefix = nil, uri = nil) @current_element = nil if (uri == @ns) || @ignore_namespace case name.downcase when SF_TAG @record[:field].append(@record[:subfield]) @record[:subfield] = nil @current_element = nil if @current_element == :subfield when DF_TAG, CF_TAG @record[:record] << @record[:field] @record[:field] = nil @current_element = nil if @current_element == :field when REC_TAG then yield_record when LEAD_TAG @record[:record].leader = @record[:leader] @record[:leader] = "" @current_element = nil if @current_element == :leader end end end
init()
click to toggle source
# File lib/marc/xml_parsers.rb, line 58 def init @record = {record: nil, leader: "", field: nil, subfield: nil} @current_element = nil @ns = "http://www.loc.gov/MARC21/slim" end
start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = {})
click to toggle source
# File lib/marc/xml_parsers.rb, line 77 def start_element_namespace name, attributes = [], prefix = nil, uri = nil, ns = {} attributes = attributes_to_hash(attributes) if (uri == @ns) || @ignore_namespace case name.downcase when SF_TAG @current_element = :subfield @record[:subfield] = MARC::Subfield.new(attributes[CODE]) when DF_TAG @record[:field] = MARC::DataField.new(attributes[TAG], attributes[IND1], attributes[IND2]) when CF_TAG @current_element = :field @record[:field] = MARC::ControlField.new(attributes[TAG]) when LEAD_TAG then @current_element = :leader when REC_TAG then @record[:record] = MARC::Record.new end end end
yield_record()
click to toggle source
Returns our MARC::Record
object to the each block.
# File lib/marc/xml_parsers.rb, line 65 def yield_record if @record[:record].valid? @block.call(@record[:record]) elsif @error_handler @error_handler.call(self, @record[:record], @block) else raise MARC::RecordException, @record[:record] end ensure @record[:record] = nil end