milkfarm-onix 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ v0.8.9 (24 March 2011)
2
+ - Add RelatedProduct composite (PR.23.7 - PR.23.33)
3
+ - Create ProductIdentifiers module
4
+ - Create ListWriter module
5
+ - WARNING: Set methods product_identifier, product_identifier_set removed
6
+
1
7
  v0.8.8 (15 March 2011)
2
8
  - Format EpubType value as 3-digit, padded number
3
9
 
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+ module ListWriter
5
+
6
+ def list_writer(name, options = {})
7
+ options.symbolize_keys!
8
+ unless options.is_a?(Hash) && options[:list].is_a?(Integer)
9
+ raise ArgumentError, "Must specify code list number as ':list => Integer'"
10
+ end
11
+ define_method("#{name}=") do |value|
12
+ if value.nil? || ONIX::Lists.list(options[:list]).keys.include?(value)
13
+ self.instance_variable_set("@#{name}", value)
14
+ else
15
+ raise ArgumentError, "Invalid #{("_" + name.to_s).downcase.gsub!(/_(.)/) { $1.upcase }} '#{value}' -- Refer to ONIX Code List #{options[:list]}"
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
data/lib/onix/product.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  module ONIX
4
4
  class Product
5
5
  include ROXML
6
+ extend ONIX::ListWriter
6
7
 
7
8
  xml_name "Product"
8
9
 
@@ -12,6 +13,7 @@ module ONIX
12
13
  xml_accessor :product_form, :from => "ProductForm"
13
14
  xml_accessor :product_form_detail, :from => "ProductFormDetail"
14
15
  xml_reader :epub_type, :from => "EpubType", :as => Fixnum, :to_xml => ONIX::Formatters.three_digit
16
+ list_writer :epub_type, :list => 10
15
17
  xml_accessor :series, :from => "Series", :as => [ONIX::Series]
16
18
  xml_accessor :sets, :from => "Set", :as => [ONIX::Set]
17
19
  xml_accessor :titles, :from => "Title", :as => [ONIX::Title]
@@ -42,6 +44,7 @@ module ONIX
42
44
  xml_accessor :year_first_published, :from => "YearFirstPublished", :as => Fixnum
43
45
  xml_accessor :sales_restrictions, :from => "SalesRestriction", :as => [ONIX::SalesRestriction]
44
46
  xml_accessor :measurements, :from => "Measure", :as => [ONIX::Measure]
47
+ xml_accessor :related_products, :from => "RelatedProduct", :as => [ONIX::RelatedProduct]
45
48
  xml_accessor :supply_details, :from => "SupplyDetail", :as => [ONIX::SupplyDetail]
46
49
  xml_accessor :market_representations, :from => "MarketRepresentation", :as => [ONIX::MarketRepresentation]
47
50
 
@@ -71,19 +74,10 @@ module ONIX
71
74
  self.publishers = []
72
75
  self.sales_restrictions = []
73
76
  self.measurements = []
77
+ self.related_products = []
74
78
  self.supply_details = []
75
79
  self.market_representations = []
76
80
  end
77
81
 
78
- # TODO: Refactor writer methods using method_missing
79
- def epub_type=(new_epub_type)
80
- if new_epub_type.nil? || ONIX::Lists.list(10).keys.include?(new_epub_type)
81
- # ProductForm code must equal DG if EpubType element is present
82
- @product_form = "DG"
83
- @epub_type = new_epub_type
84
- else
85
- raise "Invalid EpubType #{new_epub_type}"
86
- end
87
- end
88
82
  end
89
83
  end
