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
@@ -2,6 +2,8 @@ module ONIX
2
2
  class SalesRestriction
3
3
  include ROXML
4
4
 
5
- xml_accessor :sales_restriction_type, :twodigit, :from =>"SalesRestrictionType"
5
+ xml_name "SalesRestriction"
6
+
7
+ xml_accessor :sales_restriction_type, :from =>"SalesRestrictionType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
6
8
  end
7
9
  end
@@ -2,7 +2,9 @@ module ONIX
2
2
  class SenderIdentifier
3
3
  include ROXML
4
4
 
5
- xml_accessor :sender_id_type, :from => "SenderIDType"
5
+ xml_name "SenderIdentifier"
6
+
7
+ xml_accessor :sender_id_type, :from => "SenderIDType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
6
8
  xml_accessor :id_type_name, :from => "IDTypeName"
7
9
  xml_accessor :id_value, :from => "IDValue"
8
10
  end
@@ -12,6 +12,10 @@ module ONIX
12
12
 
13
13
  include Forwardable
14
14
 
15
+ def from_xml(xml)
16
+ self.new(::ONIX::Product.from_xml(xml))
17
+ end
18
+
15
19
  def parse_file(filename)
16
20
  self.new(::ONIX::Product.parse(File.read(filename)))
17
21
  end
@@ -2,6 +2,8 @@ module ONIX
2
2
  class Stock
3
3
  include ROXML
4
4
 
5
+ xml_name "Stock"
6
+
5
7
  # NOTE: these *should* be numeric fields according to the spec,
6
8
  # but heaps of ONIX files in the wild use text
7
9
  xml_accessor :on_hand, :from => "OnHand"
@@ -2,10 +2,12 @@ module ONIX
2
2
  class Subject
3
3
  include ROXML
4
4
 
5
- xml_accessor :subject_scheme_id, :twodigit, :from => "SubjectSchemeIdentifier"
6
- xml_accessor :subject_scheme_name, :from => "SubjectSchemeName"
7
- xml_accessor :subject_scheme_version, :from => "SubjectSchemeVersion"
8
- xml_accessor :subject_code, :from => "SubjectCode"
9
- xml_accessor :subject_heading_text, :from => "SubjectHeadingText"
5
+ xml_name "Subject"
6
+
7
+ xml_accessor :subject_scheme_id, :from => "SubjectSchemeIdentifier", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :subject_scheme_name, :from => "SubjectSchemeName"
9
+ xml_accessor :subject_scheme_version, :from => "SubjectSchemeVersion"
10
+ xml_accessor :subject_code, :from => "SubjectCode"
11
+ xml_accessor :subject_heading_text, :from => "SubjectHeadingText"
10
12
  end
11
13
  end
@@ -2,20 +2,27 @@ module ONIX
2
2
  class SupplyDetail
3
3
  include ROXML
4
4
 
5
+ xml_name "SupplyDetail"
6
+
5
7
  xml_accessor :supplier_ean_location_number, :from => "SupplierEANLocationNumber"
6
8
  xml_accessor :supplier_san, :from => "SupplierSAN"
7
9
  xml_accessor :supplier_name, :from => "SupplierName"
8
10
  xml_accessor :telephone_number, :from => "TelephoneNumber"
9
11
  xml_accessor :fax_number, :from => "FaxNumber"
10
12
  xml_accessor :email_address, :from => "EmailAddress"
11
- xml_accessor :websites, [ONIX::Website], :from => "Website"
12
- xml_accessor :supplier_role, :twodigit, :from => "SupplierRole"
13
+ xml_accessor :websites, :from => "Website", :as => [ONIX::Website]
14
+ xml_accessor :supplier_role, :from => "SupplierRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
13
15
  xml_accessor :supply_to_country, :from => "SupplyToCountry"
14
16
  xml_accessor :supply_to_territory, :from => "SupplyToTerritory"
