rbook-onix 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/COPYING +340 -0
  2. data/LICENSE +13 -0
  3. data/README +0 -0
  4. data/Rakefile +90 -0
  5. data/examples/stream_reader.rb +13 -0
  6. data/lib/rbook/onix.rb +70 -0
  7. data/lib/rbook/onix/contributor.rb +59 -0
  8. data/lib/rbook/onix/lists.rb +2 -0
  9. data/lib/rbook/onix/lists/contributor_role.rb +10 -0
  10. data/lib/rbook/onix/lists/product_form.rb +100 -0
  11. data/lib/rbook/onix/message.rb +121 -0
  12. data/lib/rbook/onix/product.rb +208 -0
  13. data/lib/rbook/onix/sales_restriction.rb +50 -0
  14. data/lib/rbook/onix/stream_reader.rb +120 -0
  15. data/lib/rbook/onix/stream_writer.rb +40 -0
  16. data/lib/rbook/onix/supply_detail.rb +75 -0
  17. data/lib/rbook/onix/xchar.rb +62 -0
  18. data/specs/contributor_class_spec.rb +33 -0
  19. data/specs/contributor_with_data_spec.rb +36 -0
  20. data/specs/data/10_products.xml +469 -0
  21. data/specs/data/2_products_utf16.xml +0 -0
  22. data/specs/data/abingdon.xml +38931 -0
  23. data/specs/data/augsburg.xml +39009 -0
  24. data/specs/data/chalice.xml +10851 -0
  25. data/specs/data/eerdsman.xml +36942 -0
  26. data/specs/data/invalid_no_product.xml +9 -0
  27. data/specs/data/invalid_xml.xml +24 -0
  28. data/specs/data/not_xml.csv +1 -0
  29. data/specs/data/single_product.xml +55 -0
  30. data/specs/data/xml_not_onix.xml +7 -0
  31. data/specs/message_class_spec.rb +110 -0
  32. data/specs/message_with_data_spec.rb +81 -0
  33. data/specs/product_class_spec.rb +42 -0
  34. data/specs/product_with_data_spec.rb +66 -0
  35. data/specs/sales_restriction_class_spec.rb +32 -0
  36. data/specs/sales_restriction_with_data_spec.rb +31 -0
  37. data/specs/stream_reader_spec.rb +31 -0
  38. data/specs/stream_writer_spec.rb +30 -0
  39. data/specs/supply_detail_class_spec.rb +35 -0
  40. data/specs/supply_detail_with_data_spec.rb +42 -0
  41. data/specs/xchar_spec.rb +39 -0
  42. metadata +116 -0