@@ -0,0 +1,63 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+ module ProductIdentifiers
5
+ ACCESSOR_METHODS = {:proprietary_id => 1, :ean => 3, :isbn10 => 2, :isbn13 => 15, :isbn => 15, :lccn => 13}
6
+
7
+ def initialize_product_identifiers(options)
8
+ @product_identifiers ||= []
9
+ ACCESSOR_METHODS.keys.push(:product_identifiers).each do |name|
10
+ self.send("#{name}=", options[name]) if options[name]
11
+ end
12
+ end
13
+
14
+ ACCESSOR_METHODS.each do |name, digit|
15
+ define_method(name) do
16
+ identifier(digit).andand.id_value
17
+ end
18
+ define_method("#{name}=") do |value|
19
+ identifier_set(digit, value)
20
+ end
21
+ end
22
+
23
+ def product_identifiers
24
+ @product_identifiers ||= []
25
+ end
26
+
27
+ private
28
+
29
+ def product_identifiers=(values)
30
+ values = [values] if values.nil? || values.is_a?(ONIX::ProductIdentifier)
31
+ if values.is_a?(Array)
32
+ # Empty array
33
+ @product_identifiers = []
34
+ # Add any valid value
35
+ values.each do |value|
36
+ @product_identifiers << value if value.is_a?(ONIX::ProductIdentifier)
37
+ end
38
+ else
39
+ raise ArgumentError, "Invalid ProductIdentifier value: #{values.inspect}"
40
+ end
41
+ end
42
+
43
+ # find the ProductIdentifier matching a particular type
44
+ def identifier(type)
45
+ @product_identifiers.find { |obj| obj.product_id_type == type }
46
+ end
47
+
48
+ # set the value of a particular ProductIdentifier (found by type)
49
+ def identifier_set(type, value)
50
+ obj = identifier(type)
51
+
52
+ # create a new product identifier object if we necessary
53
+ if obj.nil?
54
+ obj = ONIX::ProductIdentifier.new
55
+ obj.product_id_type = type
56
+ @product_identifiers << obj
57
+ end
58
+
59
+ obj.id_value = value
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ module ONIX
4
+ class RelatedProduct
5
+ include ROXML
6
+ include ONIX::ProductIdentifiers
7
+ extend ONIX::ListWriter
8
+
9
+ xml_name "RelatedProduct"
10
+
11
+ xml_reader :relation_code, :from => "RelationCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
12
+ xml_reader :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
13
+ list_writer :relation_code, :list => 51
14
+
15
+ def initialize(options = {})
16
+ options.symbolize_keys!
17
+ self.relation_code = options[:relation_code]
18
+ self.initialize_product_identifiers(options) # Must be called to setup @product_identifiers array
19
+ end
20
+
21
+ end
22
+ end
data/lib/onix/set.rb CHANGED
@@ -3,74 +3,26 @@
3
3
  module ONIX
4
4
  class Set
5
5
  include ROXML
6
+ include ONIX::ProductIdentifiers
6
7
 
7
8
  xml_name "Set"
8
9
 
9
- xml_accessor :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
10
+ xml_reader :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
10
11
  xml_accessor :title_of_set, :from => "TitleOfSet"
11
12
 
12
- def initialize
13
- self.product_identifiers = []
13
+ def initialize(options = {})
14
+ options.symbolize_keys!
15
+ self.initialize_product_identifiers(options) # Must be called to setup @product_identifiers array
14
16
  end
15
17
 
16
- # retrieve the proprietary set ID
17
- def proprietary_set_id
18
- product_identifier(1).andand.id_value
19
- end
20
-
21
- # set a new proprietary set ID
22
- def proprietary_set_id=(id)
23
- product_identifier_set(1, id)
24
- end
18
+ # Following methods removed os of gem 0.8.9 (aliased for backwards compatible):
19
+ alias_method :proprietary_set_id, :proprietary_id
20
+ alias_method :proprietary_set_id=, :proprietary_id=
25
21
 
26
- # retrieve the 10-digit isbn
27
- def isbn10
28
- product_identifier(2).andand.id_value
29
- end
30
-
31
- # set a new 10-digit isbn
32
- def isbn10=(id)
33
- product_identifier_set(2, id)
34
- end
22
+ # Following methods removed os of gem 0.8.9 (NOT backwards compatible):
23
+ # original method -> replacement method
24
+ # product_identifier(type) -> see product_identifiers.rb (eg, use isbn, lccn...)
25
+ # product_identifier_set(type, value) -> see product_identifiers.rb (eg, use isbn=, lccn=...)
35
26
 