15
- xml_accessor :availability_status_code, :twodigit, :from => "AvailabilityStatusCode"
16
- xml_accessor :product_availability, :twodigit, :from => "ProductAvailability"
17
- xml_accessor :stock, [ONIX::Stock], :from => "Stock"
18
- xml_accessor :prices, [ONIX::Price], :from => "Price"
17
+ xml_accessor :availability_status_code, :from => "AvailabilityStatusCode", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
18
+ xml_accessor :product_availability, :from => "ProductAvailability", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
19
+ xml_accessor :stock, :from => "Stock", :as => [ONIX::Stock]
20
+ xml_accessor :prices, :from => "Price", :as => [ONIX::Price]
19
21
 
22
+ def initialize
23
+ self.websites = []
24
+ self.stock = []
25
+ self.prices = []
26
+ end
20
27
  end
21
28
  end
@@ -2,9 +2,11 @@ module ONIX
2
2
  class Title
3
3
  include ROXML
4
4
 
5
- xml_accessor :title_type, :twodigit, :from => "TitleType"
6
- xml_accessor :title_text, :etext, :from => "TitleText"
7
- xml_accessor :subtitle, :etext, :from => "Subtitle"
5
+ xml_name "Title"
6
+
7
+ xml_accessor :title_type, :from => "TitleType", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :title_text, :from => "TitleText"
9
+ xml_accessor :subtitle, :from => "Subtitle"
8
10
 
9
11
  end
10
12
  end
@@ -2,8 +2,10 @@ module ONIX
2
2
  class Website
3
3
  include ROXML
4
4
 
5
- xml_accessor :website_role, :twodigit, :from => "WebsiteRole"
6
- xml_accessor :website_description, :from => "WebsiteDescription"
7
- xml_accessor :website_link, :from => "WebsiteLink"
5
+ xml_name "Website"
6
+
7
+ xml_accessor :website_role, :from => "WebsiteRole", :as => Fixnum, :to_xml => ONIX::Formatters.two_digit
8
+ xml_accessor :website_description, :from => "WebsiteDescription"
9
+ xml_accessor :website_link, :from => "WebsiteLink"
8
10
  end
9
11
  end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+
