milkfarm-onix 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +136 -0
- data/README.markdown +40 -0
- data/TODO +14 -0
- data/dtd/2.1r3/iso-amsa.ent +173 -0
- data/dtd/2.1r3/iso-amsb.ent +146 -0
- data/dtd/2.1r3/iso-amsc.ent +49 -0
- data/dtd/2.1r3/iso-amsn.ent +117 -0
- data/dtd/2.1r3/iso-amso.ent +77 -0
- data/dtd/2.1r3/iso-amsr.ent +205 -0
- data/dtd/2.1r3/iso-box.ent +67 -0
- data/dtd/2.1r3/iso-cyr1.ent +94 -0
- data/dtd/2.1r3/iso-cyr2.ent +53 -0
- data/dtd/2.1r3/iso-dia.ent +41 -0
- data/dtd/2.1r3/iso-grk3.ent +70 -0
- data/dtd/2.1r3/iso-lat1.ent +89 -0
- data/dtd/2.1r3/iso-lat2.ent +148 -0
- data/dtd/2.1r3/iso-mfrk.ent +79 -0
- data/dtd/2.1r3/iso-mopf.ent +53 -0
- data/dtd/2.1r3/iso-mscr.ent +79 -0
- data/dtd/2.1r3/iso-num.ent +103 -0
- data/dtd/2.1r3/iso-num.old.ent +103 -0
- data/dtd/2.1r3/iso-pub.ent +110 -0
- data/dtd/2.1r3/iso-tech.ent +183 -0
- data/dtd/2.1r3/onix-international.dtd +1012 -0
- data/dtd/2.1r3/onix-xhtml.elt +672 -0
- data/dtd/2.1r3/reference.elt +4758 -0
- data/dtd/2.1r3/xhtml-special.ent +79 -0
- data/dtd/2.1r3/xhtml-symbol.ent +242 -0
- data/lib/onix/addressee_identifier.rb +12 -0
- data/lib/onix/apa_product.rb +731 -0
- data/lib/onix/audience_range.rb +26 -0
- data/lib/onix/common.rb +26 -0
- data/lib/onix/contributor.rb +27 -0
- data/lib/onix/header.rb +46 -0
- data/lib/onix/imprint.rb +15 -0
- data/lib/onix/language.rb +14 -0
- data/lib/onix/lists/audience_code.rb +17 -0
- data/lib/onix/lists/country_code.rb +257 -0
- data/lib/onix/lists/language_code.rb +498 -0
- data/lib/onix/lists/language_role.rb +18 -0
- data/lib/onix/lists/notification_type.rb +19 -0
- data/lib/onix/lists/product_availability.rb +32 -0
- data/lib/onix/lists/product_form.rb +99 -0
- data/lib/onix/lists/product_form_detail.rb +157 -0
- data/lib/onix/market_representation.rb +19 -0
- data/lib/onix/measure.rb +14 -0
- data/lib/onix/media_file.rb +16 -0
- data/lib/onix/normaliser.rb +187 -0
- data/lib/onix/other_text.rb +17 -0
- data/lib/onix/price.rb +21 -0
- data/lib/onix/product.rb +73 -0
- data/lib/onix/product_identifier.rb +13 -0
- data/lib/onix/publisher.rb +16 -0
- data/lib/onix/reader.rb +187 -0
- data/lib/onix/sales_restriction.rb +12 -0
- data/lib/onix/sender_identifier.rb +14 -0
- data/lib/onix/series.rb +57 -0
- data/lib/onix/series_identifier.rb +13 -0
- data/lib/onix/simple_product.rb +47 -0
- data/lib/onix/sl_product.rb +131 -0
- data/lib/onix/stock.rb +15 -0
- data/lib/onix/subject.rb +16 -0
- data/lib/onix/supply_detail.rb +32 -0
- data/lib/onix/title.rb +17 -0
- data/lib/onix/website.rb +14 -0
- data/lib/onix/writer.rb +86 -0
- data/lib/onix.rb +114 -0
- data/spec/apa_product_spec.rb +59 -0
- data/spec/audience_range_spec.rb +46 -0
- data/spec/contributor_spec.rb +42 -0
- data/spec/header_spec.rb +123 -0
- data/spec/imprint_spec.rb +39 -0
- data/spec/language_spec.rb +42 -0
- data/spec/market_representation_spec.rb +41 -0
- data/spec/measure_spec.rb +43 -0
- data/spec/media_file_spec.rb +42 -0
- data/spec/normaliser_spec.rb +125 -0
- data/spec/other_text_spec.rb +40 -0
- data/spec/price_spec.rb +40 -0
- data/spec/product_identifier_spec.rb +40 -0
- data/spec/product_spec.rb +96 -0
- data/spec/publisher_spec.rb +38 -0
- data/spec/reader_spec.rb +131 -0
- data/spec/sales_restriction_spec.rb +35 -0
- data/spec/sender_identifier.rb +40 -0
- data/spec/series_identifier_spec.rb +38 -0
- data/spec/series_spec.rb +34 -0
- data/spec/sl_product_spec.rb +48 -0
- data/spec/stock_spec.rb +44 -0
- data/spec/subject_spec.rb +40 -0
- data/spec/supply_detail_spec.rb +53 -0
- data/spec/title_spec.rb +43 -0
- data/spec/website_spec.rb +41 -0
- data/spec/writer_spec.rb +81 -0
- data/support/entities.txt +1499 -0
- data/support/extract.rb +25 -0
- data/support/switch-onix-2.1-short-to-reference.xsl +23 -0
- data/support/switch-onix-tagnames-1.1.xsl +25 -0
- data/support/switch-onix-tagnames-2.0.xsl +37 -0
- metadata +209 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::Normaliser", "with a simple short tag file" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
@filename = File.join(@data_path, "short_tags.xml")
|
12
|
+
@outfile = @filename + ".new"
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
File.unlink(@outfile) if File.file?(@outfile)
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "should correctly convert short tag file to reference tag" do
|
20
|
+
ONIX::Normaliser.process(@filename, @outfile)
|
21
|
+
|
22
|
+
File.file?(@outfile).should be_true
|
23
|
+
content = File.read(@outfile)
|
24
|
+
content.include?("<m174>").should be_false
|
25
|
+
content.include?("<FromCompany>").should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "ONIX::Normaliser", "with an ISO-8859-1 file" do
|
31
|
+
|
32
|
+
before(:each) do
|
33
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
34
|
+
@filename = File.join(@data_path, "iso_8859_1.xml")
|
35
|
+
@outfile = @filename + ".new"
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:each) do
|
39
|
+
File.unlink(@outfile) if File.file?(@outfile)
|
40
|
+
end
|
41
|
+
|
42
|
+
specify "should correctly convert an iso-8859-1 file to UTF-8" do
|
43
|
+
ONIX::Normaliser.process(@filename, @outfile)
|
44
|
+
|
45
|
+
File.file?(@outfile).should be_true
|
46
|
+
content = File.read(@outfile)
|
47
|
+
|
48
|
+
content.include?("ISO-8859-1").should be_false
|
49
|
+
content.include?("UTF-8").should be_true
|
50
|
+
|
51
|
+
`isutf8 #{File.expand_path(@outfile)}`.strip.should eql("")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
context "ONIX::Normaliser", "with an file using entities" do
|
57
|
+
|
58
|
+
before(:each) do
|
59
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
60
|
+
@filename = File.join(@data_path, "entities.xml")
|
61
|
+
@outfile = @filename + ".new"
|
62
|
+
end
|
63
|
+
|
64
|
+
after(:each) do
|
65
|
+
File.unlink(@outfile) if File.file?(@outfile)
|
66
|
+
end
|
67
|
+
|
68
|
+
specify "should correctly convert named entities to numeric entities" do
|
69
|
+
ONIX::Normaliser.process(@filename, @outfile)
|
70
|
+
|
71
|
+
File.file?(@outfile).should be_true
|
72
|
+
content = File.read(@outfile)
|
73
|
+
|
74
|
+
content.include?("–").should be_false
|
75
|
+
content.include?("–").should be_true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "ONIX::Normaliser", "with a utf8 file that has no declared encoding" do
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
83
|
+
@filename = File.join(@data_path, "no_encoding.xml")
|
84
|
+
@outfile = @filename + ".new"
|
85
|
+
end
|
86
|
+
|
87
|
+
after(:each) do
|
88
|
+
File.unlink(@outfile) if File.file?(@outfile)
|
89
|
+
end
|
90
|
+
|
91
|
+
# this is to test for a bug where an exception was raised on files that
|
92
|
+
# had no declared encoding
|
93
|
+
specify "should add a utf-8 marker to the file" do
|
94
|
+
ONIX::Normaliser.process(@filename, @outfile)
|
95
|
+
|
96
|
+
File.file?(@outfile).should be_true
|
97
|
+
content = File.read(@outfile)
|
98
|
+
|
99
|
+
content.include?("encoding=\"UTF-8\"").should be_true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "ONIX::Normaliser", "with a utf8 file that has illegal control chars" do
|
104
|
+
|
105
|
+
before(:each) do
|
106
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
107
|
+
@filename = File.join(@data_path, "control_chars.xml")
|
108
|
+
@outfile = @filename + ".new"
|
109
|
+
end
|
110
|
+
|
111
|
+
after(:each) do
|
112
|
+
File.unlink(@outfile) if File.file?(@outfile)
|
113
|
+
end
|
114
|
+
|
115
|
+
# this is to test for a bug where an exception was raised on files that
|
116
|
+
# had no declared encoding
|
117
|
+
specify "should remove all control chars except LF, CR and TAB" do
|
118
|
+
ONIX::Normaliser.process(@filename, @outfile)
|
119
|
+
|
120
|
+
File.file?(@outfile).should be_true
|
121
|
+
content = File.read(@outfile)
|
122
|
+
|
123
|
+
content.include?("<TitleText>OXFORDPICTURE DICTIONARY CHINESE</TitleText>").should be_true
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::OtherText" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "other_text.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
ot = ONIX::OtherText.from_xml(@root.to_s)
|
18
|
+
ot.to_xml.to_s[0,11].should eql("<OtherText>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
ot = ONIX::OtherText.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
ot.text_type_code.should eql(2)
|
25
|
+
ot.text[0,7].should eql("A woman")
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should provide write access to first level attibutes" do
|
29
|
+
ot = ONIX::OtherText.new
|
30
|
+
|
31
|
+
ot.text_type_code = 2
|
32
|
+
ot.to_xml.to_s.include?("<TextTypeCode>02</TextTypeCode>").should be_true
|
33
|
+
|
34
|
+
ot.text = "James Healy"
|
35
|
+
ot.to_xml.to_s.include?("<Text>James Healy</Text>").should be_true
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
data/spec/price_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::Price" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "price.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
p = ONIX::Price.from_xml(@root.to_s)
|
18
|
+
p.to_xml.to_s[0,7].should eql("<Price>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
p = ONIX::Price.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
p.price_type_code.should eql(2)
|
25
|
+
p.price_amount.should eql(BigDecimal.new("7.5"))
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should provide write access to first level attibutes" do
|
29
|
+
p = ONIX::Price.new
|
30
|
+
|
31
|
+
p.price_type_code = 1
|
32
|
+
p.to_xml.to_s.include?("<PriceTypeCode>01</PriceTypeCode>").should be_true
|
33
|
+
|
34
|
+
p.price_amount = BigDecimal.new("7.5")
|
35
|
+
p.to_xml.to_s.include?("<PriceAmount>7.5</PriceAmount>").should be_true
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::ProductIdentifier" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "product_identifier.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
id = ONIX::ProductIdentifier.from_xml(@root.to_s)
|
18
|
+
id.to_xml.to_s[0,19].should eql("<ProductIdentifier>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
id = ONIX::ProductIdentifier.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
id.product_id_type.should eql(2)
|
25
|
+
id.id_value.should eql("0858198363")
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should provide write access to first level attibutes" do
|
29
|
+
id = ONIX::ProductIdentifier.new
|
30
|
+
|
31
|
+
id.product_id_type = 2
|
32
|
+
id.to_xml.to_s.include?("<ProductIDType>02</ProductIDType>").should be_true
|
33
|
+
|
34
|
+
id.id_value = "James"
|
35
|
+
id.to_xml.to_s.include?("<IDValue>James</IDValue>").should be_true
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
context "ONIX::Product" do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
12
|
+
file1 = File.join(@data_path, "product.xml")
|
13
|
+
@doc = LibXML::XML::Document.file(file1)
|
14
|
+
@product_node = @doc.root
|
15
|
+
end
|
16
|
+
|
17
|
+
specify "should provide read access to first level attibutes" do
|
18
|
+
product = ONIX::Product.from_xml(@product_node.to_s)
|
19
|
+
|
20
|
+
product.record_reference.should eql("365-9780194351898")
|
21
|
+
product.notification_type.should eql(3)
|
22
|
+
product.product_form.should eql("BC")
|
23
|
+
product.edition_number.should eql(1)
|
24
|
+
product.number_of_pages.should eql(100)
|
25
|
+
product.bic_main_subject.should eql("EB")
|
26
|
+
product.publishing_status.should eql(4)
|
27
|
+
product.publication_date.should eql(Date.civil(1998,9,1))
|
28
|
+
product.year_first_published.should eql(1998)
|
29
|
+
|
30
|
+
# including ye olde, deprecated ones
|
31
|
+
product.height.should eql(100)
|
32
|
+
product.width.should eql(BigDecimal.new("200.5"))
|
33
|
+
product.weight.should eql(300)
|
34
|
+
product.thickness.should eql(300)
|
35
|
+
product.dimensions.should eql("100x200")
|
36
|
+
end
|
37
|
+
|
38
|
+
specify "should provide read access to product IDs" do
|
39
|
+
product = ONIX::Product.from_xml(@product_node.to_s)
|
40
|
+
product.product_identifiers.size.should eql(3)
|
41
|
+
end
|
42
|
+
|
43
|
+
specify "should provide read access to titles" do
|
44
|
+
product = ONIX::Product.from_xml(@product_node.to_s)
|
45
|
+
product.titles.size.should eql(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
specify "should provide read access to subjects" do
|
49
|
+
product = ONIX::Product.from_xml(@product_node.to_s)
|
50
|
+
product.subjects.size.should eql(1)
|
51
|
+
end
|
52
|
+
|
53
|
+
specify "should provide read access to measurements" do
|
54
|
+
product = ONIX::Product.from_xml(@product_node.to_s)
|
55
|
+
product.measurements.size.should eql(1)
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "should provide write access to first level attibutes" do
|
59
|
+
product = ONIX::Product.new
|
60
|
+
|
61
|
+
product.notification_type = 3
|
62
|
+
product.to_xml.to_s.include?("<NotificationType>03</NotificationType>").should be_true
|
63
|
+
|
64
|
+
product.record_reference = "365-9780194351898"
|
65
|
+
product.to_xml.to_s.include?("<RecordReference>365-9780194351898</RecordReference>").should be_true
|
66
|
+
|
67
|
+
product.product_form = "BC"
|
68
|
+
product.to_xml.to_s.include?("<ProductForm>BC</ProductForm>").should be_true
|
69
|
+
|
70
|
+
product.edition_number = 1
|
71
|
+
product.to_xml.to_s.include?("<EditionNumber>1</EditionNumber>").should be_true
|
72
|
+
|
73
|
+
product.number_of_pages = 100
|
74
|
+
product.to_xml.to_s.include?("<NumberOfPages>100</NumberOfPages>").should be_true
|
75
|
+
|
76
|
+
product.bic_main_subject = "EB"
|
77
|
+
product.to_xml.to_s.include?("<BICMainSubject>EB</BICMainSubject>").should be_true
|
78
|
+
|
79
|
+
product.publishing_status = 4
|
80
|
+
product.to_xml.to_s.include?("<PublishingStatus>04</PublishingStatus>").should be_true
|
81
|
+
|
82
|
+
product.publication_date = Date.civil(1998,9,1)
|
83
|
+
product.to_xml.to_s.include?("<PublicationDate>19980901</PublicationDate>").should be_true
|
84
|
+
|
85
|
+
product.year_first_published = 1998
|
86
|
+
product.to_xml.to_s.include?("<YearFirstPublished>1998</YearFirstPublished>").should be_true
|
87
|
+
end
|
88
|
+
|
89
|
+
specify "should correctly from_xml files that have an invalid publication date" do
|
90
|
+
file = File.join(@data_path, "product_invalid_pubdate.xml")
|
91
|
+
product = ONIX::Product.from_xml(File.read(file))
|
92
|
+
|
93
|
+
product.bic_main_subject.should eql("VXFC1")
|
94
|
+
product.publication_date.should be_nil
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::Publisher" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "publisher.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
pub = ONIX::Publisher.from_xml(@root.to_s)
|
18
|
+
pub.to_xml.to_s[0,11].should eql("<Publisher>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
pub = ONIX::Publisher.from_xml(@root.to_s)
|
23
|
+
pub.publishing_role.should eql(1)
|
24
|
+
pub.publisher_name.should eql("Desbooks Publishing")
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should provide write access to first level attibutes" do
|
28
|
+
pub = ONIX::Publisher.new
|
29
|
+
|
30
|
+
pub.publisher_name = "Paulist Press"
|
31
|
+
pub.to_xml.to_s.include?("<PublisherName>Paulist Press</PublisherName>").should be_true
|
32
|
+
|
33
|
+
pub.publishing_role = 2
|
34
|
+
pub.to_xml.to_s.include?("<PublishingRole>02</PublishingRole>").should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
data/spec/reader_spec.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::Reader" do
|
8
|
+
|
9
|
+
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")
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "should initialize with a filename" do
|
20
|
+
reader = ONIX::Reader.new(@file1)
|
21
|
+
reader.instance_variable_get("@reader").should be_a_kind_of(LibXML::XML::Reader)
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "should initialize with an IO object" do
|
25
|
+
File.open(@file1,"rb") do |f|
|
26
|
+
reader = ONIX::Reader.new(f)
|
27
|
+
reader.instance_variable_get("@reader").should be_a_kind_of(LibXML::XML::Reader)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# This is commented out as the code that I was using to read the ONIX version from the
|
32
|
+
# input was causing segfaults and other stability issues
|
33
|
+
specify "should provide access to various XML metadata from file"
|
34
|
+
#do
|
35
|
+
# reader = ONIX::Reader.new(@file1)
|
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
|
41
|
+
|
42
|
+
specify "should provide access to the header in an ONIX file" do
|
43
|
+
reader = ONIX::Reader.new(@file1)
|
44
|
+
reader.header.should be_a_kind_of(ONIX::Header)
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "should iterate over all product records in an ONIX file" do
|
48
|
+
reader = ONIX::Reader.new(@file1)
|
49
|
+
counter = 0
|
50
|
+
reader.each do |product|
|
51
|
+
product.should be_a_kind_of(ONIX::Product)
|
52
|
+
counter += 1
|
53
|
+
end
|
54
|
+
|
55
|
+
counter.should eql(1)
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "should iterate over all product records in an ONIX file" do
|
59
|
+
reader = ONIX::Reader.new(@file2)
|
60
|
+
products = []
|
61
|
+
reader.each do |product|
|
62
|
+
products << product
|
63
|
+
end
|
64
|
+
|
65
|
+
products.size.should eql(2)
|
66
|
+
products[0].record_reference.should eql("365-9780194351898")
|
67
|
+
products[1].record_reference.should eql("9780754672326")
|
68
|
+
end
|
69
|
+
|
70
|
+
# libxml can handle the 3 standard entities fine (& < and ^gt;) but
|
71
|
+
# barfs when it encounters others. In theory other entities are defined in the
|
72
|
+
# ONIX DTD, but I can't work out how to get libxml to recognise them
|
73
|
+
specify "should correctly parse a file that has an entity in it" do
|
74
|
+
reader = ONIX::Reader.new(@entity_file)
|
75
|
+
|
76
|
+
products = []
|
77
|
+
reader.each do |product|
|
78
|
+
products << product
|
79
|
+
end
|
80
|
+
|
81
|
+
products.size.should eql(1)
|
82
|
+
products.first.titles.size.should eql(1)
|
83
|
+
products.first.titles.first.title_text.should eql("High Noon\342\200\223in Nimbin")
|
84
|
+
products.first.record_reference.should eql("9780732287573")
|
85
|
+
end
|
86
|
+
|
87
|
+
# for some reason I'm getting segfaults when I read a file with more than 7 records
|
88
|
+
specify "should correctly parse a file with more than 7 records in in" do
|
89
|
+
reader = ONIX::Reader.new(@long_file)
|
90
|
+
counter = 0
|
91
|
+
reader.each do |product|
|
92
|
+
counter += 1
|
93
|
+
end
|
94
|
+
|
95
|
+
counter.should eql(346)
|
96
|
+
end
|
97
|
+
|
98
|
+
specify "should transparently convert a iso-8859-1 file to utf-8" do
|
99
|
+
reader = ONIX::Reader.new(@iso_8859_1_file)
|
100
|
+
product = nil
|
101
|
+
reader.each do |p|
|
102
|
+
product = p
|
103
|
+
end
|
104
|
+
|
105
|
+
# ROXML appears to munge the string encodings
|
106
|
+
if RUBY_VERSION >= "1.9"
|
107
|
+
utf8 = Encoding.find("utf-8")
|
108
|
+
product.contributors[0].person_name_inverted.encoding.should eql(utf8)
|
109
|
+
end
|
110
|
+
|
111
|
+
product.contributors[0].person_name_inverted.should eql("Küng, Hans")
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
specify "should transparently convert a utf-16 file to utf-8" do
|
116
|
+
reader = ONIX::Reader.new(@utf_16_file)
|
117
|
+
product = nil
|
118
|
+
reader.each do |p|
|
119
|
+
product = p
|
120
|
+
end
|
121
|
+
|
122
|
+
# ROXML appears to munge the string encodings
|
123
|
+
if RUBY_VERSION >= "1.9"
|
124
|
+
utf8 = Encoding.find("utf-8")
|
125
|
+
product.contributors[0].person_name_inverted.encoding.should eql(utf8)
|
126
|
+
end
|
127
|
+
|
128
|
+
product.contributors[0].person_name_inverted.should eql("Küng, Hans")
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::SalesRestriction" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "sales_restriction.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
sr = ONIX::SalesRestriction.from_xml(@root.to_s)
|
18
|
+
sr.to_xml.to_s[0,18].should eql("<SalesRestriction>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
sr = ONIX::SalesRestriction.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
sr.sales_restriction_type.should eql(0)
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should provide write access to first level attibutes" do
|
28
|
+
sr = ONIX::SalesRestriction.new
|
29
|
+
|
30
|
+
sr.sales_restriction_type = 1
|
31
|
+
sr.to_xml.to_s.include?("<SalesRestrictionType>01</SalesRestrictionType>").should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::SenderIdentifier" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "sender_identifier.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
id = ONIX::SenderIdentifier.from_xml(@root.to_s)
|
18
|
+
id.to_xml.to_s[0,18].should eql("<SenderIdentifier>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
id = ONIX::SenderIdentifier.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
id.sender_id_type.should eql(1)
|
25
|
+
id.id_value.should eql("123456")
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should provide write access to first level attibutes" do
|
29
|
+
id = ONIX::SenderIdentifier.new
|
30
|
+
|
31
|
+
id.sender_id_type = 1
|
32
|
+
id.to_xml.to_s.include?("<SenderIDType>01</SenderIDType>").should be_true
|
33
|
+
|
34
|
+
id.id_value = "54321"
|
35
|
+
id.to_xml.to_s.include?("<IDValue>54321</IDValue>").should be_true
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::SeriesIdentifier" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "series_identifier.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
series = ONIX::SeriesIdentifier.from_xml(@root.to_s)
|
18
|
+
series.to_xml.to_s[0,18].should eql("<SeriesIdentifier>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
series = ONIX::SeriesIdentifier.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
series.series_id_type.should eql(1)
|
25
|
+
series.id_value.should eql("10001")
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should provide write access to first level attibutes" do
|
29
|
+
series = ONIX::SeriesIdentifier.new
|
30
|
+
|
31
|
+
series.series_id_type = 9
|
32
|
+
series.to_xml.to_s.include?("<SeriesIDType>09</SeriesIDType>").should be_true
|
33
|
+
|
34
|
+
series.id_value = 999
|
35
|
+
series.to_xml.to_s.include?("<IDValue>999</IDValue>").should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/series_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::Series" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "series.xml")
|
12
|
+
@doc = LibXML::XML::Document.file(file1)
|
13
|
+
@root = @doc.root
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should correctly convert to a string" do
|
17
|
+
series = ONIX::Series.from_xml(@root.to_s)
|
18
|
+
series.to_xml.to_s[0,8].should eql("<Series>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
series = ONIX::Series.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
series.title_of_series.should eql("Citizens and Their Governments")
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should provide write access to first level attibutes" do
|
28
|
+
series = ONIX::Series.new
|
29
|
+
|
30
|
+
series.title_of_series = "Cool Science Careers"
|
31
|
+
series.to_xml.to_s.include?("<TitleOfSeries>Cool Science Careers</TitleOfSeries>").should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|