onix 0.4.7 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/CHANGELOG +5 -0
  2. data/lib/onix.rb +51 -17
  3. data/lib/onix/addressee_identifier.rb +1 -1
  4. data/lib/onix/contributor.rb +16 -14
  5. data/lib/onix/header.rb +24 -18
  6. data/lib/onix/imprint.rb +6 -4
  7. data/lib/onix/market_representation.rb +9 -7
  8. data/lib/onix/measure.rb +5 -3
  9. data/lib/onix/media_file.rb +5 -3
  10. data/lib/onix/other_text.rb +8 -6
  11. data/lib/onix/price.rb +8 -6
  12. data/lib/onix/product.rb +39 -24
  13. data/lib/onix/product_identifier.rb +3 -1
  14. data/lib/onix/publisher.rb +7 -5
  15. data/lib/onix/reader.rb +51 -8
  16. data/lib/onix/sales_restriction.rb +3 -1
  17. data/lib/onix/sender_identifier.rb +3 -1
  18. data/lib/onix/simple_product.rb +4 -0
  19. data/lib/onix/stock.rb +2 -0
  20. data/lib/onix/subject.rb +7 -5
  21. data/lib/onix/supply_detail.rb +13 -6
  22. data/lib/onix/title.rb +5 -3
  23. data/lib/onix/website.rb +5 -3
  24. data/spec/contributor_spec.rb +42 -0
  25. data/spec/header_spec.rb +19 -18
  26. data/spec/imprint_spec.rb +39 -0
  27. data/spec/market_representation_spec.rb +41 -0
  28. data/spec/measure_spec.rb +43 -0
  29. data/spec/media_file_spec.rb +42 -0
  30. data/spec/other_text_spec.rb +40 -0
  31. data/spec/price_spec.rb +40 -0
  32. data/spec/product_identifier_spec.rb +40 -0
  33. data/spec/product_spec.rb +17 -16
  34. data/spec/publisher_spec.rb +38 -0
  35. data/spec/sales_restriction_spec.rb +35 -0
  36. data/spec/sender_identifier.rb +40 -0
  37. data/spec/stock_spec.rb +44 -0
  38. data/spec/subject_spec.rb +40 -0
  39. data/spec/supply_detail_spec.rb +50 -0
  40. data/spec/title_spec.rb +43 -0
  41. data/spec/website_spec.rb +41 -0
  42. metadata +25 -14
  43. data/lib/onix/date_type.rb +0 -54
  44. data/lib/onix/decimal_type.rb +0 -49
  45. data/lib/onix/etext_type.rb +0 -44
  46. data/lib/onix/integer_type.rb +0 -43
  47. data/lib/onix/two_digit_type.rb +0 -57
@@ -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
+
@@ -15,7 +15,7 @@ context "ONIX::Product" do
15
15
  end
16
16
 
17
17
  specify "should provide read access to first level attibutes" do
18
- product = ONIX::Product.parse(@product_node.to_s)
18
+ product = ONIX::Product.from_xml(@product_node.to_s)
19
19
 
20
20
  product.record_reference.should eql("365-9780194351898")
21
21
  product.notification_type.should eql(3)
@@ -36,22 +36,22 @@ context "ONIX::Product" do
36
36
  end
37
37
 
38
38
  specify "should provide read access to product IDs" do
39
- product = ONIX::Product.parse(@product_node.to_s)
39
+ product = ONIX::Product.from_xml(@product_node.to_s)
40
40
  product.product_identifiers.size.should eql(3)
41
41
  end
42
42
 
43
43
  specify "should provide read access to titles" do
44
- product = ONIX::Product.parse(@product_node.to_s)
44
+ product = ONIX::Product.from_xml(@product_node.to_s)
45
45
  product.titles.size.should eql(1)
46
46
  end
47
47
 
48
48
  specify "should provide read access to subjects" do
49
- product = ONIX::Product.parse(@product_node.to_s)
49
+ product = ONIX::Product.from_xml(@product_node.to_s)
50
50
  product.subjects.size.should eql(1)
51
51
  end
52
52
 
53
53
  specify "should provide read access to measurements" do
54
- product = ONIX::Product.parse(@product_node.to_s)
54
+ product = ONIX::Product.from_xml(@product_node.to_s)
55
55
  product.measurements.size.should eql(1)
56
56
  end
57
57
 
@@ -59,37 +59,38 @@ context "ONIX::Product" do
59
59
  product = ONIX::Product.new
60
60
 
61
61
  product.notification_type = 3
62
- product.notification_type.should eql(3)
62
+ product.to_xml.to_s.include?("<NotificationType>03</NotificationType>").should be_true
63
+
63
64
  product.record_reference = "365-9780194351898"
64
- product.record_reference.should eql("365-9780194351898")
65
+ product.to_xml.to_s.include?("<RecordReference>365-9780194351898</RecordReference>").should be_true
65
66
 
66
67
  product.product_form = "BC"
67
- product.product_form.should eql("BC")
68
+ product.to_xml.to_s.include?("<ProductForm>BC</ProductForm>").should be_true
68
69
 
69
70
  product.edition_number = 1
70
- product.edition_number.should eql(1)
71
+ product.to_xml.to_s.include?("<EditionNumber>1</EditionNumber>").should be_true
71
72
 
72
73
  product.number_of_pages = 100
73
- product.number_of_pages.should eql(100)
74
+ product.to_xml.to_s.include?("<NumberOfPages>100</NumberOfPages>").should be_true
74
75
 
75
76
  product.bic_main_subject = "EB"
76
- product.bic_main_subject.should eql("EB")
77
+ product.to_xml.to_s.include?("<BICMainSubject>EB</BICMainSubject>").should be_true
77
78
 
78
79
  product.publishing_status = 4