36
- # retrieve the 13-digit isbn
37
- def isbn
38
- product_identifier(15).andand.id_value
39
- end
40
-
41
- # set a new 13-digit isbn
42
- def isbn=(id)
43
- product_identifier_set(15, id)
44
- end
45
-
46
- # retrieve the lccn
47
- def lccn
48
- product_identifier(13).andand.id_value
49
- end
50
-
51
- # set a new lccn
52
- def lccn=(id)
53
- product_identifier_set(13, id)
54
- end
55
-
56
- # retrieve the value of a particular ID
57
- def product_identifier(type)
58
- identifier = product_identifiers.find { |id| id.product_id_type == type }
59
- end
60
-
61
- # set the value of a particular ID
62
- def product_identifier_set(type, value)
63
- product_identifier_id = product_identifiers.find { |id| id.product_id_type == type }
64
-
65
- # create a new set identifier record if we need to
66
- if product_identifier_id.nil?
67
- product_identifier_id = ONIX::ProductIdentifier.new
68
- end
69
-
70
- product_identifier_id.product_id_type = type
71
- product_identifier_id.id_value = value
72
-
73
- product_identifiers << product_identifier_id
74
- end
75
27
  end
76
28
  end
@@ -8,6 +8,7 @@ module ONIX
8
8
  delegate :product_form_detail, :product_form_detail=
9
9
  delegate :basic_main_subject, :basic_main_subject=
10
10
  delegate :epub_type, :epub_type=
11
+ delegate :related_products, :related_products=
11
12
 
12
13
  # retrieve the value of a particular ID
13
14
  def series(str)
@@ -63,14 +64,28 @@ module ONIX
63
64
  # process based on value type
64
65
  if value.is_a?(WorkIdentifier)
65
66
  str = value.id_value
66
- work_identifier_obj = value
67
+ obj = value
67
68
  else
68
69
  str = value
69
- work_identifier_obj = ONIX::WorkIdentifier.new(:work_id_type => type, :id_value => value)
70
+ obj = ONIX::WorkIdentifier.new(:work_id_type => type, :id_value => value)
70
71
  end
71
72
  # check if exists already
72
73
  unless work_identifier(str)
73
- product.work_identifiers << work_identifier_obj
74
+ product.work_identifiers << obj
75
+ end
76
+ end
77
+
78
+ # find the related_product that has relation_code 5
79
+ def replacement
80
+ product.related_products.find { |obj| obj.relation_code == 5 }
81
+ end
82
+
83
+ # set the proprietary_id of the replacement product
84
+ def replacement=(value)
85
+ if obj = replacement
86
+ obj.proprietary_id = value
87
+ else
88
+ product.related_products << ONIX::RelatedProduct.new(:relation_code => 5, :proprietary_id => value)
74
89
  end
75
90
  end
76
91
 
data/lib/onix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ONIX
2
- VERSION = "0.8.8"
2
+ VERSION = "0.8.9"
3
3
  end
@@ -3,12 +3,14 @@
3
3
  module ONIX
4
4
  class WorkIdentifier
5
5
  include ROXML
6
+ extend ONIX::ListWriter
6
7
 
7
8
  xml_name "WorkIdentifier"
8
9
 
9
10
  xml_reader :work_id_type, :from => "WorkIDType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
10
11
  xml_accessor :id_type_name, :from => "IDTypeName"
11
12
  xml_accessor :id_value, :from => "IDValue"
13
+ list_writer :work_id_type, :list => 16
12
14
 
13
15
  def initialize(options = {})
14
16
  options.symbolize_keys!
@@ -17,12 +19,5 @@ module ONIX
17
19
  @id_value = options[:id_value]
18
20
  end
19
21
 
20
- def work_id_type=(new_work_id_type)
21
- if new_work_id_type.nil? || ::ONIX::Lists.list(16).keys.include?(new_work_id_type)
22
- @work_id_type = new_work_id_type
23
- else
24
- raise "Invalid WorkIDType #{new_work_id_type}"
25
- end
26
- end
27
22
  end
28
23
  end
data/lib/onix.rb CHANGED
@@ -55,9 +55,11 @@ end
55
55
  # core files
56
56
  # - ordering is important, classes need to be defined before any
57
57
  # other class can use them
