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.
- data/CHANGELOG +5 -0
- data/lib/onix.rb +51 -17
- data/lib/onix/addressee_identifier.rb +1 -1
- data/lib/onix/contributor.rb +16 -14
- data/lib/onix/header.rb +24 -18
- data/lib/onix/imprint.rb +6 -4
- data/lib/onix/market_representation.rb +9 -7
- data/lib/onix/measure.rb +5 -3
- data/lib/onix/media_file.rb +5 -3
- data/lib/onix/other_text.rb +8 -6
- data/lib/onix/price.rb +8 -6
- data/lib/onix/product.rb +39 -24
- data/lib/onix/product_identifier.rb +3 -1
- data/lib/onix/publisher.rb +7 -5
- data/lib/onix/reader.rb +51 -8
- data/lib/onix/sales_restriction.rb +3 -1
- data/lib/onix/sender_identifier.rb +3 -1
- data/lib/onix/simple_product.rb +4 -0
- data/lib/onix/stock.rb +2 -0
- data/lib/onix/subject.rb +7 -5
- data/lib/onix/supply_detail.rb +13 -6
- data/lib/onix/title.rb +5 -3
- data/lib/onix/website.rb +5 -3
- data/spec/contributor_spec.rb +42 -0
- data/spec/header_spec.rb +19 -18
- data/spec/imprint_spec.rb +39 -0
- data/spec/market_representation_spec.rb +41 -0
- data/spec/measure_spec.rb +43 -0
- data/spec/media_file_spec.rb +42 -0
- data/spec/other_text_spec.rb +40 -0
- data/spec/price_spec.rb +40 -0
- data/spec/product_identifier_spec.rb +40 -0
- data/spec/product_spec.rb +17 -16
- data/spec/publisher_spec.rb +38 -0
- data/spec/sales_restriction_spec.rb +35 -0
- data/spec/sender_identifier.rb +40 -0
- data/spec/stock_spec.rb +44 -0
- data/spec/subject_spec.rb +40 -0
- data/spec/supply_detail_spec.rb +50 -0
- data/spec/title_spec.rb +43 -0
- data/spec/website_spec.rb +41 -0
- metadata +25 -14
- data/lib/onix/date_type.rb +0 -54
- data/lib/onix/decimal_type.rb +0 -49
- data/lib/onix/etext_type.rb +0 -44
- data/lib/onix/integer_type.rb +0 -43
- data/lib/onix/two_digit_type.rb +0 -57
@@ -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::Website" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
data_path = File.join(File.dirname(__FILE__),"..","data")
|
11
|
+
file1 = File.join(data_path, "website.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
|
+
web = ONIX::Website.from_xml(@root.to_s)
|
18
|
+
web.to_xml.to_s[0,9].should eql("<Website>")
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should provide read access to first level attibutes" do
|
22
|
+
web = ONIX::Website.from_xml(@root.to_s)
|
23
|
+
|
24
|
+
web.website_role.should eql(1)
|
25
|
+
web.website_link.should eql("http://www.rainbowbooks.com.au")
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should provide write access to first level attibutes" do
|
29
|
+
web = ONIX::Website.new
|
30
|
+
|
31
|
+
web.website_role = 2
|
32
|
+
web.to_xml.to_s.include?("<WebsiteRole>02</WebsiteRole>").should be_true
|
33
|
+
|
34
|
+
web.website_link = "http://www.yob.id.au"
|
35
|
+
web.to_xml.to_s.include?("<WebsiteLink>http://www.yob.id.au</WebsiteLink>").should be_true
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Healy
|
@@ -9,18 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-03-02 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: roxml
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.
|
23
|
+
version: 2.5.1
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: libxml-ruby
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.8
|
33
|
+
version: 0.9.8
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: andand
|
@@ -54,7 +54,7 @@ files:
|
|
54
54
|
- lib/onix/header.rb
|
55
55
|
- lib/onix/price.rb
|
56
56
|
- lib/onix/product.rb
|
57
|
-
- lib/onix/
|
57
|
+
- lib/onix/reader.rb
|
58
58
|
- lib/onix/lists/product_form.rb
|
59
59
|
- lib/onix/lists/product_availability.rb
|
60
60
|
- lib/onix/addressee_identifier.rb
|
@@ -65,7 +65,7 @@ files:
|
|
65
65
|
- lib/onix/other_text.rb
|
66
66
|
- lib/onix/product_identifier.rb
|
67
67
|
- lib/onix/publisher.rb
|
68
|
-
- lib/onix/
|
68
|
+
- lib/onix/website.rb
|
69
69
|
- lib/onix/sales_restriction.rb
|
70
70
|
- lib/onix/sender_identifier.rb
|
71
71
|
- lib/onix/simple_product.rb
|
@@ -73,14 +73,9 @@ files:
|
|
73
73
|
- lib/onix/subject.rb
|
74
74
|
- lib/onix/supply_detail.rb
|
75
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/measure.rb
|
82
|
-
- lib/onix/decimal_type.rb
|
83
76
|
- lib/onix/market_representation.rb
|
77
|
+
- lib/onix/measure.rb
|
78
|
+
- lib/onix/writer.rb
|
84
79
|
- lib/onix.rb
|
85
80
|
- README.markdown
|
86
81
|
- TODO
|
@@ -118,3 +113,19 @@ test_files:
|
|
118
113
|
- spec/product_spec.rb
|
119
114
|
- spec/reader_spec.rb
|
120
115
|
- spec/writer_spec.rb
|
116
|
+
- spec/contributor_spec.rb
|
117
|
+
- spec/imprint_spec.rb
|
118
|
+
- spec/market_representation_spec.rb
|
119
|
+
- spec/measure_spec.rb
|
120
|
+
- spec/media_file_spec.rb
|
121
|
+
- spec/other_text_spec.rb
|
122
|
+
- spec/price_spec.rb
|
123
|
+
- spec/product_identifier_spec.rb
|
124
|
+
- spec/publisher_spec.rb
|
125
|
+
- spec/sales_restriction_spec.rb
|
126
|
+
- spec/sender_identifier.rb
|
127
|
+
- spec/stock_spec.rb
|
128
|
+
- spec/subject_spec.rb
|
129
|
+
- spec/supply_detail_spec.rb
|
130
|
+
- spec/title_spec.rb
|
131
|
+
- spec/website_spec.rb
|
data/lib/onix/date_type.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
module ONIX
|
4
|
-
|
5
|
-
# Internal class representing XML content date binding
|
6
|
-
#
|
7
|
-
# In context:
|
8
|
-
# <element attribute="XMLAttributeRef">
|
9
|
-
# XMLYYYYMMDDRef
|
10
|
-
# </element>
|
11
|
-
class DateType < ROXML::XMLRef # ::nodoc::
|
12
|
-
attr_reader :cdata, :content
|
13
|
-
|
14
|
-
def initialize(accessor, args, &block)
|
15
|
-
super(accessor, args, &block)
|
16
|
-
@content = args.content?
|
17
|
-
@cdata = args.cdata?
|
18
|
-
end
|
19
|
-
|
20
|
-
# Updates the text in the given _xml_ block to
|
21
|
-
# the _value_ provided.
|
22
|
-
def update_xml(xml, value)
|
23
|
-
parent = wrap(xml)
|
24
|
-
add(parent.child_add(LibXML::XML::Node.new_element(name)), value.strftime("%Y%m%d"))
|
25
|
-
xml
|
26
|
-
end
|
27
|
-
|
28
|
-
def value(xml)
|
29
|
-
begin
|
30
|
-
if content
|
31
|
-
value = Date.parse(xml.content.strip)
|
32
|
-
else
|
33
|
-
child = xml.search(name).first
|
34
|
-
value = Date.parse(child.content.strip) if child
|
35
|
-
end
|
36
|
-
rescue ArgumentError
|
37
|
-
value = nil
|
38
|
-
end
|
39
|
-
block ? block.call(value) : value
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def add(dest, value)
|
45
|
-
if cdata
|
46
|
-
dest.child_add(LibXML::XML::Node.new_cdata(value.to_utf))
|
47
|
-
else
|
48
|
-
dest.content = value.to_utf
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
ROXML::TypeRegistry.register(:yyyymmdd, ONIX::DateType)
|
data/lib/onix/decimal_type.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'bigdecimal'
|
2
|
-
|
3
|
-
module ONIX
|
4
|
-
|
5
|
-
class DecimalType < ROXML::XMLRef # ::nodoc::
|
6
|
-
attr_reader :cdata, :content
|
7
|
-
|
8
|
-
def initialize(accessor, args, &block)
|
9
|
-
super(accessor, args, &block)
|
10
|
-
@content = args.content?
|
11
|
-
@cdata = args.cdata?
|
12
|
-
end
|
13
|
-
|
14
|
-
# Updates the text in the given _xml_ block to
|
15
|
-
# the _value_ provided.
|
16
|
-
def update_xml(xml, value)
|
17
|
-
parent = wrap(xml)
|
18
|
-
if value.kind_of?(BigDecimal)
|
19
|
-
value = value.to_s("F")
|
20
|
-
else
|
21
|
-
value = value.to_s
|
22
|
-
end
|
23
|
-
add(parent.child_add(LibXML::XML::Node.new_element(name)), value)
|
24
|
-
xml
|
25
|
-
end
|
26
|
-
|
27
|
-
def value(xml)
|
28
|
-
if content
|
29
|
-
value = BigDecimal.new(xml.content)
|
30
|
-
else
|
31
|
-
child = xml.search(name).first
|
32
|
-
value = BigDecimal.new(child.content) if child
|
33
|
-
end
|
34
|
-
block ? block.call(value) : value
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def add(dest, value)
|
40
|
-
if cdata
|
41
|
-
dest.child_add(LibXML::XML::Node.new_cdata(value.to_utf))
|
42
|
-
else
|
43
|
-
dest.content = value.to_utf
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
ROXML::TypeRegistry.register(:decimal, ONIX::DecimalType)
|
data/lib/onix/etext_type.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module ONIX
|
2
|
-
|
3
|
-
class ETextType < ROXML::XMLRef # ::nodoc::
|
4
|
-
attr_reader :cdata, :content
|
5
|
-
|
6
|
-
def initialize(accessor, args, &block)
|
7
|
-
super(accessor, args, &block)
|
8
|
-
@content = args.content?
|
9
|
-
@cdata = args.cdata?
|
10
|
-
end
|
11
|
-
|
12
|
-
# Updates the text in the given _xml_ block to
|
13
|
-
# the _value_ provided.
|
14
|
-
def update_xml(xml, value)
|
15
|
-
value = value.to_s.gsub("&","&").gsub("<","<").gsub(">",">")
|
16
|
-
parent = wrap(xml)
|
17
|
-
add(parent.child_add(LibXML::XML::Node.new_element(name)), value)
|
18
|
-
xml
|
19
|
-
end
|
20
|
-
|
21
|
-
def value(xml)
|
22
|
-
if content
|
23
|
-
value = xml.content
|
24
|
-
else
|
25
|
-
child = xml.search(name).first
|
26
|
-
value = child.content if child
|
27
|
-
end
|
28
|
-
value = value.gsub("&","&").gsub("<","<").gsub(">",">") if value
|
29
|
-
block ? block.call(value) : value
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def add(dest, value)
|
35
|
-
if cdata
|
36
|
-
dest.child_add(LibXML::XML::Node.new_cdata(value.to_utf))
|
37
|
-
else
|
38
|
-
dest.content = value.to_utf
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
ROXML::TypeRegistry.register(:etext, ONIX::ETextType)
|
data/lib/onix/integer_type.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
|
2
|
-
module ONIX
|
3
|
-
|
4
|
-
class IntegerType < ROXML::XMLRef # ::nodoc::
|
5
|
-
attr_reader :cdata, :content
|
6
|
-
|
7
|
-
def initialize(accessor, args, &block)
|
8
|
-
super(accessor, args, &block)
|
9
|
-
@content = args.content?
|
10
|
-
@cdata = args.cdata?
|
11
|
-
end
|
12
|
-
|
13
|
-
# Updates the text in the given _xml_ block to
|
14
|
-
# the _value_ provided.
|
15
|
-
def update_xml(xml, value)
|
16
|
-
parent = wrap(xml)
|
17
|
-
add(parent.child_add(LibXML::XML::Node.new_element(name)), value)
|
18
|
-
xml
|
19
|
-
end
|
20
|
-
|
21
|
-
def value(xml)
|
22
|
-
if content
|
23
|
-
value = xml.content.to_i
|
24
|
-
else
|
25
|
-
child = xml.search(name).first
|
26
|
-
value = child.content.to_i if child
|
27
|
-
end
|
28
|
-
block ? block.call(value) : value
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def add(dest, value)
|
34
|
-
if cdata
|
35
|
-
dest.child_add(LibXML::XML::Node.new_cdata(value.to_utf))
|
36
|
-
else
|
37
|
-
dest.content = value.to_utf
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
ROXML::TypeRegistry.register(:integer, ONIX::IntegerType)
|
data/lib/onix/two_digit_type.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
|
2
|
-
module ONIX
|
3
|
-
|
4
|
-
# Internal class representing 2-digit XML content
|
5
|
-
#
|
6
|
-
# In context:
|
7
|
-
# <element attribute="XMLAttributeRef">
|
8
|
-
# XMLTwoDigitRef
|
9
|
-
# </element>
|
10
|
-
class TwoDigitType < ROXML::XMLRef # ::nodoc::
|
11
|
-
attr_reader :cdata, :content
|
12
|
-
|
13
|
-
def initialize(accessor, args, &block)
|
14
|
-
super(accessor, args, &block)
|
15
|
-
@content = args.content?
|
16
|
-
@cdata = args.cdata?
|
17
|
-
end
|
18
|
-
|
19
|
-
# Updates the text in the given _xml_ block to
|
20
|
-
# the _value_ provided.
|
21
|
-
def update_xml(xml, value)
|
22
|
-
parent = wrap(xml)
|
23
|
-
value = value.to_i
|
24
|
-
if value < 10
|
25
|
-
value = "0#{value}"
|
26
|
-
elsif value < 100
|
27
|
-
value = value.to_s
|
28
|
-
else
|
29
|
-
value = "00"
|
30
|
-
end
|
31
|
-
add(parent.child_add(LibXML::XML::Node.new_element(name)), value)
|
32
|
-
xml
|
33
|
-
end
|
34
|
-
|
35
|
-
def value(xml)
|
36
|
-
if content
|
37
|
-
value = xml.content.to_i
|
38
|
-
else
|
39
|
-
child = xml.search(name).first
|
40
|
-
value = child.content.to_i if child
|
41
|
-
end
|
42
|
-
block ? block.call(value) : value
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def add(dest, value)
|
48
|
-
if cdata
|
49
|
-
dest.child_add(LibXML::XML::Node.new_cdata(value.to_utf))
|
50
|
-
else
|
51
|
-
dest.content = value.to_utf
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
ROXML::TypeRegistry.register(:twodigit, ONIX::TwoDigitType)
|