Module: MARC::GenericPullParser
- Included in:
- JRubySTAXReader, NokogiriReader
- Defined in:
- lib/marc/xml_parsers.rb
Instance Method Summary collapse
- #characters(text) ⇒ Object
- #end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
- #start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = {}) ⇒ Object
-
#yield_record ⇒ Object
Returns our MARC::Record object to the #each block.
Instance Method Details
#characters(text) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/marc/xml_parsers.rb', line 60 def characters text case @current_element when :leader then @record[:record].leader = text when :field then @record[:field].value << text when :subfield then @record[:subfield].value << text end end |
#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/marc/xml_parsers.rb', line 68 def end_element_namespace name, prefix = nil, uri = nil @current_element = nil if uri == @ns case name.downcase when 'record' then yield_record when /(control|data)field/ @record[:record] << @record[:field] @record[:field] = nil @current_element = nil if @current_element == :field when 'subfield' @record[:field].append(@record[:subfield]) @record[:subfield] = nil @current_element = nil if @current_element == :subfield end end end |
#start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/marc/xml_parsers.rb', line 41 def start_element_namespace name, attributes = [], prefix = nil, uri = nil, ns = {} attributes = attributes_to_hash(attributes) if uri == @ns case name.downcase when 'record' then @record[:record] = MARC::Record.new when 'leader' then @current_element = :leader when 'controlfield' @current_element=:field @record[:field] = MARC::ControlField.new(attributes["tag"]) when 'datafield' @record[:field] = MARC::DataField.new(attributes["tag"], attributes['ind1'], attributes['ind2']) when 'subfield' @current_element=:subfield @record[:subfield] = MARC::Subfield.new(attributes['code']) end end end |
#yield_record ⇒ Object
Returns our MARC::Record object to the #each block.
36 37 38 39 |
# File 'lib/marc/xml_parsers.rb', line 36 def yield_record @block.call(@record[:record]) @record[:record] = nil end |