milkfarm-onix 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/CHANGELOG +136 -0
  2. data/README.markdown +40 -0
  3. data/TODO +14 -0
  4. data/dtd/2.1r3/iso-amsa.ent +173 -0
  5. data/dtd/2.1r3/iso-amsb.ent +146 -0
  6. data/dtd/2.1r3/iso-amsc.ent +49 -0
  7. data/dtd/2.1r3/iso-amsn.ent +117 -0
  8. data/dtd/2.1r3/iso-amso.ent +77 -0
  9. data/dtd/2.1r3/iso-amsr.ent +205 -0
  10. data/dtd/2.1r3/iso-box.ent +67 -0
  11. data/dtd/2.1r3/iso-cyr1.ent +94 -0
  12. data/dtd/2.1r3/iso-cyr2.ent +53 -0
  13. data/dtd/2.1r3/iso-dia.ent +41 -0
  14. data/dtd/2.1r3/iso-grk3.ent +70 -0
  15. data/dtd/2.1r3/iso-lat1.ent +89 -0
  16. data/dtd/2.1r3/iso-lat2.ent +148 -0
  17. data/dtd/2.1r3/iso-mfrk.ent +79 -0
  18. data/dtd/2.1r3/iso-mopf.ent +53 -0
  19. data/dtd/2.1r3/iso-mscr.ent +79 -0
  20. data/dtd/2.1r3/iso-num.ent +103 -0
  21. data/dtd/2.1r3/iso-num.old.ent +103 -0
  22. data/dtd/2.1r3/iso-pub.ent +110 -0
  23. data/dtd/2.1r3/iso-tech.ent +183 -0
  24. data/dtd/2.1r3/onix-international.dtd +1012 -0
  25. data/dtd/2.1r3/onix-xhtml.elt +672 -0
  26. data/dtd/2.1r3/reference.elt +4758 -0
  27. data/dtd/2.1r3/xhtml-special.ent +79 -0
  28. data/dtd/2.1r3/xhtml-symbol.ent +242 -0
  29. data/lib/onix/addressee_identifier.rb +12 -0
  30. data/lib/onix/apa_product.rb +731 -0
  31. data/lib/onix/audience_range.rb +26 -0
  32. data/lib/onix/common.rb +26 -0
  33. data/lib/onix/contributor.rb +27 -0
  34. data/lib/onix/header.rb +46 -0
  35. data/lib/onix/imprint.rb +15 -0
  36. data/lib/onix/language.rb +14 -0
  37. data/lib/onix/lists/audience_code.rb +17 -0
  38. data/lib/onix/lists/country_code.rb +257 -0
  39. data/lib/onix/lists/language_code.rb +498 -0
  40. data/lib/onix/lists/language_role.rb +18 -0
  41. data/lib/onix/lists/notification_type.rb +19 -0
  42. data/lib/onix/lists/product_availability.rb +32 -0
  43. data/lib/onix/lists/product_form.rb +99 -0
  44. data/lib/onix/lists/product_form_detail.rb +157 -0
  45. data/lib/onix/market_representation.rb +19 -0
  46. data/lib/onix/measure.rb +14 -0
  47. data/lib/onix/media_file.rb +16 -0
  48. data/lib/onix/normaliser.rb +187 -0
  49. data/lib/onix/other_text.rb +17 -0
  50. data/lib/onix/price.rb +21 -0
  51. data/lib/onix/product.rb +73 -0
  52. data/lib/onix/product_identifier.rb +13 -0
  53. data/lib/onix/publisher.rb +16 -0
  54. data/lib/onix/reader.rb +187 -0
  55. data/lib/onix/sales_restriction.rb +12 -0
  56. data/lib/onix/sender_identifier.rb +14 -0
  57. data/lib/onix/series.rb +57 -0
  58. data/lib/onix/series_identifier.rb +13 -0
  59. data/lib/onix/simple_product.rb +47 -0
  60. data/lib/onix/sl_product.rb +131 -0
  61. data/lib/onix/stock.rb +15 -0
  62. data/lib/onix/subject.rb +16 -0
  63. data/lib/onix/supply_detail.rb +32 -0
  64. data/lib/onix/title.rb +17 -0
  65. data/lib/onix/website.rb +14 -0
  66. data/lib/onix/writer.rb +86 -0
  67. data/lib/onix.rb +114 -0
  68. data/spec/apa_product_spec.rb +59 -0
  69. data/spec/audience_range_spec.rb +46 -0
  70. data/spec/contributor_spec.rb +42 -0
  71. data/spec/header_spec.rb +123 -0
  72. data/spec/imprint_spec.rb +39 -0
  73. data/spec/language_spec.rb +42 -0
  74. data/spec/market_representation_spec.rb +41 -0
  75. data/spec/measure_spec.rb +43 -0
  76. data/spec/media_file_spec.rb +42 -0
  77. data/spec/normaliser_spec.rb +125 -0
  78. data/spec/other_text_spec.rb +40 -0
  79. data/spec/price_spec.rb +40 -0
  80. data/spec/product_identifier_spec.rb +40 -0
  81. data/spec/product_spec.rb +96 -0
  82. data/spec/publisher_spec.rb +38 -0
  83. data/spec/reader_spec.rb +131 -0
  84. data/spec/sales_restriction_spec.rb +35 -0
  85. data/spec/sender_identifier.rb +40 -0
  86. data/spec/series_identifier_spec.rb +38 -0
  87. data/spec/series_spec.rb +34 -0
  88. data/spec/sl_product_spec.rb +48 -0
  89. data/spec/stock_spec.rb +44 -0
  90. data/spec/subject_spec.rb +40 -0
  91. data/spec/supply_detail_spec.rb +53 -0
  92. data/spec/title_spec.rb +43 -0
  93. data/spec/website_spec.rb +41 -0
  94. data/spec/writer_spec.rb +81 -0
  95. data/support/entities.txt +1499 -0
  96. data/support/extract.rb +25 -0
  97. data/support/switch-onix-2.1-short-to-reference.xsl +23 -0
  98. data/support/switch-onix-tagnames-1.1.xsl +25 -0
  99. data/support/switch-onix-tagnames-2.0.xsl +37 -0
  100. metadata +209 -0
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+ require 'date'
7
+
8
+ context "ONIX::SLProduct" do
9
+
10
+ before(:each) do
11
+ @data_path = File.join(File.dirname(__FILE__),"..","data")
12
+ file1 = File.join(@data_path, "sl_product.xml")
13
+ @doc = LibXML::XML::Document.file(file1)
14
+ @product_node = @doc.root
15
+ end
16
+
17
+ specify "should provide read access to attibrutes" do
18
+ @product = ONIX::Product.from_xml(@product_node.to_s)
19
+ @sl = ONIX::SLProduct.new(@product)
20
+
21
+ @sl.record_reference.should eql("10001")
22
+ @sl.notification_type.should eql(2)
23
+ @sl.number_of_pages.should eql(32)
24
+ @sl.publishing_status.should eql(2)
25
+ @sl.publication_date.should eql(Date.civil(2009,12,1))
26
+ @sl.copyright_year.should eql(2008)
27
+ end
28
+
29
+ specify "should provide write access to attibutes" do
30
+ apa = ONIX::SLProduct.new
31
+
32
+ apa.notification_type = 3
33
+ apa.to_xml.to_s.include?("<NotificationType>03</NotificationType>").should be_true
34
+
35
+ apa.record_reference = "999"
36
+ apa.to_xml.to_s.include?("<RecordReference>999</RecordReference>").should be_true
37
+
38
+ apa.number_of_pages = 100
39
+ apa.to_xml.to_s.include?("<NumberOfPages>100</NumberOfPages>").should be_true
40
+
41
+ apa.publishing_status = 4
42
+ apa.to_xml.to_s.include?("<PublishingStatus>04</PublishingStatus>").should be_true
43
+
44
+ apa.publication_date = Date.civil(1998,9,1)
45
+ apa.to_xml.to_s.include?("<PublicationDate>19980901</PublicationDate>").should be_true
46
+ end
47
+
48
+ end
@@ -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,53 @@
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.pack_quantity.should eql(16)
29
+ sd.prices.should be_a_kind_of(Array)
30
+ sd.prices.size.should eql(1)
31
+ end
32
+
33
+ specify "should provide write access to first level attibutes" do
34
+ sd = ONIX::SupplyDetail.new
35
+
36
+ sd.supplier_name = "RBA"
37
+ sd.to_xml.to_s.include?("<SupplierName>RBA</SupplierName>").should be_true
38
+
39
+ sd.supplier_role = 1
40
+ sd.to_xml.to_s.include?("<SupplierRole>01</SupplierRole>").should be_true
41
+
42
+ sd.availability_status_code = 2
43
+ sd.to_xml.to_s.include?("<AvailabilityStatusCode>02</AvailabilityStatusCode>").should be_true
44
+
45
+ sd.product_availability = 3
46
+ sd.to_xml.to_s.include?("<ProductAvailability>03</ProductAvailability>").should be_true
47
+
48
+ sd.pack_quantity = 12
49
+ sd.to_xml.to_s.include?("<PackQuantity>12</PackQuantity>").should be_true
50
+ end
51
+
52
+ end
53
+
@@ -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
+
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+
7
+ context "ONIX::Website" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "website.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
+ web = ONIX::Website.from_xml(@root.to_s)
18
+ web.to_xml.to_s[0,9].should eql("<Website>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ web = ONIX::Website.from_xml(@root.to_s)
23
+
24
+ web.website_role.should eql(1)
25
+ web.website_link.should eql("http://www.rainbowbooks.com.au")
26
+ end
27
+
28
+ specify "should provide write access to first level attibutes" do
29
+ web = ONIX::Website.new
30
+
31
+ web.website_role = 2
32
+ web.to_xml.to_s.include?("<WebsiteRole>02</WebsiteRole>").should be_true
33
+
34
+ web.website_link = "http://www.yob.id.au"
35
+ web.to_xml.to_s.include?("<WebsiteLink>http://www.yob.id.au</WebsiteLink>").should be_true
36
+
37
+ end
38
+
39
+ end
40
+
41
+
@@ -0,0 +1,81 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+ require 'stringio'
7
+
8
+ context "ONIX::Writer" do
9
+
10
+ before(:each) do
11
+ @output = StringIO.new
12
+ end
13
+
14
+ specify "should output the correct xml metadata" do
15
+ header = ONIX::Header.new
16
+ writer = ONIX::Writer.new(@output, header)
17
+ writer.end_document
18
+
19
+ lines = @output.string.split("\n")
20
+
21
+ # xml declaration
22
+ lines[0][0,5].should eql("<?xml")
23
+
24
+ # doctype
25
+ lines[1][0,9].should eql("<!DOCTYPE")
26
+ end
27
+
28
+ specify "should output the correct xml metadata when used in block form" do
29
+ header = ONIX::Header.new
30
+ ONIX::Writer.open(@output, header) { |writer| }
31
+
32
+ lines = @output.string.split("\n")
33
+
34
+ # xml declaration
35
+ lines[0][0,5].should eql("<?xml")
36
+
37
+ # doctype
38
+ lines[1][0,9].should eql("<!DOCTYPE")
39
+ end
40
+
41
+ specify "should output the header node" do
42
+ header = ONIX::Header.new
43
+
44
+ ONIX::Writer.open(@output, header) { |writer| }
45
+
46
+ lines = @output.string.split("\n")
47
+
48
+ lines[3][0,7].should eql("<Header")
49
+ end
50
+
51
+ specify "should output the product node" do
52
+ header = ONIX::Header.new
53
+ product = ONIX::Product.new
54
+
55
+ ONIX::Writer.open(@output, header) do |writer|
56
+ writer << product
57
+ end
58
+
59
+ lines = @output.string.split("\n")
60
+
61
+ lines[4][0,8].should eql("<Product")
62
+ end
63
+
64
+ specify "should correctly store finished state" do
65
+ header = ONIX::Header.new
66
+ writer = ONIX::Writer.new(@output, header)
67
+ writer.finished?.should be_false
68
+ writer.end_document
69
+ writer.finished?.should be_true
70
+ end
71
+
72
+ =begin
73
+ specify "should convert non-ASCII chars to references when outputting as a string" do
74
+ header = ONIX::Header.new
75
+ header.from_person = "Hans Küng"
76
+ ONIX::Writer.open(@output, header) { |writer| }
77
+
78
+ @output.string.include?("K&#252;ng").should be_true
79
+ end
80
+ =end
81
+ end