58
+ require File.join(File.dirname(__FILE__), "onix", "list_writer")
58
59
  require File.join(File.dirname(__FILE__), "onix", "sender_identifier")
59
60
  require File.join(File.dirname(__FILE__), "onix", "addressee_identifier")
60
61
  require File.join(File.dirname(__FILE__), "onix", "header")
62
+ require File.join(File.dirname(__FILE__), "onix", "product_identifiers")
61
63
  require File.join(File.dirname(__FILE__), "onix", "product_identifier")
62
64
  require File.join(File.dirname(__FILE__), "onix", "series_identifier")
63
65
  require File.join(File.dirname(__FILE__), "onix", "series")
@@ -76,6 +78,7 @@ require File.join(File.dirname(__FILE__), "onix", "media_file")
76
78
  require File.join(File.dirname(__FILE__), "onix", "sales_restriction")
77
79
  require File.join(File.dirname(__FILE__), "onix", "stock")
78
80
  require File.join(File.dirname(__FILE__), "onix", "price")
81
+ require File.join(File.dirname(__FILE__), "onix", "related_product")
79
82
  require File.join(File.dirname(__FILE__), "onix", "supply_detail")
80
83
  require File.join(File.dirname(__FILE__), "onix", "market_representation")
81
84
  require File.join(File.dirname(__FILE__), "onix", "measure")
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
+
5
+ describe ONIX::ListWriter do
6
+
7
+ module ONIX
8
+ class FakeEntity
9
+ include ROXML
10
+ extend ONIX::ListWriter
11
+
12
+ xml_name "FakeEntity"
13
+ xml_reader :series_id_type, :from => "SeriesIDType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
14
+ list_writer :series_id_type, :list => 13
15
+
16
+ def initialize(options = {})
17
+ self.series_id_type = options[:series_id_type]
18
+ end
19
+ end
20
+ end
21
+
22
+ before :each do
23
+ data_path = File.join(File.dirname(__FILE__),"..","data")
24
+ file1 = File.join(data_path, "fake_entity_for_lists.xml")
25
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
26
+ @root = @doc.root
27
+ end
28
+
29
+ it "should provide read access to first level attribute" do
30
+ fake = ONIX::FakeEntity.from_xml(@root.to_s)
31
+ fake.series_id_type.should eql(1)
32
+ end
33
+
34
+ it "should provide write access to first level attribute" do
35
+ fake = ONIX::FakeEntity.new(:series_id_type => 3)
36
+ fake.series_id_type.should eql(3)
37
+ fake.to_xml.to_s.include?("<SeriesIDType>03</SeriesIDType>").should be_true
38
+ end
39
+
40
+ it "should raise error writing value not in list" do
41
+ fake = ONIX::FakeEntity.new
42
+ lambda {fake.series_id_type = 100}.should raise_error
43
+ lambda {ONIX::FakeEntity.new(:series_id_type => 100)}.should raise_error
44
+ end
45
+
46
+ end
@@ -0,0 +1,71 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
+
5
+ describe ONIX::ProductIdentifiers do
6
+
7
+ module ONIX
8
+ class FakeEntity
9
+ include ROXML
10
+ include ONIX::ProductIdentifiers
11
+
12
+ xml_name "FakeEntity"
13
+ xml_reader :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
14
+
15
+ def initialize(options = {})
16
+ self.initialize_product_identifiers(options)
17
+ end
18
+ end
19
+ end
20
+
21
+ before :each do
22
+ @fake = ONIX::FakeEntity.new(:isbn => 123456)
23
+ data_path = File.join(File.dirname(__FILE__),"..","data")
24
+ file1 = File.join(data_path, "fake_entity.xml")
25
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
26
+ @root = @doc.root
27
+ end
28
+
29
+ it "should instantiate product identifiers array" do
30
+ @fake.product_identifiers.should be_a(Array)
31
+ end
32
+
33
+ it "should provide read access to product identifiers" do
34
+ fe = ONIX::FakeEntity.from_xml(@root.to_s)
35
+ fe.proprietary_id.should eql("PROPRIETARY_ID")
36
+ fe.isbn10.should eql("ISBN10")
37
+ fe.isbn.should eql("ISBN13")
38
+ fe.isbn13.should eql("ISBN13")
39
+ fe.ean.should eql("EAN")
40
+ fe.lccn.should eql("LCCN")
41
+ end
42
+
43
+ it "should provide write access to product identifiers" do
44
+ id_value = "123456"
45
+ {:proprietary_id => 1, :ean => 3, :isbn10 => 2, :isbn13 => 15, :isbn => 15, :lccn => 13}.each do |key, product_id_type|
46
+ fe = ONIX::FakeEntity.new(key => id_value)
47
+ fe.to_xml.to_s.include?("<ProductIDType>#{sprintf('%02d', product_id_type)}</ProductIDType>").should be_true
48
+ fe.to_xml.to_s.include?("<IDValue>#{id_value}</IDValue>").should be_true
49
+ end
50
+ end
51
+
52
+ it "should provide write access to product_identifiers array" do
53
+ id = ONIX::ProductIdentifier.new
54
+ id.product_id_type = 1
55
+ id.id_value = "123456"
56
+ fe = ONIX::FakeEntity.new(:product_identifiers => id)
57
+
58
+ fe.to_xml.to_s.include?("<ProductIdentifier>").should be_true
59
+ fe.to_xml.to_s.include?("<ProductIDType>01</ProductIDType>").should be_true
60
+ fe.to_xml.to_s.include?("<IDValue>123456</IDValue>").should be_true
61
+
62
+ id = ONIX::ProductIdentifier.new
63
+ id.product_id_type = 2
64
+ id.id_value = "987654"
65
+ fe.product_identifiers << id
66
+
67
+ fe.to_xml.to_s.include?("<ProductIDType>02</ProductIDType>").should be_true
68
+ fe.to_xml.to_s.include?("<IDValue>987654</IDValue>").should be_true
69
+ end
70
+
71
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
+
5
+ describe ONIX::RelatedProduct do
6
+
7
+ before(:each) do
8
+ data_path = File.join(File.dirname(__FILE__),"..","data")
9
+ file1 = File.join(data_path, "related_product.xml")
10
+ @doc = Nokogiri::XML::Document.parse(File.read(file1))
11
+ @root = @doc.root
12
+ end
13
+
14
+ it "should correctly convert to a string" do
15
+ rp = ONIX::RelatedProduct.from_xml(@root.to_s)
16
+ rp.to_xml.to_s[0,16].should eql("<RelatedProduct>")
17
+ end
18
+
19
+ it "should provide read access to relation_code" do
20
+ rp = ONIX::RelatedProduct.from_xml(@root.to_s)
21
+ rp.relation_code.should eql(5)
22
+ end
23
+
24
+ it "should provide write access to relation_code" do
25
+ rp = ONIX::RelatedProduct.new(:relation_code => 1)
26
+ rp.to_xml.to_s.include?("<RelationCode>01</RelationCode>").should be_true
27
+
28
+ rp.relation_code = 2
29
+ rp.to_xml.to_s.include?("<RelationCode>02</RelationCode>").should be_true
30
+ end
31
+
32
+ # This is essentially testing product_identifers.rb module
33
+ it "should provide read access to proprietary_id" do
34
+ rp = ONIX::RelatedProduct.from_xml(@root.to_s)
35
+ rp.proprietary_id.should eql("123456")
36
+ end
37
+
38
+ # This is essentially testing product_identifers.rb module
39
+ it "should provide write access to proprietary_id" do
40
+ rp = ONIX::RelatedProduct.new(:proprietary_id => 123456)
41
+ rp.to_xml.to_s.include?("<ProductIDType>01</ProductIDType>").should be_true
42
+ rp.to_xml.to_s.include?("<IDValue>123456</IDValue>").should be_true
43
+ end
44
+
45
+ end
data/spec/set_spec.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/spec_helper.rb'
4
4
 
