onix 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +30 -0
- data/README.rdoc +30 -0
- data/TODO +14 -0
- data/lib/onix.rb +57 -0
- data/lib/onix/addressee_identifier.rb +9 -0
- data/lib/onix/apa_product.rb +534 -0
- data/lib/onix/contributor.rb +20 -0
- data/lib/onix/date_type.rb +54 -0
- data/lib/onix/etext_type.rb +44 -0
- data/lib/onix/header.rb +31 -0
- data/lib/onix/imprint.rb +10 -0
- data/lib/onix/integer_type.rb +43 -0
- data/lib/onix/lists/product_availability.rb +30 -0
- data/lib/onix/lists/product_form.rb +97 -0
- data/lib/onix/media_file.rb +11 -0
- data/lib/onix/other_text.rb +12 -0
- data/lib/onix/price.rb +16 -0
- data/lib/onix/product.rb +30 -0
- data/lib/onix/product_identifier.rb +8 -0
- data/lib/onix/publisher.rb +11 -0
- data/lib/onix/reader.rb +124 -0
- data/lib/onix/sales_restriction.rb +7 -0
- data/lib/onix/sender_identifier.rb +9 -0
- data/lib/onix/simple_product.rb +41 -0
- data/lib/onix/stock.rb +10 -0
- data/lib/onix/subject.rb +11 -0
- data/lib/onix/supply_detail.rb +21 -0
- data/lib/onix/title.rb +10 -0
- data/lib/onix/two_digit_type.rb +57 -0
- data/lib/onix/website.rb +9 -0
- data/lib/onix/writer.rb +87 -0
- data/spec/header_spec.rb +111 -0
- data/spec/product_spec.rb +75 -0
- data/spec/reader_spec.rb +64 -0
- data/spec/writer_spec.rb +81 -0
- metadata +117 -0
data/spec/reader_spec.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
4
|
+
|
5
|
+
require 'onix'
|
6
|
+
|
7
|
+
context "ONIX::Reader" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
@file1 = File.join(data_path, "9780194351898.xml")
|
12
|
+
@file2 = File.join(data_path, "two_products.xml")
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "should initialize with a filename" do
|
16
|
+
reader = ONIX::Reader.new(@file1)
|
17
|
+
reader.instance_variable_get("@reader").should be_a_kind_of(LibXML::XML::Reader)
|
18
|
+
end
|
19
|
+
|
20
|
+
=begin
|
21
|
+
specify "should initialize with an IO object" do
|
22
|
+
File.open(@file1,"rb") do |f|
|
23
|
+
reader = ONIX::Reader.new(f)
|
24
|
+
reader.instance_variable_get("@reader").should be_a_kind_of(LibXML::XML::Reader)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
=end
|
28
|
+
|
29
|
+
specify "should provide access to various XML metadata from file" do
|
30
|
+
reader = ONIX::Reader.new(@file1)
|
31
|
+
reader.encoding.should eql("utf-8")
|
32
|
+
reader.xml_lang.should eql(nil)
|
33
|
+
reader.xml_version.should eql(1.0)
|
34
|
+
reader.version.should eql([2,1,0])
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "should provide access to the header in an ONIX file" do
|
38
|
+
reader = ONIX::Reader.new(@file1)
|
39
|
+
reader.header.should be_a_kind_of(ONIX::Header)
|
40
|
+
end
|
41
|
+
|
42
|
+
specify "should iterate over all product records in an ONIX file" do
|
43
|
+
reader = ONIX::Reader.new(@file1)
|
44
|
+
counter = 0
|
45
|
+
reader.each do |product|
|
46
|
+
product.should be_a_kind_of(ONIX::Product)
|
47
|
+
counter += 1
|
48
|
+
end
|
49
|
+
|
50
|
+
counter.should eql(1)
|
51
|
+
end
|
52
|
+
|
53
|
+
specify "should iterate over all product records in an ONIX file" do
|
54
|
+
reader = ONIX::Reader.new(@file2)
|
55
|
+
products = []
|
56
|
+
reader.each do |product|
|
57
|
+
products << product
|
58
|
+
end
|
59
|
+
|
60
|
+
products.size.should eql(2)
|
61
|
+
products[0].record_reference.should eql("365-9780194351898")
|
62
|
+
products[1].record_reference.should eql("9780754672326")
|
63
|
+
end
|
64
|
+
end
|
data/spec/writer_spec.rb
ADDED
@@ -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üng").should be_true
|
79
|
+
end
|
80
|
+
=end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Healy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-28 00:00:00 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: yob-roxml
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: libxml-ruby
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.3
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: andand
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: A convient mapping between ruby objects and the ONIX XML specification
|
46
|
+
email: jimmy@deefa.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- lib/onix/header.rb
|
55
|
+
- lib/onix/price.rb
|
56
|
+
- lib/onix/product.rb
|
57
|
+
- lib/onix/date_type.rb
|
58
|
+
- lib/onix/lists/product_form.rb
|
59
|
+
- lib/onix/lists/product_availability.rb
|
60
|
+
- lib/onix/addressee_identifier.rb
|
61
|
+
- lib/onix/apa_product.rb
|
62
|
+
- lib/onix/contributor.rb
|
63
|
+
- lib/onix/imprint.rb
|
64
|
+
- lib/onix/media_file.rb
|
65
|
+
- lib/onix/other_text.rb
|
66
|
+
- lib/onix/product_identifier.rb
|
67
|
+
- lib/onix/publisher.rb
|
68
|
+
- lib/onix/reader.rb
|
69
|
+
- lib/onix/sales_restriction.rb
|
70
|
+
- lib/onix/sender_identifier.rb
|
71
|
+
- lib/onix/simple_product.rb
|
72
|
+
- lib/onix/stock.rb
|
73
|
+
- lib/onix/subject.rb
|
74
|
+
- lib/onix/supply_detail.rb
|
75
|
+
- lib/onix/title.rb
|
76
|
+
- lib/onix/website.rb
|
77
|
+
- lib/onix/integer_type.rb
|
78
|
+
- lib/onix/two_digit_type.rb
|
79
|
+
- lib/onix/writer.rb
|
80
|
+
- lib/onix/etext_type.rb
|
81
|
+
- lib/onix.rb
|
82
|
+
- README.rdoc
|
83
|
+
- TODO
|
84
|
+
- CHANGELOG
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: http://github.com/yob/onix/tree/master
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options:
|
89
|
+
- --title
|
90
|
+
- ONIX - Working with the ONIX XML spec
|
91
|
+
- --line-numbers
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
99
|
+
version:
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: "0"
|
105
|
+
version:
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project: rbook
|
109
|
+
rubygems_version: 1.2.0
|
110
|
+
signing_key:
|
111
|
+
specification_version: 2
|
112
|
+
summary: A convient mapping between ruby objects and the ONIX XML specification
|
113
|
+
test_files:
|
114
|
+
- spec/header_spec.rb
|
115
|
+
- spec/product_spec.rb
|
116
|
+
- spec/reader_spec.rb
|
117
|
+
- spec/writer_spec.rb
|