@@ -25,7 +25,7 @@ module ONIX
25
25
# in a shim that provides simple accessor access to common attributes, pass the
26
26
# shim class as a second argument
27
27
#
28
- # reader = ONIX::Reader.new("somefile.xml", ONIX::APAProduct)
28
+ # reader = ONIX::Reader.new("somefile.xml", :product_class => ONIX::APAProduct)
29
29
#
30
30
# puts reader.header.inspect
31
31
#
@@ -39,7 +39,7 @@ module ONIX
39
39
# As well as accessing the file header, there are handful of other read only
40
40
# attributes that might be useful
41
41
#
42
- # reader = ONIX::Reader.new("somefile.xml", ONIX::APAProduct )
42
+ # reader = ONIX::Reader.new("somefile.xml")
43
43
#
44
44
# puts reader.version
45
45
# puts reader.xml_lang
@@ -62,7 +62,7 @@ module ONIX
62
62
# If the encoding declaration is missing or wrong and the file isn't UTF-8,
63
63
# you can manually set or override it like so:
64
64
#
65
- # reader = ONIX::Reader.new("somefile.xml", ONIX::APAProduct, :encoding => "iso-8859-1")
65
+ # reader = ONIX::Reader.new("somefile.xml", :encoding => "iso-8859-1")
66
66
#
67
67
# If the file contains invalid bytes for the source encoding an exception will
68
68
# be raised. This isn't ideal, but I'm still looking for ways to make this
@@ -73,18 +73,22 @@ class Reader
73
73
74
74
attr_reader :header , :release
75
75
76
- def initialize ( input , product_klass = nil , options = { } )
76
+ def initialize ( input , *args )
77
+ opts = args . last . kind_of? ( Hash ) ? args . pop : { }
78
+ if args . size > 0
79
+ ActiveSupport ::Deprecation . warn ( "Passing a klass as ONIX::Reader's second argument is deprecated, use the :product_class option instead" , caller )
80
+ end
81
+ @product_klass = opts [ :product_class ] || args . pop || ::ONIX ::Product
82
+
77
83
if input . kind_of? ( String )
78
84
@file = File . open ( input , "r" )
79
- @reader = Nokogiri ::XML ::Reader ( @file , nil , options [ :encoding ] ) { |cfg | cfg . dtdload . noent }
85
+ @reader = Nokogiri ::XML ::Reader ( @file , nil , opts [ :encoding ] ) { |cfg | cfg . dtdload . noent }
80
86
elsif input . kind_of? ( IO )
81
- @reader = Nokogiri ::XML ::Reader ( input , nil , options [ :encoding ] ) { |cfg | cfg . dtdload . noent }
87
+ @reader = Nokogiri ::XML ::Reader ( input , nil , opts [ :encoding ] ) { |cfg | cfg . dtdload . noent }
82
88
else
83
89
raise ArgumentError , "Unable to read from file or IO stream"
84
90
end
85
91
86
- @product_klass = product_klass || ::ONIX ::Product
87
-
88
92
@release = find_release
89
93
@header = find_header
90
94
0 commit comments