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
64 65 66 67 68 69 70 |
# File 'lib/marc/xml_parsers.rb', line 64 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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/marc/xml_parsers.rb', line 72 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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/marc/xml_parsers.rb', line 45 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.
40 41 42 43 |
# File 'lib/marc/xml_parsers.rb', line 40 def yield_record @block.call(@record[:record]) @record[:record] = nil end |