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.
Files changed (64) hide show
  1. data/CHANGELOG +31 -1
  2. data/README.markdown +24 -2
  3. data/lib/onix.rb +3 -16
  4. data/lib/onix/addressee_identifier.rb +0 -1
  5. data/lib/onix/apa_product.rb +19 -2
  6. data/lib/onix/audience_range.rb +6 -7
  7. data/lib/onix/contributor.rb +0 -1
  8. data/lib/onix/header.rb +0 -1
  9. data/lib/onix/imprint.rb +0 -1
  10. data/lib/onix/language.rb +0 -1
  11. data/lib/onix/lists/contributor_role.rb +99 -0
  12. data/lib/onix/market_representation.rb +0 -1
  13. data/lib/onix/measure.rb +0 -1
  14. data/lib/onix/media_file.rb +0 -1
  15. data/lib/onix/normaliser.rb +0 -77
  16. data/lib/onix/other_text.rb +0 -1
  17. data/lib/onix/price.rb +0 -1
  18. data/lib/onix/product.rb +3 -2
  19. data/lib/onix/product_identifier.rb +0 -1
  20. data/lib/onix/publisher.rb +0 -1
  21. data/lib/onix/reader.rb +39 -96
  22. data/lib/onix/sales_restriction.rb +0 -1
  23. data/lib/onix/sender_identifier.rb +0 -1
  24. data/lib/onix/series.rb +8 -8
  25. data/lib/onix/series_identifier.rb +0 -1
  26. data/lib/onix/set.rb +76 -0
  27. data/lib/onix/sl_product.rb +32 -45
  28. data/lib/onix/stock.rb +0 -1
  29. data/lib/onix/subject.rb +0 -1
  30. data/lib/onix/supply_detail.rb +0 -1
  31. data/lib/onix/title.rb +0 -1
  32. data/lib/onix/website.rb +0 -1
  33. data/lib/onix/writer.rb +1 -1
  34. data/spec/apa_product_spec.rb +44 -4
  35. data/spec/audience_range_spec.rb +5 -7
  36. data/spec/contributor_spec.rb +2 -4
  37. data/spec/header_spec.rb +2 -4
  38. data/spec/imprint_spec.rb +4 -6
  39. data/spec/language_spec.rb +5 -7
  40. data/spec/market_representation_spec.rb +2 -4
  41. data/spec/measure_spec.rb +2 -4
  42. data/spec/media_file_spec.rb +2 -4
  43. data/spec/normaliser_spec.rb +1 -78
  44. data/spec/other_text_spec.rb +2 -4
  45. data/spec/price_spec.rb +2 -4
  46. data/spec/product_identifier_spec.rb +2 -4
  47. data/spec/product_spec.rb +2 -5
  48. data/spec/publisher_spec.rb +2 -4
  49. data/spec/reader_spec.rb +15 -22
  50. data/spec/sales_restriction_spec.rb +2 -4
  51. data/spec/sender_identifier.rb +2 -4
  52. data/spec/series_identifier_spec.rb +5 -7
  53. data/spec/series_spec.rb +4 -6
  54. data/spec/set_spec.rb +32 -0
  55. data/spec/sl_product_spec.rb +76 -24
  56. data/spec/spec_helper.rb +8 -0
  57. data/spec/stock_spec.rb +2 -4
  58. data/spec/subject_spec.rb +2 -4
  59. data/spec/supply_detail_spec.rb +2 -4
  60. data/spec/title_spec.rb +2 -4
  61. data/spec/website_spec.rb +2 -4
  62. data/spec/writer_spec.rb +1 -4
  63. metadata +64 -28
  64. data/lib/onix/common.rb +0 -26
data/lib/onix/stock.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  module ONIX
4
4
  class Stock
5
5
  include ROXML
6
- include ONIX::Common
7
6
 
8
7
  xml_name "Stock"
9
8
 
data/lib/onix/subject.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  module ONIX
4
4
  class Subject
5
5
  include ROXML
6
- include ONIX::Common
7
6
 
8
7
  xml_name "Subject"
9
8
 