5
- context "ONIX::Set" do
5
+ describe ONIX::Set do
6
6
 
7
7
  before(:each) do
8
8
  data_path = File.join(File.dirname(__FILE__),"..","data")
@@ -11,18 +11,18 @@ context "ONIX::Set" do
11
11
  @root = @doc.root
12
12
  end
13
13
 
14
- specify "should correctly convert to a string" do
14
+ it "should correctly convert to a string" do
15
15
  set = ONIX::Set.from_xml(@root.to_s)
16
16
  set.to_xml.to_s[0,5].should eql("<Set>")
17
17
  end
18
18
 
19
- specify "should provide read access to first level attributes" do
19
+ it "should provide read access to first level attributes" do
20
20
  set = ONIX::Set.from_xml(@root.to_s)
21
21
 
22
22
  set.title_of_set.should eql("Citizens and Their Governments")
23
23
  end
24
24
 
25
- specify "should provide write access to first level attributes" do
25
+ it "should provide write access to first level attributes" do
26
26
  set = ONIX::Set.new
27
27
 
28
28
  set.title_of_set = "Cool Science Careers"
@@ -3,43 +3,45 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper.rb'
4
4
  require 'date'
5
5
 
6
- context "ONIX::SLProduct" do
6
+ describe ONIX::SLProduct do
7
7
 