79
- product.publishing_status.should eql(4)
80
+ product.to_xml.to_s.include?("<PublishingStatus>04</PublishingStatus>").should be_true
80
81
 
81
82
  product.publication_date = Date.civil(1998,9,1)
82
- product.publication_date.should eql(Date.civil(1998,9,1))
83
+ product.to_xml.to_s.include?("<PublicationDate>19980901</PublicationDate>").should be_true
83
84
 
84
85
  product.year_first_published = 1998
85
- product.year_first_published.should eql(1998)
86
+ product.to_xml.to_s.include?("<YearFirstPublished>1998</YearFirstPublished>").should be_true
86
87
  end
87
88
 
88
- specify "should correctly parse files that have non-standard entties"
89
+ specify "should correctly from_xml files that have non-standard entties"
89
90
  =begin
90
91
  do
91
92
  file = File.join(@data_path, "extra_entities.xml")
92
- product = ONIX::Product.parse(File.read(file))
93
+ product = ONIX::Product.from_xml(File.read(file))
93
94
 
94
95
  product.titles.first.title_text.should eql("Ipod® & Itunes® for Dummies®, 4th Edition")
95
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
+
@@ -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,44 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+
7
+ context "ONIX::Stock" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "stock.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
+ s = ONIX::Stock.from_xml(@root.to_s)
18
+ s.to_xml.to_s[0,7].should eql("<Stock>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ s = ONIX::Stock.from_xml(@root.to_s)
23
+
24
+ # note that these fields *should* be numeric according to the ONIX spec,
25
+ # however heaps of ONIX files in the wild have strings there.
26
+ s.on_hand.should eql("2862")
27
+ s.on_order.should eql("0")
28
+ end
29
+
30
+ specify "should provide write access to first level attibutes" do
31
+ s = ONIX::Stock.new
32
+
33
+ s.on_hand = "123"
34
+ s.to_xml.to_s.include?("<OnHand>123</OnHand>").should be_true
35
+
36
+ s.on_order = "011"
37
+ s.to_xml.to_s.include?("<OnOrder>011</OnOrder>").should be_true
38
+
39
+ s.on_order = 11
40
+ s.to_xml.to_s.include?("<OnOrder>11</OnOrder>").should be_true
41
+ end
42
+
43
+ end
44
+
@@ -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::Subject" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "subject.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
+ sub = ONIX::Subject.from_xml(@root.to_s)
18
+ sub.to_xml.to_s[0,9].should eql("<Subject>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ sub = ONIX::Subject.from_xml(@root.to_s)
23
+ sub.subject_scheme_id.should eql(3)
24
+ sub.subject_scheme_name.should eql("RBA Subjects")
25
+ sub.subject_code.should eql("AABB")
26
+ end
27
+
28
+ specify "should provide write access to first level attibutes" do
29
+ sub = ONIX::Subject.new
30
+
31
+ sub.subject_scheme_id = 2
32
+ sub.to_xml.to_s.include?("<SubjectSchemeIdentifier>02</SubjectSchemeIdentifier>").should be_true
33
+
34
+ sub.subject_code = "ABCD"
35
+ sub.to_xml.to_s.include?("<SubjectCode>ABCD</SubjectCode>").should be_true
36
+
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,50 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+
7
+ context "ONIX::SupplyDetail" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "supply_detail.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
+ sd = ONIX::SupplyDetail.from_xml(@root.to_s)
18
+ sd.to_xml.to_s[0,14].should eql("<SupplyDetail>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ sd = ONIX::SupplyDetail.from_xml(@root.to_s)
23
+
24
+ sd.supplier_name.should eql("Rainbow Book Agencies")
25
+ sd.product_availability.should eql(21)
26
+ sd.stock.should be_a_kind_of(Array)
27
+ sd.stock.size.should eql(1)
28
+ sd.prices.should be_a_kind_of(Array)
29
+ sd.prices.size.should eql(1)
30
+ end
31
+
32
+ specify "should provide write access to first level attibutes" do
33
+ sd = ONIX::SupplyDetail.new
34
+
35
+ sd.supplier_name = "RBA"
36
+ sd.to_xml.to_s.include?("<SupplierName>RBA</SupplierName>").should be_true
37
+
38
+ sd.supplier_role = 1
39
+ sd.to_xml.to_s.include?("<SupplierRole>01</SupplierRole>").should be_true
40
+
41
+ sd.availability_status_code = 2
42
+ sd.to_xml.to_s.include?("<AvailabilityStatusCode>02</AvailabilityStatusCode>").should be_true
43
+
44
+ sd.product_availability = 3
45
+ sd.to_xml.to_s.include?("<ProductAvailability>03</ProductAvailability>").should be_true
46
+
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+
7
+ context "ONIX::Title" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "title.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
+ t = ONIX::Title.from_xml(@root.to_s)
18
+ t.to_xml.to_s[0,7].should eql("<Title>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ t = ONIX::Title.from_xml(@root.to_s)
23
+ t.title_type.should eql(1)
24
+ t.title_text.should eql("Good Grief")
25
+ t.subtitle.should eql("A Constructive Approach to the Problem of Loss")
26
+ end
27
+
28
+ specify "should provide write access to first level attibutes" do
29
+ t = ONIX::Title.new
30
+
31
+ t.title_type = 1
32
+ t.to_xml.to_s.include?("<TitleType>01</TitleType>").should be_true
33
+
34
+ t.title_text = "Good Grief"
35
+ t.to_xml.to_s.include?("<TitleText>Good Grief</TitleText>").should be_true
36
+
37
+ t.subtitle = "Blah"
38
+ t.to_xml.to_s.include?("<Subtitle>Blah</Subtitle>").should be_true
39
+
40
+ end
41
+
42
+ end
43
+