@@ -3,7 +3,6 @@
3
3
  module ONIX
4
4
  class SupplyDetail
5
5
  include ROXML
6
- include ONIX::Common
7
6
 
8
7
  xml_name "SupplyDetail"
9
8
 
data/lib/onix/title.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  module ONIX
4
4
  class Title
5
5
  include ROXML
6
- include ONIX::Common
7
6
 
8
7
  xml_name "Title"
9
8
 
data/lib/onix/website.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  module ONIX
4
4
  class Website
5
5
  include ROXML
6
- include ONIX::Common
7
6
 
8
7
  xml_name "Website"
9
8
 
data/lib/onix/writer.rb CHANGED
@@ -77,7 +77,7 @@ module ONIX
77
77
  def start_document
78
78
  @output.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
79
79
  @output.write("<!DOCTYPE ONIXMessage SYSTEM \"#{DOCTYPE}\">\n")
80
- @output.write("<ONIXMessage>\n")
80
+ @output.write("<ONIXMessage release=\"2.1\">\n")
81
81
  @output.write(@header.to_xml.to_s)
82
82
  @output.write("\n")
83
83
  end
@@ -1,8 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
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 = LibXML::XML::Document.file(file1)
11
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
14
12
  @product_node = @doc.root
15
13
  end
16
14
 
@@ -57,3 +55,45 @@ context "ONIX::APAProduct" do
57
55
  end
58
56
 
59
57
  end
58
+
59
+ context ONIX::APAProduct, "series method" do
60
+ specify "should set the nested series value on the underlying product class" do
61
+ apa = ONIX::APAProduct.new
62
+
63
+ apa.series = "Harry Potter"
64
+ apa.series.should eql("Harry Potter")
65
+ apa.to_xml.to_s.include?("<TitleOfSeries>Harry Potter</TitleOfSeries>").should be_true
66
+ end
67
+ end
68
+
69
+ context ONIX::APAProduct, "price method" do
70
+ before(:each) do
71
+ @data_path = File.join(File.dirname(__FILE__),"..","data")
72
+ file1 = File.join(@data_path, "usd.xml")
73
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
74
+ @product_node = @doc.root
75
+ end
76
+
77
+ specify "should return the first price in the file, regardless of type" do
78
+ @product = ONIX::Product.from_xml(@product_node.to_s)
79
+ @apa = ONIX::APAProduct.new(@product)
80
+
81
+ @apa.price.should eql(BigDecimal.new("99.95"))
82
+ end
83
+ end
84
+
85
+ context ONIX::APAProduct, "rrp_exc_sales_tax method" do
86
+ before(:each) do
87
+ @data_path = File.join(File.dirname(__FILE__),"..","data")
88
+ file1 = File.join(@data_path, "usd.xml")
89
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
90
+ @product_node = @doc.root
91
+ end
92
+
93
+ specify "should return the first price in the file of type 1" do
94
+ @product = ONIX::Product.from_xml(@product_node.to_s)
95
+ @apa = ONIX::APAProduct.new(@product)
96
+
97
+ @apa.rrp_exc_sales_tax.should eql(BigDecimal.new("99.95"))
98
+ end
99
+ end
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::AudienceRange" 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, "audience_range.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @root = @doc.root
14
12
  end
15
13
 
@@ -20,7 +18,7 @@ context "ONIX::AudienceRange" do
20
18
 
21
19
  specify "should provide read access to first level attibutes" do
22
20
  aud = ONIX::AudienceRange.from_xml(@root.to_s)
23
-
21
+
24
22
  aud.audience_range_qualifier.should eql(11)
25
23
  aud.audience_range_precisions.size.should eql(2)
26
24
  aud.audience_range_precisions[0].should eql(3)
@@ -32,13 +30,13 @@ context "ONIX::AudienceRange" do
32
30
 
33
31
  specify "should provide write access to first level attibutes" do
34
32
  aud = ONIX::AudienceRange.new
35
-
33
+
36
34
  aud.audience_range_qualifier = 12
37
35
  aud.to_xml.to_s.include?("<AudienceRangeQualifier>12</AudienceRangeQualifier>").should be_true