8
8
  before(:each) do
9
9
  @data_path = File.join(File.dirname(__FILE__),"..","data")
10
- file1 = File.join(@data_path, "product.xml")
10
+ file1 = File.join(@data_path, "sl_product.xml")
11
11
  @doc = Nokogiri::XML::Document.parse(File.read(file1))
12
12
  @product_node = @doc.root
13
13
  end
14
14
 
15
- specify "should provide read access to attributes" do
16
- @product = ONIX::Product.from_xml(@product_node.to_s)
17
- @sl = ONIX::SLProduct.new(@product)
15
+ it "should provide read access to attributes" do
16
+ @product = ONIX::Product.from_xml(@product_node.to_s)
17
+ @sl = ONIX::SLProduct.new(@product)
18
18
 
19
- @sl.record_reference.should eql("365-9780194351898")
19
+ @sl.record_reference.should eql("200002")
20
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")
21
+ @sl.product_form.should eql("BB")
22
+ @sl.number_of_pages.should eql(32)
23
+ @sl.basic_main_subject.should eql("JNF053090")
24
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)
25
+ @sl.publication_date.should eql(Date.civil(2007,8,1))
26
+ @sl.related_products.should be_a(Array)
27
+ @sl.related_products[0].should be_a(ONIX::RelatedProduct)
28
+ @sl.related_products[0].relation_code.should eql(5)
27
29
  end
28
30
 
29
- specify "should provide write access to attributes" do
31
+ it "should provide write access to attributes" do
30
32
  sl = ONIX::SLProduct.new
31
33
 
32
34
  sl.notification_type = 3
33
35
  sl.to_xml.to_s.include?("<NotificationType>03</NotificationType>").should be_true
34
36
 
35
- sl.record_reference = "365-9780194351898"
36
- sl.to_xml.to_s.include?("<RecordReference>365-9780194351898</RecordReference>").should be_true
37
+ sl.record_reference = "200002"
38
+ sl.to_xml.to_s.include?("<RecordReference>200002</RecordReference>").should be_true
37
39
 
38
- sl.product_form = "BC"
39
- sl.to_xml.to_s.include?("<ProductForm>BC</ProductForm>").should be_true
40
+ sl.product_form = "BB"
41
+ sl.to_xml.to_s.include?("<ProductForm>BB</ProductForm>").should be_true
40
42
 
41
- sl.number_of_pages = 100
42
- sl.to_xml.to_s.include?("<NumberOfPages>100</NumberOfPages>").should be_true
43
+ sl.number_of_pages = 32
44
+ sl.to_xml.to_s.include?("<NumberOfPages>32</NumberOfPages>").should be_true
43
45
 
44
46
  sl.basic_main_subject = "JNF053090"
45
47
  sl.to_xml.to_s.include?("<BASICMainSubject>JNF053090</BASICMainSubject>").should be_true
@@ -47,17 +49,50 @@ context "ONIX::SLProduct" do
47
49
  sl.publishing_status = 4
48
50
  sl.to_xml.to_s.include?("<PublishingStatus>04</PublishingStatus>").should be_true
49
51
 