7
+ context "ONIX::Contributor" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "contributor.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
+ header = ONIX::Contributor.from_xml(@root.to_s)
18
+ header.to_xml.to_s[0,13].should eql("<Contributor>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ contrib = ONIX::Contributor.from_xml(@root.to_s)
23
+
24
+ contrib.contributor_role.should eql("A01")
25
+ contrib.person_name_inverted.should eql("SHAPIRO")
26
+ contrib.sequence_number.should eql(1)
27
+ end
28
+
29
+ specify "should provide write access to first level attibutes" do
30
+ contrib = ONIX::Contributor.new
31
+
32
+ contrib.contributor_role = "A02"
33
+ contrib.to_xml.to_s.include?("<ContributorRole>A02</ContributorRole>").should be_true
34
+
35
+ contrib.person_name_inverted = "Healy, James"
36
+ contrib.to_xml.to_s.include?("<PersonNameInverted>Healy, James</PersonNameInverted>").should be_true
37
+
38
+ contrib.sequence_number = 1
39
+ contrib.to_xml.to_s.include?("<SequenceNumber>1</SequenceNumber>").should be_true
40
+ end
41
+
42
+ end
@@ -14,12 +14,12 @@ context "ONIX::Header" do
14
14
  end
15
15
 
16
16
  specify "should correctly convert to a string" do
17
- header = ONIX::Header.parse(@header_node.to_s)
17
+ header = ONIX::Header.from_xml(@header_node.to_s)
18
18
  header.to_xml.to_s[0,8].should eql("<Header>")
19
19
  end
20
20
 
21
21
  specify "should provide read access to first level attibutes" do
22
- header = ONIX::Header.parse(@header_node.to_s)
22
+ header = ONIX::Header.from_xml(@header_node.to_s)
23
23
 
24
24
  header.from_ean_number.should eql("1111111111111")
25
25
  header.from_san.should eql("1111111")
@@ -48,52 +48,53 @@ context "ONIX::Header" do
48
48
  header = ONIX::Header.new
49
49
 
50
50
  header.from_ean_number = "1111111111111"
51
- header.from_ean_number.should eql("1111111111111")
51
+ #puts header.to_xml.to_s
52
+ header.to_xml.to_s.include?("<FromEANNumber>1111111111111</FromEANNumber>").should be_true
52
53
 
53
54
  header.from_san = "1111111"
54
- header.from_san.should eql("1111111")
55
+ header.to_xml.to_s.include?("<FromSAN>1111111</FromSAN>").should be_true
55
56
 
56
57
  header.from_company = "Text Company"
57
- header.from_company.should eql("Text Company")
58
+ header.to_xml.to_s.include?("<FromCompany>Text Company</FromCompany>").should be_true
58
59
 
59
60
  header.from_email = "james@rainbowbooks.com.au"
60
- header.from_email.should eql("james@rainbowbooks.com.au")
61
+ header.to_xml.to_s.include?("<FromEmail>james@rainbowbooks.com.au</FromEmail>").should be_true
61
62
 
62
63
  header.from_person = "James"
63
- header.from_person.should eql("James")
64
+ header.to_xml.to_s.include?("<FromPerson>James</FromPerson>").should be_true
64
65
 
65
66
  header.to_ean_number = "2222222222222"
66
- header.to_ean_number.should eql("2222222222222")
67
+ header.to_xml.to_s.include?("<ToEANNumber>2222222222222</ToEANNumber>").should be_true
67
68
 
68
69
  header.to_san = "2222222"
69
- header.to_san.should eql("2222222")
70
+ header.to_xml.to_s.include?("<ToSAN>2222222</ToSAN>").should be_true
70
71
 
71
72
  header.to_company = "Company 2"
72
- header.to_company.should eql("Company 2")
73
+ header.to_xml.to_s.include?("<ToCompany>Company 2</ToCompany>").should be_true
73
74
 
74
75
  header.to_person = "Chris"
75
- header.to_person.should eql("Chris")
76
+ header.to_xml.to_s.include?("<ToPerson>Chris</ToPerson>").should be_true
76
77
 
77
78
  header.message_note = "A Message"
78
- header.message_note.should eql("A Message")
79
+ header.to_xml.to_s.include?("<MessageNote>A Message</MessageNote>").should be_true
79
80
 
80
81
  header.message_repeat = 1
81
- header.message_repeat.should eql(1)
82
+ header.to_xml.to_s.include?("<MessageRepeat>1</MessageRepeat>").should be_true
82
83
 
83
84
  header.sent_date = Date.civil(2008,5,19)
84
- header.sent_date.should eql(Date.civil(2008,5,19))
85
+ header.to_xml.to_s.include?("<SentDate>20080519</SentDate>").should be_true
85
86
 
86
87
  header.default_language_of_text = "aaa"
87
- header.default_language_of_text.should eql("aaa")
88
+ header.to_xml.to_s.include?("<DefaultLanguageOfText>aaa</DefaultLanguageOfText>").should be_true
88
89
 
89
90
  header.default_price_type_code = 1
90
- header.default_price_type_code.should eql(1)
91
+ header.to_xml.to_s.include?("<DefaultPriceTypeCode>01</DefaultPriceTypeCode>").should be_true
91
92
 
92
93
  header.default_currency_code = "ccc"
93
- header.default_currency_code.should eql("ccc")
94
+ header.to_xml.to_s.include?("<DefaultCurrencyCode>ccc</DefaultCurrencyCode>").should be_true
94
95
 
95
96
  header.default_class_of_trade = "f"
96
- header.default_class_of_trade.should eql("f")
97
+ header.to_xml.to_s.include?("<DefaultClassOfTrade>f</DefaultClassOfTrade>").should be_true
97
98
  end
98
99
 
99
100
  specify "should correctly handle text with & < and >" do
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+
7
+ context "ONIX::Imprint" do
8
+
9
+ before(:each) do
10
+ 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
14
+ end
15
+
16
+ specify "should correctly convert to a string" do
17
+ imp = ONIX::Imprint.from_xml(@root.to_s)
18
+ imp.to_xml.to_s[0,9].should eql("<Imprint>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ imp = ONIX::Imprint.from_xml(@root.to_s)
23
+
24
+ imp.imprint_name.should eql("Oxford University Press UK")
25
+ end
26
+
27
+ specify "should provide write access to first level attibutes" do
28
+ imp = ONIX::Imprint.new
29
+
30
+ imp.imprint_name = "Paulist Press"
31
+ imp.to_xml.to_s.include?("<ImprintName>Paulist Press</ImprintName>").should be_true
32
+
33
+ imp.name_code_type = 1
34
+ imp.to_xml.to_s.include?("<NameCodeType>01</NameCodeType>").should be_true
35
+
36
+ end
37
+
38
+ end
39
+
@@ -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::MarketRepresentation" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "market_representation.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
+ rep = ONIX::MarketRepresentation.from_xml(@root.to_s)
18
+ rep.to_xml.to_s[0,22].should eql("<MarketRepresentation>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ rep = ONIX::MarketRepresentation.from_xml(@root.to_s)
23
+
24
+ rep.agent_name.should eql("Allen & Unwin")
25
+ rep.agent_role.should eql(7)
26
+ end
27
+
28
+ specify "should provide write access to first level attibutes" do
29
+ rep = ONIX::MarketRepresentation.new
30
+
31
+ rep.agent_name = "Rainbow Book Agencies"
32
+ rep.to_xml.to_s.include?("<AgentName>Rainbow Book Agencies</AgentName>").should be_true
33
+
34
+ rep.agent_role = 3
35
+ rep.to_xml.to_s.include?("<AgentRole>03</AgentRole>").should be_true
36
+
37
+ end
38
+
39
+ end
40
+
41
+
@@ -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::Measure" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "measure.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
+ m = ONIX::Measure.from_xml(@root.to_s)
18
+ m.to_xml.to_s[0,9].should eql("<Measure>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ m = ONIX::Measure.from_xml(@root.to_s)
23
+
24
+ m.measure_type_code.should eql(1)
25
+ m.measurement.should eql(210)
26
+ m.measure_unit_code.should eql("mm")
27
+ end
28
+
29
+ specify "should provide write access to first level attibutes" do
30
+ m = ONIX::Measure.new
31
+
32
+ m.measure_type_code = 1
33
+ m.to_xml.to_s.include?("<MeasureTypeCode>01</MeasureTypeCode>").should be_true
34
+
35
+ m.measurement = 300
36
+ m.to_xml.to_s.include?("<Measurement>300</Measurement>").should be_true
37
+
38
+ m.measure_unit_code = "mm"
39
+ m.to_xml.to_s.include?("<MeasureUnitCode>mm</MeasureUnitCode>").should be_true
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'onix'
6
+
7
+ context "ONIX::MediaFile" do
8
+
9
+ before(:each) do
10
+ data_path = File.join(File.dirname(__FILE__),"..","data")
11
+ file1 = File.join(data_path, "media_file.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
+ mf = ONIX::MediaFile.from_xml(@root.to_s)
18
+ mf.to_xml.to_s[0,11].should eql("<MediaFile>")
19
+ end
20
+
21
+ specify "should provide read access to first level attibutes" do
22
+ mf = ONIX::MediaFile.from_xml(@root.to_s)
23
+ mf.media_file_type_code.should eql(4)
24
+ mf.media_file_link_type_code.should eql(1)
25
+ mf.media_file_link.should eql("http://www.allenandunwin.com/BookCovers/resized_9788888028729_224_297_FitSquare.jpg")
26
+ end
27
+
28
+ specify "should provide write access to first level attibutes" do
29
+ mf = ONIX::MediaFile.new
30
+
31
+ mf.media_file_type_code = 2
32
+ mf.to_xml.to_s.include?("<MediaFileTypeCode>02</MediaFileTypeCode>").should be_true
33
+
34
+ mf.media_file_link_type_code = 1
35
+ mf.to_xml.to_s.include?("<MediaFileLinkTypeCode>01</MediaFileLinkTypeCode>").should be_true
36
+
37
+ mf.media_file_link = "http://www.google.com"
38
+ mf.to_xml.to_s.include?("<MediaFileLink>http://www.google.com</MediaFileLink>").should be_true
39
+ end
40
+
41
+ end
42
+
@@ -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
+