onix 0.7.8 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/lib/onix.rb +2 -16
- data/lib/onix/addressee_identifier.rb +0 -1
- data/lib/onix/apa_product.rb +5 -1
- data/lib/onix/audience_range.rb +0 -1
- data/lib/onix/contributor.rb +0 -1
- data/lib/onix/header.rb +0 -1
- data/lib/onix/imprint.rb +0 -1
- data/lib/onix/language.rb +0 -1
- data/lib/onix/market_representation.rb +0 -1
- data/lib/onix/measure.rb +0 -1
- data/lib/onix/media_file.rb +0 -1
- data/lib/onix/other_text.rb +0 -1
- data/lib/onix/price.rb +0 -1
- data/lib/onix/product.rb +0 -1
- data/lib/onix/product_identifier.rb +0 -1
- data/lib/onix/publisher.rb +0 -1
- data/lib/onix/reader.rb +24 -99
- data/lib/onix/sales_restriction.rb +0 -1
- data/lib/onix/sender_identifier.rb +0 -1
- data/lib/onix/series.rb +0 -1
- data/lib/onix/series_identifier.rb +0 -1
- data/lib/onix/stock.rb +0 -1
- data/lib/onix/subject.rb +0 -1
- data/lib/onix/supply_detail.rb +0 -1
- data/lib/onix/title.rb +0 -1
- data/lib/onix/website.rb +0 -1
- data/spec/apa_product_spec.rb +34 -4
- data/spec/audience_range_spec.rb +2 -4
- data/spec/contributor_spec.rb +2 -4
- data/spec/header_spec.rb +2 -4
- data/spec/imprint_spec.rb +4 -6
- data/spec/language_spec.rb +2 -4
- data/spec/market_representation_spec.rb +2 -4
- data/spec/measure_spec.rb +2 -4
- data/spec/media_file_spec.rb +2 -4
- data/spec/normaliser_spec.rb +1 -3
- data/spec/other_text_spec.rb +2 -4
- data/spec/price_spec.rb +2 -4
- data/spec/product_identifier_spec.rb +2 -4
- data/spec/product_spec.rb +2 -5
- data/spec/publisher_spec.rb +2 -4
- data/spec/reader_spec.rb +3 -5
- data/spec/sales_restriction_spec.rb +2 -4
- data/spec/sender_identifier.rb +2 -4
- data/spec/series_identifier_spec.rb +2 -4
- data/spec/series_spec.rb +2 -4
- data/spec/spec_helper.rb +7 -0
- data/spec/stock_spec.rb +2 -4
- data/spec/subject_spec.rb +2 -4
- data/spec/supply_detail_spec.rb +2 -4
- data/spec/title_spec.rb +2 -4
- data/spec/website_spec.rb +2 -4
- data/spec/writer_spec.rb +1 -4
- metadata +93 -92
- data/lib/onix/common.rb +0 -26
data/CHANGELOG
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
v0.8.0 (31st October 2009)
|
2
|
+
- Replace LibXML dependency with Nokogiri. Nokogiri is under active development, has
|
3
|
+
a responsive maintainer and is significantly more stable
|
4
|
+
- Switch to ROXML 3.x
|
5
|
+
- roxml also switched from libxml to nokogiri
|
6
|
+
- roxml removed deprecated parts of it's API
|
7
|
+
- should now avoid various conflicts with mongrel
|
8
|
+
- Ensure APAProduct#price returns the first product price and ignores
|
9
|
+
the price type
|
10
|
+
|
11
|
+
v0.7.8 (19th October 2009)
|
12
|
+
- add support for additional elements (mostly series and audience related)
|
13
|
+
- thanks tim
|
14
|
+
|
1
15
|
v0.7.7 (1st October 2009)
|
2
16
|
- optimise sed usage in ONIX::Normaliser. *huge* speed improvement on
|
3
17
|
large files.
|
data/lib/onix.rb
CHANGED
@@ -1,22 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require 'rubygems'
|
4
3
|
require 'bigdecimal'
|
5
4
|
require 'cgi'
|
6
|
-
|
7
|
-
# ensure we load the correct gem versions
|
8
|
-
gem 'roxml', '2.5.3'
|
9
|
-
gem 'andand'
|
10
|
-
|
11
|
-
# and now load the actual gems
|
12
5
|
require 'roxml'
|
13
6
|
require 'andand'
|
14
7
|
|
15
8
|
module ONIX
|
16
9
|
module Version #:nodoc:
|
17
10
|
Major = 0
|
18
|
-
Minor =
|
19
|
-
Tiny =
|
11
|
+
Minor = 8
|
12
|
+
Tiny = 0
|
20
13
|
|
21
14
|
String = [Major, Minor, Tiny].join('.')
|
22
15
|
end
|
@@ -60,13 +53,6 @@ module ONIX
|
|
60
53
|
end
|
61
54
|
end
|
62
55
|
|
63
|
-
# silence some warnings from ROXML
|
64
|
-
unless ROXML.const_defined?("SILENCE_XML_NAME_WARNING")
|
65
|
-
ROXML::SILENCE_XML_NAME_WARNING = true
|
66
|
-
end
|
67
|
-
|
68
|
-
require File.join(File.dirname(__FILE__), "onix", "common")
|
69
|
-
|
70
56
|
# core files
|
71
57
|
# - ordering is important, classes need to be defined before any
|
72
58
|
# other class can use them
|
data/lib/onix/apa_product.rb
CHANGED
@@ -651,7 +651,11 @@ module ONIX
|
|
651
651
|
# retrieve the value of a particular price
|
652
652
|
def price_get(type)
|
653
653
|
supply = find_or_create_supply_detail
|
654
|
-
|
654
|
+
if type.nil?
|
655
|
+
supply.prices.first
|
656
|
+
else
|
657
|
+
supply.prices.find { |p| p.price_type_code == type }
|
658
|
+
end
|
655
659
|
end
|
656
660
|
|
657
661
|
# set the value of a particular price
|
data/lib/onix/audience_range.rb
CHANGED
data/lib/onix/contributor.rb
CHANGED
data/lib/onix/header.rb
CHANGED
data/lib/onix/imprint.rb
CHANGED
data/lib/onix/language.rb
CHANGED
data/lib/onix/measure.rb
CHANGED
data/lib/onix/media_file.rb
CHANGED
data/lib/onix/other_text.rb
CHANGED
data/lib/onix/price.rb
CHANGED
data/lib/onix/product.rb
CHANGED
data/lib/onix/publisher.rb
CHANGED
data/lib/onix/reader.rb
CHANGED
@@ -53,31 +53,38 @@ module ONIX
|
|
53
53
|
class Reader
|
54
54
|
include Enumerable
|
55
55
|
|
56
|
-
attr_reader :header , :version, :xml_lang, :xml_version
|
56
|
+
attr_reader :header , :version, :xml_lang, :xml_version
|
57
57
|
|
58
58
|
def initialize(input, product_klass = ::ONIX::Product)
|
59
59
|
if input.kind_of?(String)
|
60
|
-
@
|
60
|
+
@file = File.open(input, "r")
|
61
|
+
@reader = Nokogiri::XML::Reader.from_io(@file)
|
61
62
|
elsif input.kind_of?(IO)
|
62
|
-
@reader =
|
63
|
+
@reader = Nokogiri::XML::Reader.from_io(input)
|
63
64
|
else
|
64
65
|
raise ArgumentError, "Unable to read from file or IO stream"
|
65
66
|
end
|
66
67
|
|
67
68
|
@product_klass = product_klass
|
68
69
|
|
69
|
-
@header =
|
70
|
+
@header = find_header
|
70
71
|
|
71
|
-
@xml_lang ||= @reader.
|
72
|
+
@xml_lang ||= @reader.lang
|
72
73
|
@xml_version ||= @reader.xml_version.to_f
|
73
|
-
@encoding ||= encoding_const_to_name(@reader.encoding)
|
74
74
|
end
|
75
75
|
|
76
76
|
# Iterate over all the products in an ONIX file
|
77
77
|
#
|
78
78
|
def each(&block)
|
79
|
-
|
80
|
-
|
79
|
+
@reader.each do |node|
|
80
|
+
if @reader.node_type == 1 && @reader.name == "Product"
|
81
|
+
str = @reader.outer_xml
|
82
|
+
if str.nil?
|
83
|
+
yield @product_klass.new
|
84
|
+
else
|
85
|
+
yield @product_klass.from_xml(str)
|
86
|
+
end
|
87
|
+
end
|
81
88
|
end
|
82
89
|
end
|
83
90
|
|
@@ -87,101 +94,19 @@ module ONIX
|
|
87
94
|
|
88
95
|
private
|
89
96
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
# cryptic errors about the input file being truncated or
|
100
|
-
# incomplete
|
101
|
-
#uri = @reader.expand.to_s.dup
|
102
|
-
#m, major, minor, rev = *uri.match(/.+(\d)\.(\d)\/(\d*).*/)
|
103
|
-
#@version = [major.to_i, minor.to_i, rev.to_i]
|
104
|
-
elsif @reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
|
105
|
-
if @reader.name == "Header"
|
106
|
-
str = normalise_string_encoding(@reader.read_outer_xml.to_s.dup)
|
107
|
-
if str.size == 0
|
108
|
-
return ONIX::Header.new
|
109
|
-
else
|
110
|
-
return ONIX::Header.from_xml(str)
|
111
|
-
end
|
112
|
-
elsif @reader.name == "Product"
|
113
|
-
str = normalise_string_encoding(@reader.read_outer_xml.to_s.dup)
|
114
|
-
if str.size == 0
|
115
|
-
return @product_klass.new
|
116
|
-
else
|
117
|
-
return @product_klass.from_xml(str)
|
118
|
-
end
|
97
|
+
def find_header
|
98
|
+
100.times do
|
99
|
+
@reader.read
|
100
|
+
if @reader.node_type == 1 && @reader.name == "Header"
|
101
|
+
str = @reader.outer_xml
|
102
|
+
if str.nil?
|
103
|
+
return ONIX::Header.new
|
104
|
+
else
|
105
|
+
return ONIX::Header.from_xml(str)
|
119
106
|
end
|
120
107
|
end
|
121
108
|
end
|
122
|
-
|
123
|
-
return nil
|
124
|
-
rescue LibXML::XML::Error => e
|
125
109
|
return nil
|
126
110
|
end
|
127
|
-
|
128
|
-
# XML::Reader seems to transparently convert all input data to utf-8, howver
|
129
|
-
# on Ruby 1.9 it fails to correctly set the encoding on the strings.
|
130
|
-
#
|
131
|
-
def normalise_string_encoding(str)
|
132
|
-
if RUBY_VERSION >= "1.9"
|
133
|
-
return str.dup.force_encoding("utf-8")
|
134
|
-
else
|
135
|
-
str
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
# simple mapping of encoding constants to a string
|
140
|
-
#
|
141
|
-
def encoding_const_to_name(const)
|
142
|
-
return nil if const.nil?
|
143
|
-
case const
|
144
|
-
when LibXML::XML::Encoding::UTF_8
|
145
|
-
"utf-8"
|
146
|
-
when LibXML::XML::Encoding::UTF_16LE
|
147
|
-
"utf-16le"
|
148
|
-
when LibXML::XML::Encoding::UTF_16BE
|
149
|
-
"utf-16be"
|
150
|
-
when LibXML::XML::Encoding::UCS_4LE
|
151
|
-
"ucs-4le"
|
152
|
-
when LibXML::XML::Encoding::UCS_4BE
|
153
|
-
"ucs-4be"
|
154
|
-
when LibXML::XML::Encoding::UCS_2
|
155
|
-
"ucs-2"
|
156
|
-
when LibXML::XML::Encoding::ISO_8859_1
|
157
|
-
"iso-8859-1"
|
158
|
-
when LibXML::XML::Encoding::ISO_8859_2
|
159
|
-
"iso-8859-2"
|
160
|
-
when LibXML::XML::Encoding::ISO_8859_3
|
161
|
-
"iso-8859-3"
|
162
|
-
when LibXML::XML::Encoding::ISO_8859_4
|
163
|
-
"iso-8859-4"
|
164
|
-
when LibXML::XML::Encoding::ISO_8859_5
|
165
|
-
"iso-8859-5"
|
166
|
-
when LibXML::XML::Encoding::ISO_8859_6
|
167
|
-
"iso-8859-6"
|
168
|
-
when LibXML::XML::Encoding::ISO_8859_7
|
169
|
-
"iso-8859-7"
|
170
|
-
when LibXML::XML::Encoding::ISO_8859_8
|
171
|
-
"iso-8859-8"
|
172
|
-
when LibXML::XML::Encoding::ISO_8859_9
|
173
|
-
"iso-8859-9"
|
174
|
-
when LibXML::XML::Encoding::ISO_2022_JP
|
175
|
-
"iso-2022-jp"
|
176
|
-
when LibXML::XML::Encoding::SHIFT_JIS
|
177
|
-
"shift-jis"
|
178
|
-
when LibXML::XML::Encoding::EUC_JP
|
179
|
-
"euc-jp"
|
180
|
-
when LibXML::XML::Encoding::ASCII
|
181
|
-
"ascii"
|
182
|
-
else
|
183
|
-
nil
|
184
|
-
end
|
185
|
-
end
|
186
111
|
end
|
187
112
|
end
|
data/lib/onix/series.rb
CHANGED
data/lib/onix/stock.rb
CHANGED
data/lib/onix/subject.rb
CHANGED
data/lib/onix/supply_detail.rb
CHANGED
data/lib/onix/title.rb
CHANGED
data/lib/onix/website.rb
CHANGED
data/spec/apa_product_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
require 'date'
|
7
5
|
|
8
6
|
context "ONIX::APAProduct" do
|
@@ -10,7 +8,7 @@ context "ONIX::APAProduct" do
|
|
10
8
|
before(:each) do
|
11
9
|
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
12
10
|
file1 = File.join(@data_path, "product.xml")
|
13
|
-
@doc
|
11
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
14
12
|
@product_node = @doc.root
|
15
13
|
end
|
16
14
|
|
@@ -57,3 +55,35 @@ context "ONIX::APAProduct" do
|
|
57
55
|
end
|
58
56
|
|
59
57
|
end
|
58
|
+
|
59
|
+
context ONIX::APAProduct, "price method" do
|
60
|
+
before(:each) do
|
61
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
62
|
+
file1 = File.join(@data_path, "usd.xml")
|
63
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
64
|
+
@product_node = @doc.root
|
65
|
+
end
|
66
|
+
|
67
|
+
specify "should return the first price in the file, regardless of type" do
|
68
|
+
@product = ONIX::Product.from_xml(@product_node.to_s)
|
69
|
+
@apa = ONIX::APAProduct.new(@product)
|
70
|
+
|
71
|
+
@apa.price.should eql(BigDecimal.new("99.95"))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context ONIX::APAProduct, "rrp_exc_sales_tax method" do
|
76
|
+
before(:each) do
|
77
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
78
|
+
file1 = File.join(@data_path, "usd.xml")
|
79
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
80
|
+
@product_node = @doc.root
|
81
|
+
end
|
82
|
+
|
83
|
+
specify "should return the first price in the file of type 1" do
|
84
|
+
@product = ONIX::Product.from_xml(@product_node.to_s)
|
85
|
+
@apa = ONIX::APAProduct.new(@product)
|
86
|
+
|
87
|
+
@apa.rrp_exc_sales_tax.should eql(BigDecimal.new("99.95"))
|
88
|
+
end
|
89
|
+
end
|