50
- sl.publication_date = Date.civil(1998,9,1)
51
- sl.to_xml.to_s.include?("<PublicationDate>19980901</PublicationDate>").should be_true
52
+ sl.publication_date = Date.civil(2007,8,1)
53
+ sl.to_xml.to_s.include?("<PublicationDate>20070801</PublicationDate>").should be_true
54
+
55
+ id = ONIX::ProductIdentifier.new
56
+ id.product_id_type = 1
57
+ id.id_value = "123456"
58
+ sl.related_products = [ONIX::RelatedProduct.new(:relation_code => 1, :product_identifiers => id)]
59
+ sl.related_products << ONIX::RelatedProduct.new(:relation_code => 2, :product_identifiers => id)
60
+ sl.related_products[0].to_xml.to_s.include?("<RelationCode>01</RelationCode>").should be_true
61
+ sl.related_products[1].to_xml.to_s.include?("<RelationCode>02</RelationCode>").should be_true
62
+ end
63
+
64
+ it "should provide read access to replacement" do
65
+ @product = ONIX::Product.from_xml(@product_node.to_s)
66
+ @sl = ONIX::SLProduct.new(@product)
52
67
 
53
- sl.pack_quantity = 12
54
- sl.to_xml.to_s.include?("<PackQuantity>12</PackQuantity>").should be_true
68
+ @sl.replacement.relation_code.should eql(5)
69
+ @sl.replacement.proprietary_id.should eql("123456")
70
+ end
71
+
72
+ it "should provide write access to replacement" do
73
+ sl = ONIX::SLProduct.new
74
+
75
+ sl.replacement = "XYZ123"
76
+ sl.related_products[0].to_xml.to_s.include?("<RelationCode>05</RelationCode>").should be_true
77
+ sl.related_products[0].to_xml.to_s.include?("<ProductIDType>01</ProductIDType>").should be_true
78
+ sl.related_products[0].to_xml.to_s.include?("<IDValue>XYZ123</IDValue>").should be_true
79
+ end
80
+
81
+ it "should provide write access to epub_type" do
82
+ sl = ONIX::SLProduct.new
83
+ sl.epub_type = 1
84
+ sl.to_xml.to_s.include?("<EpubType>001</EpubType>").should be_true
85
+ end
86
+
87
+ it "should raise error when writing invalid epub_type" do
88
+ sl = ONIX::SLProduct.new
89
+ lambda {sl.epub_type = 999}.should raise_error
55
90
  end
56
91
 
57
92
  end
58
93
 
59
- context ONIX::SLProduct, "series method" do
60
- specify "should set the nested series value on the underlying product class" do
94
+ describe ONIX::SLProduct, "series method" do
95
+ it "should set the nested series value on the underlying product class" do
61
96
  sl = ONIX::SLProduct.new
62
97
 
63
98
  sl.series = "Harry Potter"
@@ -67,7 +102,7 @@ context ONIX::SLProduct, "series method" do
67
102
  end
68
103
  end
69
104
 
70
- context ONIX::SLProduct, "price method" do
105
+ describe ONIX::SLProduct, "price method" do
71
106
  before(:each) do
72
107
  @data_path = File.join(File.dirname(__FILE__),"..","data")
73
108
  file1 = File.join(@data_path, "usd.xml")
@@ -75,7 +110,7 @@ context ONIX::SLProduct, "price method" do
75
110
  @product_node = @doc.root
76
111
  end
77
112
 
78
- specify "should return the first price in the file, regardless of type" do
113
+ it "should return the first price in the file, regardless of type" do
79
114
  @product = ONIX::Product.from_xml(@product_node.to_s)
80
115
  @sl = ONIX::SLProduct.new(@product)
81
116
 
@@ -83,7 +118,7 @@ context ONIX::SLProduct, "price method" do
83
118
  end
84
119
  end
85
120
 
86
- context ONIX::SLProduct, "rrp_exc_sales_tax method" do
121
+ describe ONIX::SLProduct, "rrp_exc_sales_tax method" do
87
122
  before(:each) do
88
123
  @data_path = File.join(File.dirname(__FILE__),"..","data")
