milkfarm-onix 0.7.7 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +31 -1
- data/README.markdown +24 -2
- data/lib/onix.rb +3 -16
- data/lib/onix/addressee_identifier.rb +0 -1
- data/lib/onix/apa_product.rb +19 -2
- data/lib/onix/audience_range.rb +6 -7
- 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/lists/contributor_role.rb +99 -0
- 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/normaliser.rb +0 -77
- data/lib/onix/other_text.rb +0 -1
- data/lib/onix/price.rb +0 -1
- data/lib/onix/product.rb +3 -2
- data/lib/onix/product_identifier.rb +0 -1
- data/lib/onix/publisher.rb +0 -1
- data/lib/onix/reader.rb +39 -96
- data/lib/onix/sales_restriction.rb +0 -1
- data/lib/onix/sender_identifier.rb +0 -1
- data/lib/onix/series.rb +8 -8
- data/lib/onix/series_identifier.rb +0 -1
- data/lib/onix/set.rb +76 -0
- data/lib/onix/sl_product.rb +32 -45
- 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/lib/onix/writer.rb +1 -1
- data/spec/apa_product_spec.rb +44 -4
- data/spec/audience_range_spec.rb +5 -7
- 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 +5 -7
- 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 -78
- 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 +15 -22
- data/spec/sales_restriction_spec.rb +2 -4
- data/spec/sender_identifier.rb +2 -4
- data/spec/series_identifier_spec.rb +5 -7
- data/spec/series_spec.rb +4 -6
- data/spec/set_spec.rb +32 -0
- data/spec/sl_product_spec.rb +76 -24
- data/spec/spec_helper.rb +8 -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 +64 -28
- data/lib/onix/common.rb +0 -26
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::ProductIdentifier" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "product_identifier.xml")
|
12
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
data/spec/product_spec.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
6
|
-
require 'date'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
7
4
|
|
8
5
|
context "ONIX::Product" do
|
9
6
|
|
10
7
|
before(:each) do
|
11
8
|
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
12
9
|
file1 = File.join(@data_path, "product.xml")
|
13
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
14
11
|
@product_node = @doc.root
|
15
12
|
end
|
16
13
|
|
data/spec/publisher_spec.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::Publisher" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "publisher.xml")
|
12
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
data/spec/reader_spec.rb
CHANGED
@@ -1,43 +1,36 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::Reader" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
|
-
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
-
@file1 = File.join(data_path, "9780194351898.xml")
|
12
|
-
@file2 = File.join(data_path, "two_products.xml")
|
13
|
-
@long_file = File.join(data_path, "Bookwise_July_2008.xml")
|
14
|
-
@entity_file = File.join(data_path, "entities.xml")
|
15
|
-
@utf_16_file = File.join(data_path, "utf_16.xml")
|
16
|
-
@iso_8859_1_file = File.join(data_path, "iso_8859_1.xml")
|
8
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
9
|
+
@file1 = File.join(@data_path, "9780194351898.xml")
|
10
|
+
@file2 = File.join(@data_path, "two_products.xml")
|
11
|
+
@long_file = File.join(@data_path, "Bookwise_July_2008.xml")
|
12
|
+
@entity_file = File.join(@data_path, "entities.xml")
|
13
|
+
@utf_16_file = File.join(@data_path, "utf_16.xml")
|
14
|
+
@iso_8859_1_file = File.join(@data_path, "iso_8859_1.xml")
|
17
15
|
end
|
18
16
|
|
19
17
|
specify "should initialize with a filename" do
|
20
18
|
reader = ONIX::Reader.new(@file1)
|
21
|
-
reader.instance_variable_get("@reader").should be_a_kind_of(
|
19
|
+
reader.instance_variable_get("@reader").should be_a_kind_of(Nokogiri::XML::Reader)
|
22
20
|
end
|
23
21
|
|
24
22
|
specify "should initialize with an IO object" do
|
25
23
|
File.open(@file1,"rb") do |f|
|
26
24
|
reader = ONIX::Reader.new(f)
|
27
|
-
reader.instance_variable_get("@reader").should be_a_kind_of(
|
25
|
+
reader.instance_variable_get("@reader").should be_a_kind_of(Nokogiri::XML::Reader)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
# reader.encoding.should eql("utf-8")
|
37
|
-
# reader.xml_lang.should eql(nil)
|
38
|
-
# reader.xml_version.should eql(1.0)
|
39
|
-
# reader.version.should eql([2,1,0])
|
40
|
-
#end
|
29
|
+
specify "should provide access to various XML metadata from file" do
|
30
|
+
filename = File.join(@data_path, "reference_with_release_attrib.xml")
|
31
|
+
reader = ONIX::Reader.new(filename)
|
32
|
+
reader.release.should eql(BigDecimal.new("2.1"))
|
33
|
+
end
|
41
34
|
|
42
35
|
specify "should provide access to the header in an ONIX file" do
|
43
36
|
reader = ONIX::Reader.new(@file1)
|
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::SalesRestriction" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "sales_restriction.xml")
|
12
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
data/spec/sender_identifier.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::SenderIdentifier" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "sender_identifier.xml")
|
12
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::SeriesIdentifier" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "series_identifier.xml")
|
12
|
-
@doc =
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
@@ -20,17 +18,17 @@ context "ONIX::SeriesIdentifier" do
|
|
20
18
|
|
21
19
|
specify "should provide read access to first level attibutes" do
|
22
20
|
series = ONIX::SeriesIdentifier.from_xml(@root.to_s)
|
23
|
-
|
21
|
+
|
24
22
|
series.series_id_type.should eql(1)
|
25
23
|
series.id_value.should eql("10001")
|
26
24
|
end
|
27
25
|
|
28
26
|
specify "should provide write access to first level attibutes" do
|
29
27
|
series = ONIX::SeriesIdentifier.new
|
30
|
-
|
28
|
+
|
31
29
|
series.series_id_type = 9
|
32
30
|
series.to_xml.to_s.include?("<SeriesIDType>09</SeriesIDType>").should be_true
|
33
|
-
|
31
|
+
|
34
32
|
series.id_value = 999
|
35
33
|
series.to_xml.to_s.include?("<IDValue>999</IDValue>").should be_true
|
36
34
|
end
|
data/spec/series_spec.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::Series" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "series.xml")
|
12
|
-
@doc =
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
@@ -20,13 +18,13 @@ context "ONIX::Series" do
|
|
20
18
|
|
21
19
|
specify "should provide read access to first level attibutes" do
|
22
20
|
series = ONIX::Series.from_xml(@root.to_s)
|
23
|
-
|
21
|
+
|
24
22
|
series.title_of_series.should eql("Citizens and Their Governments")
|
25
23
|
end
|
26
24
|
|
27
25
|
specify "should provide write access to first level attibutes" do
|
28
26
|
series = ONIX::Series.new
|
29
|
-
|
27
|
+
|
30
28
|
series.title_of_series = "Cool Science Careers"
|
31
29
|
series.to_xml.to_s.include?("<TitleOfSeries>Cool Science Careers</TitleOfSeries>").should be_true
|
32
30
|
end
|
data/spec/set_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
4
|
+
|
5
|
+
context "ONIX::Set" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
9
|
+
file1 = File.join(data_path, "set.xml")
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
11
|
+
@root = @doc.root
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "should correctly convert to a string" do
|
15
|
+
set = ONIX::Set.from_xml(@root.to_s)
|
16
|
+
set.to_xml.to_s[0,5].should eql("<Set>")
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "should provide read access to first level attibutes" do
|
20
|
+
set = ONIX::Set.from_xml(@root.to_s)
|
21
|
+
|
22
|
+
set.title_of_set.should eql("Citizens and Their Governments")
|
23
|
+
end
|
24
|
+
|
25
|
+
specify "should provide write access to first level attibutes" do
|
26
|
+
set = ONIX::Set.new
|
27
|
+
|
28
|
+
set.title_of_set = "Cool Science Careers"
|
29
|
+
set.to_xml.to_s.include?("<TitleOfSet>Cool Science Careers</TitleOfSet>").should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/spec/sl_product_spec.rb
CHANGED
@@ -1,48 +1,100 @@
|
|
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::SLProduct" do
|
9
7
|
|
10
8
|
before(:each) do
|
11
9
|
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
12
|
-
file1
|
13
|
-
@doc
|
10
|
+
file1 = File.join(@data_path, "product.xml")
|
11
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
14
12
|
@product_node = @doc.root
|
15
13
|
end
|
16
14
|
|
17
|
-
specify "should provide read access to
|
15
|
+
specify "should provide read access to attibutes" do
|
18
16
|
@product = ONIX::Product.from_xml(@product_node.to_s)
|
19
|
-
@sl
|
17
|
+
@sl = ONIX::SLProduct.new(@product)
|
20
18
|
|
21
|
-
@sl.record_reference.should eql("
|
22
|
-
@sl.notification_type.should eql(
|
23
|
-
@sl.
|
24
|
-
@sl.
|
25
|
-
@sl.
|
26
|
-
@sl.
|
19
|
+
@sl.record_reference.should eql("365-9780194351898")
|
20
|
+
@sl.notification_type.should eql(3)
|
21
|
+
@sl.product_form.should eql("BC")
|
22
|
+
@sl.number_of_pages.should eql(100)
|
23
|
+
@sl.bic_main_subject.should eql("EB")
|
24
|
+
@sl.publishing_status.should eql(4)
|
25
|
+
@sl.publication_date.should eql(Date.civil(1998,9,1))
|
26
|
+
@sl.pack_quantity.should eql(12)
|
27
27
|
end
|
28
28
|
|
29
29
|
specify "should provide write access to attibutes" do
|
30
|
-
|
30
|
+
sl = ONIX::SLProduct.new
|
31
|
+
|
32
|
+
sl.notification_type = 3
|
33
|
+
sl.to_xml.to_s.include?("<NotificationType>03</NotificationType>").should be_true
|
34
|
+
|
35
|
+
sl.record_reference = "365-9780194351898"
|
36
|
+
sl.to_xml.to_s.include?("<RecordReference>365-9780194351898</RecordReference>").should be_true
|
37
|
+
|
38
|
+
sl.product_form = "BC"
|
39
|
+
sl.to_xml.to_s.include?("<ProductForm>BC</ProductForm>").should be_true
|
40
|
+
|
41
|
+
sl.number_of_pages = 100
|
42
|
+
sl.to_xml.to_s.include?("<NumberOfPages>100</NumberOfPages>").should be_true
|
43
|
+
|
44
|
+
sl.bic_main_subject = "EB"
|
45
|
+
sl.to_xml.to_s.include?("<BICMainSubject>EB</BICMainSubject>").should be_true
|
46
|
+
|
47
|
+
sl.publishing_status = 4
|
48
|
+
sl.to_xml.to_s.include?("<PublishingStatus>04</PublishingStatus>").should be_true
|
31
49
|
|
32
|
-
|
33
|
-
|
50
|
+
sl.publication_date = Date.civil(1998,9,1)
|
51
|
+
sl.to_xml.to_s.include?("<PublicationDate>19980901</PublicationDate>").should be_true
|
52
|
+
|
53
|
+
sl.pack_quantity = 12
|
54
|
+
sl.to_xml.to_s.include?("<PackQuantity>12</PackQuantity>").should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context ONIX::SLProduct, "series method" do
|
60
|
+
specify "should set the nested series value on the underlying product class" do
|
61
|
+
sl = ONIX::SLProduct.new
|
62
|
+
|
63
|
+
sl.series = "Harry Potter"
|
64
|
+
sl.series = "Lemony Snicket"
|
65
|
+
sl.to_xml.to_s.include?("<TitleOfSeries>Harry Potter</TitleOfSeries>").should be_true
|
66
|
+
sl.to_xml.to_s.include?("<TitleOfSeries>Lemony Snicket</TitleOfSeries>").should be_true
|
67
|
+
end
|
68
|
+
end
|
34
69
|
|
35
|
-
|
36
|
-
|
70
|
+
context ONIX::SLProduct, "price method" do
|
71
|
+
before(:each) do
|
72
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
73
|
+
file1 = File.join(@data_path, "usd.xml")
|
74
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
75
|
+
@product_node = @doc.root
|
76
|
+
end
|
37
77
|
|
38
|
-
|
39
|
-
|
78
|
+
specify "should return the first price in the file, regardless of type" do
|
79
|
+
@product = ONIX::Product.from_xml(@product_node.to_s)
|
80
|
+
@sl = ONIX::SLProduct.new(@product)
|
40
81
|
|
41
|
-
|
42
|
-
|
82
|
+
@sl.price.should eql(BigDecimal.new("99.95"))
|
83
|
+
end
|
84
|
+
end
|
43
85
|
|
44
|
-
|
45
|
-
|
86
|
+
context ONIX::SLProduct, "rrp_exc_sales_tax method" do
|
87
|
+
before(:each) do
|
88
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
89
|
+
file1 = File.join(@data_path, "usd.xml")
|
90
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
91
|
+
@product_node = @doc.root
|
46
92
|
end
|
47
93
|
|
94
|
+
specify "should return the first price in the file of type 1" do
|
95
|
+
@product = ONIX::Product.from_xml(@product_node.to_s)
|
96
|
+
@sl = ONIX::SLProduct.new(@product)
|
97
|
+
|
98
|
+
@sl.rrp_exc_sales_tax.should eql(BigDecimal.new("99.95"))
|
99
|
+
end
|
48
100
|
end
|
data/spec/spec_helper.rb
ADDED
data/spec/stock_spec.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::Stock" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "stock.xml")
|
12
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
data/spec/subject_spec.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::Subject" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "subject.xml")
|
12
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|
data/spec/supply_detail_spec.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'onix'
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
4
|
|
7
5
|
context "ONIX::SupplyDetail" do
|
8
6
|
|
9
7
|
before(:each) do
|
10
8
|
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
9
|
file1 = File.join(data_path, "supply_detail.xml")
|
12
|
-
@doc
|
10
|
+
@doc = Nokogiri::XML::Document.parse(File.read(file1))
|
13
11
|
@root = @doc.root
|
14
12
|
end
|
15
13
|
|