lib/onix/reader.rb in onix-0.8.0 vs lib/onix/reader.rb in onix-0.8.1

- old
+ new

@@ -51,24 +51,25 @@ # version it is. # class Reader include Enumerable - attr_reader :header , :version, :xml_lang, :xml_version + attr_reader :header, :release def initialize(input, product_klass = ::ONIX::Product) if input.kind_of?(String) @file = File.open(input, "r") - @reader = Nokogiri::XML::Reader.from_io(@file) + @reader = Nokogiri::XML::Reader(@file) { |cfg| cfg.dtdload.noent } elsif input.kind_of?(IO) - @reader = Nokogiri::XML::Reader.from_io(input) + @reader = Nokogiri::XML::Reader(input) { |cfg| cfg.dtdload.noent } else raise ArgumentError, "Unable to read from file or IO stream" end @product_klass = product_klass + @release = find_release @header = find_header @xml_lang ||= @reader.lang @xml_version ||= @reader.xml_version.to_f end @@ -91,9 +92,26 @@ def close @reader.close if @reader end private + + def find_release + 2.times do + @reader.read + if @reader.node_type == 1 && @reader.name == "ONIXMessage" + value = @reader.attributes["release"] + if value + return BigDecimal.new(value) + else + return nil + end + elsif @reader.node_type == 14 + return nil + end + end + return nil + end def find_header 100.times do @reader.read if @reader.node_type == 1 && @reader.name == "Header"