89
124
  file1 = File.join(@data_path, "usd.xml")
@@ -91,7 +126,7 @@ context ONIX::SLProduct, "rrp_exc_sales_tax method" do
91
126
  @product_node = @doc.root
92
127
  end
93
128
 
94
- specify "should return the first price in the file of type 1" do
129
+ it "should return the first price in the file of type 1" do
95
130
  @product = ONIX::Product.from_xml(@product_node.to_s)
96
131
  @sl = ONIX::SLProduct.new(@product)
97
132
 
@@ -35,5 +35,11 @@ describe ONIX::WorkIdentifier do
35
35
  t.id_value = "ABC123"
36
36
  t.to_xml.to_s.include?("<IDValue>ABC123</IDValue>").should be_true
37
37
  end
38
+
39
+ it "should raise error writing work_id_type value not in list" do
40
+ t = ONIX::WorkIdentifier.new
41
+ lambda {t.work_id_type = 999}.should raise_error
42
+ lambda {ONIX::WorkIdentifier.new(:work_id_type => 999)}.should raise_error
43
+ end
38
44
 
39
45
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milkfarm-onix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 47
4
+ hash: 45
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 8
10
- version: 0.8.8
9
+ - 9
10
+ version: 0.8.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Healy
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-15 00:00:00 -07:00
19
+ date: 2011-03-24 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -126,6 +126,7 @@ files:
126
126
  - lib/onix/header.rb
127
127
  - lib/onix/imprint.rb
128
128
  - lib/onix/language.rb
129
+ - lib/onix/list_writer.rb
129
130
  - lib/onix/lists.rb
130
131
  - lib/onix/market_representation.rb
131
132
  - lib/onix/measure.rb
@@ -135,8 +136,10 @@ files:
135
136
  - lib/onix/price.rb
136
137
  - lib/onix/product.rb
137
138
  - lib/onix/product_identifier.rb
139
+ - lib/onix/product_identifiers.rb
138
140
  - lib/onix/publisher.rb
139
141
  - lib/onix/reader.rb
142
+ - lib/onix/related_product.rb
140
143
  - lib/onix/sales_restriction.rb
141
144
  - lib/onix/sender_identifier.rb
142
145
  - lib/onix/series.rb
@@ -335,6 +338,7 @@ files:
335
338
  - spec/header_spec.rb
336
339
  - spec/imprint_spec.rb
337
340
  - spec/language_spec.rb
341
+ - spec/list_writer_spec.rb
338
342
  - spec/lists_spec.rb
339
343
  - spec/market_representation_spec.rb
340
344
  - spec/measure_spec.rb
@@ -343,9 +347,11 @@ files:
343
347
  - spec/other_text_spec.rb
344
348
  - spec/price_spec.rb
345
349
  - spec/product_identifier_spec.rb
350
+ - spec/product_identifiers_spec.rb
346
351
  - spec/product_spec.rb
347
352
  - spec/publisher_spec.rb
348
353
  - spec/reader_spec.rb
354
+ - spec/related_product_spec.rb
349
355
  - spec/sales_restriction_spec.rb
350
356
  - spec/sender_identifier.rb
351
357
  - spec/series_identifier_spec.rb
@@ -403,6 +409,7 @@ test_files:
403
409
  - spec/header_spec.rb
404
410
  - spec/imprint_spec.rb
405
411
  - spec/language_spec.rb
412
+ - spec/list_writer_spec.rb
406
413
  - spec/lists_spec.rb
407
414
  - spec/market_representation_spec.rb
408
415
  - spec/measure_spec.rb
@@ -411,9 +418,11 @@ test_files:
411
418
  - spec/other_text_spec.rb
412
419
  - spec/price_spec.rb
413
420
  - spec/product_identifier_spec.rb
421
+ - spec/product_identifiers_spec.rb
414
422
  - spec/product_spec.rb
415
423
  - spec/publisher_spec.rb
416
424
  - spec/reader_spec.rb
425
+ - spec/related_product_spec.rb
417
426
  - spec/sales_restriction_spec.rb
418
427
  - spec/sender_identifier.rb
419
428
  - spec/series_identifier_spec.rb