38
36
 
39
37
  aud.audience_range_precisions[0] = 888
40
38
  aud.to_xml.to_s.include?("<AudienceRangePrecision>888</AudienceRangePrecision>").should be_true
41
-
39
+
42
40
  aud.audience_range_values[0] = 999
43
41
  aud.to_xml.to_s.include?("<AudienceRangeValue>999</AudienceRangeValue>").should be_true
44
42
  end
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::Contributor" 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, "contributor.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @root = @doc.root
14
12
  end
15
13
 
data/spec/header_spec.rb CHANGED
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::Header" 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, "header.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @header_node = @doc.root
14
12
  end
15
13
 
data/spec/imprint_spec.rb CHANGED
@@ -1,16 +1,14 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::Imprint" do
8
6
 
9
7
  before(:each) do
10
8
  data_path = File.join(File.dirname(__FILE__),"..","data")
11
- file1 = File.join(data_path, "imprint.xml")
12
- @doc = LibXML::XML::Document.file(file1)
13
- @root = @doc.root
9
+ file1 = File.join(data_path, "imprint.xml")
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
11
+ @root = @doc.root
14
12
  end
15
13
 
16
14
  specify "should correctly convert to a string" do
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::Language" 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, "language.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @root = @doc.root
14
12
  end
15
13
 
@@ -20,7 +18,7 @@ context "ONIX::Language" do
20
18
 
21
19
  specify "should provide read access to first level attibutes" do
22
20
  lan = ONIX::Language.from_xml(@root.to_s)
23
-
21
+
24
22
  lan.language_role.should eql(1)
25
23
  lan.language_code.should eql("eng")
26
24
  lan.country_code.should eql("US")
@@ -28,13 +26,13 @@ context "ONIX::Language" do
28
26
 
29
27
  specify "should provide write access to first level attibutes" do
30
28
  lan = ONIX::Language.new
31
-
29
+
32
30
  lan.language_role = 2
33
31
  lan.to_xml.to_s.include?("<LanguageRole>02</LanguageRole>").should be_true
34
32
 
35
33
  lan.language_code = "aar"
36
34
  lan.to_xml.to_s.include?("<LanguageCode>aar</LanguageCode>").should be_true
37
-
35
+
38
36
  lan.country_code = "AD"
39
37
  lan.to_xml.to_s.include?("<CountryCode>AD</CountryCode>").should be_true
40
38
  end
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::MarketRepresentation" 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, "market_representation.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @root = @doc.root
14
12
  end
15
13
 
data/spec/measure_spec.rb CHANGED
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::Measure" 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, "measure.xml")
12
- @doc = LibXML::XML::Document.file(file1)
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
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::MediaFile" 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, "media_file.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @root = @doc.root
14
12
  end
15
13
 
@@ -1,8 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::Normaliser", "with a simple short tag file" do
8
6
 
@@ -27,79 +25,6 @@ context "ONIX::Normaliser", "with a simple short tag file" do
27
25
 
28
26
  end
29
27
 
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?("&ndash;").should be_false
75
- content.include?("&#x02013;").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
28
  context "ONIX::Normaliser", "with a utf8 file that has illegal control chars" do
104
29
 
105
30
  before(:each) do
@@ -112,8 +37,6 @@ context "ONIX::Normaliser", "with a utf8 file that has illegal control chars" do
112
37
  File.unlink(@outfile) if File.file?(@outfile)
113
38
  end
114
39
 
115
- # this is to test for a bug where an exception was raised on files that
116
- # had no declared encoding
117
40
  specify "should remove all control chars except LF, CR and TAB" do
118
41
  ONIX::Normaliser.process(@filename, @outfile)
119
42
 
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::OtherText" 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, "other_text.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @root = @doc.root
14
12
  end
15
13
 
data/spec/price_spec.rb CHANGED
@@ -1,15 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'onix'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
6
4
 
7
5
  context "ONIX::Price" 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, "price.xml")
12
- @doc = LibXML::XML::Document.file(file1)
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
13
11
  @root = @doc.root
14
12
  end
15
13