@@ -0,0 +1,31 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'rbook/onix'
4
+ include RBook
5
+
6
+ context "The stream reader class" do
7
+
8
+ specify "should read in all the objects from an ONIX file with a single product" do
9
+ counter = 0
10
+
11
+ reader = RBook::Onix::StreamReader.new(File.dirname(__FILE__)+"/data/single_product.xml")
12
+ reader.each do |product|
13
+ product.should be_a_kind_of(RBook::Onix::Product)
14
+ counter += 1
15
+ end
16
+
17
+ counter.should eql(1)
18
+ end
19
+
20
+ specify "should read in all the objects from an ONIX file with multiple products" do
21
+ counter = 0
22
+
23
+ reader = RBook::Onix::StreamReader.new(File.dirname(__FILE__)+"/data/10_products.xml")
24
+ reader.each do |product|
25
+ product.should be_a_kind_of(RBook::Onix::Product)
26
+ counter += 1
27
+ end
28
+
29
+ counter.should eql(10)
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'rbook/onix'
4
+ include RBook
5
+
6
+ context "The stream class class" do
7
+
8
+ specify "should write all supplied products to the IO object" do
9
+ reader = RBook::Onix::StreamReader.new(File.dirname(__FILE__)+"/data/single_product.xml")
10
+
11
+ output = StringIO.new
12
+ msg = RBook::Onix::Message.new
13
+ msg.from_company = "Test Company"
14
+ msg.from_person = "James Healy"
15
+
16
+ writer = RBook::Onix::StreamWriter.new(output, msg)
17
+ writer.start_document
18
+
19
+ reader.each do |product|
20
+ writer << product
21
+ end
22
+
23
+ writer.end_document
24
+
25
+ matches = output.string.match(/<Product>/)
26
+ matches.should_not be_nil
27
+ matches.size.should eql(1)
28
+ end
29
+
30
+ end
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'rbook/onix'
4
+ include RBook
5
+
6
+ context "The contributor class" do
7
+
8
+ #setup do
9
+ #end
10
+
11
+ # test loading a valid onix file. Make sure the correct number of products
12
+ # exist, but don't worry about the content. The product unit tests can check them
13
+ specify "should create a object tree from an xmldoc object" do
14
+ supply_detail = nil
15
+ File.open(File.dirname(__FILE__)+"/data/single_product.xml", "r") do |f|
16
+ doc = REXML::Document.new(f)
17
+ supply_detail = RBook::Onix::SupplyDetail.load_from_element(REXML::XPath.first(doc, '/ONIXMessage/Product/SupplyDetail'))
18
+ end
19
+
20
+ supply_detail.supplier_name.should eql("Chalice")
21
+ supply_detail.availability_code.should eql("CS")
22
+ supply_detail.intermediary_availability_code.should eql("99")
23
+ supply_detail.price.should eql(29.95)
24
+ supply_detail.price_type_code.should eql(2)
25
+ end
26
+
27
+ specify "should raise an exception when atytempting to load from a non Product XML fragment" do
28
+ element = REXML::Element.new('NonSupplyDetail')
29
+ element.add_element('SupplierName').text = 'blah'
30
+
31
+ # TODO: change this to a custom RBook error
32
+ lambda {RBook::Onix::SupplyDetail.load_from_element(element) }.should raise_error(LoadError)
33
+
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'rbook/onix'
4
+ include RBook
5
+
6
+ context "A product object with valid data" do
7
+
8
+ #setup do
9
+ #end
10
+
11
+ # ensure product information is output to xml correctly
12
+ # TODO: test more than just IDValue and TitleText
13
+ specify "should output to a valid XML fragment" do
14
+
15
+ supply_detail = RBook::Onix::SupplyDetail.new
16
+ supply_detail.supplier_name = 'Walker'
17
+ supply_detail.availability_code = 'CS'
18
+ supply_detail.price = 38.05
19
+
20
+ doc = supply_detail.to_element
21
+
22
+ REXML::XPath.first(doc, '/SupplierName').should_not be_nil
23
+ REXML::XPath.first(doc, '/SupplierName').text.should eql("Walker")
24
+ REXML::XPath.first(doc, '/AvailabilityCode').should_not be_nil
25
+ REXML::XPath.first(doc, '/AvailabilityCode').text.should eql("CS")
26
+ REXML::XPath.first(doc, '/Price/PriceAmount').should_not be_nil
27
+ REXML::XPath.first(doc, '/Price/PriceAmount').text.should eql("38.05")
28
+ REXML::XPath.first(doc, '/Price/PriceTypeCode').should_not be_nil
29
+ REXML::XPath.first(doc, '/Price/PriceTypeCode').text.should eql("02")
30
+
31
+ end
32
+
33
+ specify "should output a valid string" do
34
+ supply_detail = RBook::Onix::SupplyDetail.new
35
+ supply_detail.supplier_name = 'Walker'
36
+ supply_detail.availability_code = 'CS'
37
+ supply_detail.price = 38.05
38
+
39
+ supply_detail.to_s.should be_a_kind_of(String)
40
+
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'rbook/onix'
4
+ include RBook
5
+
6
+ context "The xchar methods added to the core classes" do
7
+
8
+ specify "should leave ascii chars untouched" do
9
+ "abc".to_xs.should eql("abc")
10
+ end
11
+
12
+ specify "should convert reserved XML chars to entities" do
13
+ "&".to_xs.should eql("&amp;")
14
+ "<".to_xs.should eql("&lt;")
15
+ ">".to_xs.should eql("&gt;")
16
+ end
17
+
18
+ specify "should replaces chars that are illegal in XML with a *" do
19
+ "\x00".to_xs.should eql("*")
20
+ "\x0C".to_xs.should eql("*")
21
+ "\xEF\xBF\xBF".to_xs.should eql("*")
22
+ end
23
+
24
+ specify "should convert iso-8859-1 chars to their UTF-8 equivilants" do
25
+ "\xE7".to_xs.should eql("&#231;")
26
+ "\xA9".to_xs.should eql("&#169;")
27
+ end
28
+
29
+ specify "should convert windows-1252 chars to their UTF-8 equivilants" do
30
+ "\x92".to_xs.should eql("&#8217;")
31
+ "\x80".to_xs.should eql("&#8364;")
32
+ end
33
+
34
+ specify "should convert UTF-8 chars > 127 into entities" do
35
+ "\xE2\x80\x99".to_xs.should eql("&#8217;")
36
+ "\xC2\xA9".to_xs.should eql("&#169;")
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: rbook-onix
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.5"
7
+ date: 2007-07-03 00:00:00 +10:00
8
+ summary: A library for manipulating ONIX files
9
+ require_paths:
10
+ - lib
11
+ email: jimmy@deefa.com
12
+ homepage: http://rbook.rubyforge.org/
13
+ rubyforge_project: rbook
14
+ description: This library is designed to make working with the book industries ONIX standard easier.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - James Healy
31
+ files:
32
+ - examples/stream_reader.rb
33
+ - lib/rbook
34
+ - lib/rbook/onix
35
+ - lib/rbook/onix/lists
36
+ - lib/rbook/onix/lists/contributor_role.rb
37
+ - lib/rbook/onix/lists/product_form.rb
38
+ - lib/rbook/onix/sales_restriction.rb
39
+ - lib/rbook/onix/stream_reader.rb
40
+ - lib/rbook/onix/lists.rb
41
+ - lib/rbook/onix/supply_detail.rb
42
+ - lib/rbook/onix/product.rb
43
+ - lib/rbook/onix/message.rb
44
+ - lib/rbook/onix/xchar.rb
45
+ - lib/rbook/onix/stream_writer.rb
46
+ - lib/rbook/onix/contributor.rb
47
+ - lib/rbook/onix.rb
48
+ - specs/data
49
+ - specs/data/xml_not_onix.xml
50
+ - specs/data/abingdon.xml
51
+ - specs/data/invalid_no_product.xml
52
+ - specs/data/single_product.xml
53
+ - specs/data/chalice.xml
54
+ - specs/data/not_xml.csv
55
+ - specs/data/10_products.xml
56
+ - specs/data/eerdsman.xml
57
+ - specs/data/augsburg.xml
58
+ - specs/data/2_products_utf16.xml
59
+ - specs/data/invalid_xml.xml
60
+ - specs/message_class_spec.rb
61
+ - specs/contributor_class_spec.rb
62
+ - specs/product_class_spec.rb
63
+ - specs/product_with_data_spec.rb
64
+ - specs/message_with_data_spec.rb
65
+ - specs/contributor_with_data_spec.rb
66
+ - specs/xchar_spec.rb
67
+ - specs/supply_detail_class_spec.rb
68
+ - specs/supply_detail_with_data_spec.rb
69
+ - specs/sales_restriction_class_spec.rb
70
+ - specs/sales_restriction_with_data_spec.rb
71
+ - specs/stream_reader_spec.rb
72
+ - specs/stream_writer_spec.rb
73
+ - Rakefile
74
+ - README
75
+ - COPYING
76
+ - LICENSE
77
+ test_files:
78
+ - specs/message_class_spec.rb
79
+ - specs/contributor_class_spec.rb
80
+ - specs/product_class_spec.rb
81
+ - specs/product_with_data_spec.rb
82
+ - specs/message_with_data_spec.rb
83
+ - specs/contributor_with_data_spec.rb
84
+ - specs/xchar_spec.rb
85
+ - specs/supply_detail_class_spec.rb
86
+ - specs/supply_detail_with_data_spec.rb
87
+ - specs/sales_restriction_class_spec.rb
88
+ - specs/sales_restriction_with_data_spec.rb
89
+ - specs/stream_reader_spec.rb
90
+ - specs/stream_writer_spec.rb
91
+ rdoc_options:
92
+ - --title
93
+ - onix Documentation
94
+ - --main
95
+ - README
96
+ - -q
97
+ extra_rdoc_files:
98
+ - README
99
+ - COPYING
100
+ - LICENSE
101
+ executables: []
102
+
103
+ extensions: []
104
+
105
+ requirements: []
106
+
107
+ dependencies:
108
+ - !ruby/object:Gem::Dependency
109
+ name: rbook-isbn
110
+ version_requirement:
111
+ version_requirements: !ruby/object:Gem::Version::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "1.0"
116
+ version: