im_onix 1.0.2 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.yardopts +1 -0
- data/Gemfile +8 -0
- data/LICENSE.md +7 -0
- data/README.md +3 -3
- data/Rakefile +10 -0
- data/bin/html_codelist_to_yml.rb +14 -15
- data/bin/onix_bench.rb +1 -0
- data/bin/onix_pp.rb +4 -8
- data/bin/onix_serialize.rb +27 -0
- data/doc-src/handlers.rb +154 -0
- data/im_onix.gemspec +32 -0
- data/lib/im_onix.rb +0 -1
- data/lib/onix/addressee.rb +10 -0
- data/lib/onix/code.rb +108 -282
- data/lib/onix/collateral_detail.rb +24 -17
- data/lib/onix/collection.rb +38 -0
- data/lib/onix/collection_sequence.rb +7 -0
- data/lib/onix/contributor.rb +40 -39
- data/lib/onix/date.rb +73 -109
- data/lib/onix/descriptive_detail.rb +90 -417
- data/lib/onix/discount_coded.rb +3 -16
- data/lib/onix/entity.rb +28 -62
- data/lib/onix/epub_usage_constraint.rb +7 -0
- data/lib/onix/epub_usage_limit.rb +6 -0
- data/lib/onix/extent.rb +39 -0
- data/lib/onix/helper.rb +25 -25
- data/lib/onix/identifier.rb +13 -54
- data/lib/onix/language.rb +8 -0
- data/lib/onix/market.rb +5 -0
- data/lib/onix/market_publishing_detail.rb +20 -0
- data/lib/onix/onix21.rb +76 -139
- data/lib/onix/onix_message.rb +87 -100
- data/lib/onix/price.rb +19 -39
- data/lib/onix/product.rb +141 -637
- data/lib/onix/product_form_feature.rb +7 -0
- data/lib/onix/product_part.rb +89 -0
- data/lib/onix/product_supplies_extractor.rb +275 -0
- data/lib/onix/product_supply.rb +17 -58
- data/lib/onix/publishing_detail.rb +16 -32
- data/lib/onix/related_material.rb +4 -3
- data/lib/onix/related_product.rb +9 -29
- data/lib/onix/related_work.rb +3 -17
- data/lib/onix/sales_outlet.rb +2 -10
- data/lib/onix/sales_restriction.rb +8 -21
- data/lib/onix/sales_rights.rb +1 -5
- data/lib/onix/sender.rb +12 -0
- data/lib/onix/serializer.rb +156 -0
- data/lib/onix/subject.rb +9 -30
- data/lib/onix/subset.rb +88 -78
- data/lib/onix/supply_detail.rb +42 -0
- data/lib/onix/supporting_resource.rb +29 -86
- data/lib/onix/tax.rb +9 -18
- data/lib/onix/territory.rb +23 -17
- data/lib/onix/title_detail.rb +22 -0
- data/lib/onix/title_element.rb +32 -0
- data/lib/onix/website.rb +3 -16
- metadata +53 -34
@@ -4,16 +4,18 @@ module ONIX
|
|
4
4
|
class PublishingDetail < SubsetDSL
|
5
5
|
elements "Imprint", :subset
|
6
6
|
elements "Publisher", :subset
|
7
|
-
element "CityOfPublication", :text
|
8
|
-
element "CountryOfPublication", :text
|
9
|
-
element "PublishingStatus", :subset
|
7
|
+
element "CityOfPublication", :text, :shortcut => :city
|
8
|
+
element "CountryOfPublication", :text, :shortcut => :country
|
9
|
+
element "PublishingStatus", :subset, :shortcut => :status
|
10
10
|
elements "PublishingDate", :subset
|
11
|
-
elements "SalesRights", :subset, {:pluralize=>false}
|
12
|
-
element "ROWSalesRightsType", :subset, {:klass=>"SalesRightsType"}
|
11
|
+
elements "SalesRights", :subset, {:pluralize => false}
|
12
|
+
element "ROWSalesRightsType", :subset, {:klass => "SalesRightsType"}
|
13
13
|
element "SalesRestriction", :subset
|
14
14
|
|
15
|
+
# @!group High level
|
16
|
+
|
15
17
|
def publisher
|
16
|
-
main_publishers = @publishers.select { |p| p.role.human=="Publisher" }
|
18
|
+
main_publishers = @publishers.select { |p| p.role.human == "Publisher" }
|
17
19
|
return nil if main_publishers.empty?
|
18
20
|
if main_publishers.length == 1
|
19
21
|
main_publishers.first
|
@@ -24,63 +26,45 @@ module ONIX
|
|
24
26
|
|
25
27
|
def imprint
|
26
28
|
if @imprints.length > 0
|
27
|
-
if @imprints.length==1
|
29
|
+
if @imprints.length == 1
|
28
30
|
@imprints.first
|
29
31
|
else
|
30
32
|
raise ExpectsOneButHasSeveral, @imprints.map(&:name)
|
31
33
|
end
|
32
|
-
else
|
33
|
-
nil
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# date of publication
|
37
38
|
def publication_date
|
38
|
-
pub
|
39
|
+
pub = @publishing_dates.publication.first
|
39
40
|
if pub
|
40
41
|
pub.date
|
41
|
-
else
|
42
|
-
nil
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
45
|
+
# date of embargo
|
46
46
|
def embargo_date
|
47
|
-
pub
|
47
|
+
pub = @publishing_dates.embargo.first
|
48
48
|
if pub
|
49
49
|
pub.date
|
50
|
-
else
|
51
|
-
nil
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
def preorder_embargo_date
|
56
|
-
pub
|
54
|
+
pub = @publishing_dates.preorder_embargo.first
|
57
55
|
if pub
|
58
56
|
pub.date
|
59
|
-
else
|
60
|
-
nil
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
64
60
|
def public_announcement_date
|
65
|
-
pub
|
61
|
+
pub = @publishing_dates.public_announcement.first
|
66
62
|
if pub
|
67
63
|
pub.date
|
68
|
-
else
|
69
|
-
nil
|
70
64
|
end
|
71
65
|
end
|
72
66
|
|
73
|
-
|
74
|
-
@publising_status
|
75
|
-
end
|
76
|
-
|
77
|
-
def city
|
78
|
-
@city_of_publication
|
79
|
-
end
|
80
|
-
|
81
|
-
def country
|
82
|
-
@country_of_publication
|
83
|
-
end
|
67
|
+
# @!endgroup
|
84
68
|
|
85
69
|
end
|
86
70
|
end
|
@@ -5,26 +5,27 @@ module ONIX
|
|
5
5
|
elements "RelatedWork", :subset
|
6
6
|
elements "RelatedProduct", :subset
|
7
7
|
|
8
|
+
# @!group High level
|
9
|
+
|
8
10
|
def linking(human)
|
9
11
|
@related_products.select{|rp| rp.code.human==human}
|
10
12
|
end
|
11
13
|
|
12
|
-
# :category: High level
|
13
14
|
# print products RelatedProduct array
|
14
15
|
def print_products
|
15
16
|
linking("EpublicationBasedOnPrintProduct") + self.alternative_format_products.select{|rp| rp.form && rp.form.code=~/^B/}
|
16
17
|
end
|
17
18
|
|
18
|
-
# :category: High level
|
19
19
|
# is part of products RelatedProduct array
|
20
20
|
def part_of_products
|
21
21
|
linking("IsPartOf")
|
22
22
|
end
|
23
23
|
|
24
|
-
# :category: High level
|
25
24
|
# alternative format products RelatedProduct array
|
26
25
|
def alternative_format_products
|
27
26
|
linking("AlternativeFormat")
|
28
27
|
end
|
28
|
+
|
29
|
+
# @!endgroup
|
29
30
|
end
|
30
31
|
end
|
data/lib/onix/related_product.rb
CHANGED
@@ -3,43 +3,23 @@ module ONIX
|
|
3
3
|
include EanMethods
|
4
4
|
include ProprietaryIdMethods
|
5
5
|
|
6
|
-
element "ProductRelationCode", :subset
|
7
|
-
elements "ProductIdentifier", :subset
|
8
|
-
element "ProductForm", :subset
|
9
|
-
elements "ProductFormDetail", :subset
|
10
|
-
|
11
|
-
# shortcuts
|
12
|
-
def code
|
13
|
-
@product_relation_code
|
14
|
-
end
|
15
|
-
|
16
|
-
def identifiers
|
17
|
-
@product_identifiers
|
18
|
-
end
|
19
|
-
|
20
|
-
def form
|
21
|
-
@product_form
|
22
|
-
end
|
23
|
-
|
24
|
-
def form_details
|
25
|
-
@product_form_details
|
26
|
-
end
|
6
|
+
element "ProductRelationCode", :subset, :shortcut => :code
|
7
|
+
elements "ProductIdentifier", :subset, :shortcut => :identifiers
|
8
|
+
element "ProductForm", :subset, :shortcut => :form
|
9
|
+
elements "ProductFormDetail", :subset, :shortcut => :form_details
|
27
10
|
|
28
11
|
# full Product if referenced in ONIXMessage
|
29
|
-
|
30
|
-
@product
|
31
|
-
end
|
32
|
-
|
33
|
-
def product=v
|
34
|
-
@product=v
|
35
|
-
end
|
12
|
+
attr_accessor :product
|
36
13
|
|
14
|
+
# @!group High level
|
37
15
|
def file_format
|
38
16
|
file_formats.first.human if file_formats.first
|
39
17
|
end
|
40
18
|
|
19
|
+
# @!endgroup
|
20
|
+
|
41
21
|
def file_formats
|
42
|
-
@product_form_details.select{|fd| fd.code =~ /^E1.*/}
|
22
|
+
@product_form_details.select { |fd| fd.code =~ /^E1.*/ }
|
43
23
|
end
|
44
24
|
end
|
45
25
|
end
|
data/lib/onix/related_work.rb
CHANGED
@@ -1,24 +1,10 @@
|
|
1
1
|
module ONIX
|
2
2
|
class RelatedWork < SubsetDSL
|
3
3
|
include EanMethods
|
4
|
-
element "WorkRelationCode", :subset
|
5
|
-
elements "WorkIdentifier", :subset
|
6
|
-
|
7
|
-
def code
|
8
|
-
@work_relation_code
|
9
|
-
end
|
10
|
-
|
11
|
-
def identifiers
|
12
|
-
@work_identifiers
|
13
|
-
end
|
4
|
+
element "WorkRelationCode", :subset, :shortcut => :code
|
5
|
+
elements "WorkIdentifier", :subset, :shortcut => :identifiers
|
14
6
|
|
15
7
|
# full Product if referenced in ONIXMessage
|
16
|
-
|
17
|
-
@product
|
18
|
-
end
|
19
|
-
|
20
|
-
def product=v
|
21
|
-
@product=v
|
22
|
-
end
|
8
|
+
attr_accessor :product
|
23
9
|
end
|
24
10
|
end
|
data/lib/onix/sales_outlet.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
module ONIX
|
2
2
|
class SalesOutlet < SubsetDSL
|
3
|
-
element "SalesOutletIdentifier", :subset
|
4
|
-
element "SalesOutletName", :text
|
5
|
-
|
6
|
-
def identifier
|
7
|
-
@sales_outlet_identifier
|
8
|
-
end
|
9
|
-
|
10
|
-
def name
|
11
|
-
@sales_outlet_name
|
12
|
-
end
|
3
|
+
element "SalesOutletIdentifier", :subset, :shortcut => :identifier
|
4
|
+
element "SalesOutletName", :text, :shortcut => :name
|
13
5
|
end
|
14
6
|
end
|
@@ -1,35 +1,22 @@
|
|
1
1
|
require 'onix/sales_outlet'
|
2
2
|
module ONIX
|
3
3
|
class SalesRestriction < SubsetDSL
|
4
|
-
element "SalesRestrictionType", :subset
|
4
|
+
element "SalesRestrictionType", :subset, :shortcut => :type
|
5
5
|
elements "SalesOutlet", :subset
|
6
|
-
element "SalesRestrictionNote", :text
|
6
|
+
element "SalesRestrictionNote", :text, :shortcut => :note
|
7
7
|
|
8
8
|
attr_accessor :start_date, :end_date
|
9
9
|
|
10
|
-
# shortcuts
|
11
|
-
def type
|
12
|
-
@sales_restriction_type
|
13
|
-
end
|
14
|
-
|
15
|
-
def note
|
16
|
-
@sales_restriction_note
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize
|
20
|
-
@sales_outlets=[]
|
21
|
-
end
|
22
|
-
|
23
10
|
def parse(n)
|
24
11
|
super
|
25
12
|
n.elements.each do |t|
|
26
13
|
case t
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
14
|
+
when tag_match("StartDate")
|
15
|
+
fmt = t["dateformat"] || "00"
|
16
|
+
@start_date = ONIX::Helper.to_date(fmt, t.text)
|
17
|
+
when tag_match("EndDate")
|
18
|
+
fmt = t["dateformat"] || "00"
|
19
|
+
@end_date = ONIX::Helper.to_date(fmt, t.text)
|
33
20
|
end
|
34
21
|
end
|
35
22
|
end
|
data/lib/onix/sales_rights.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
require 'onix/sales_restriction'
|
2
2
|
module ONIX
|
3
3
|
class SalesRights < SubsetDSL
|
4
|
-
element "SalesRightsType", :subset
|
4
|
+
element "SalesRightsType", :subset, :shortcut => :type
|
5
5
|
element "Territory", :subset
|
6
6
|
elements "SalesRestriction", :subset
|
7
|
-
|
8
|
-
def type
|
9
|
-
@sales_rights_type
|
10
|
-
end
|
11
7
|
end
|
12
8
|
end
|
data/lib/onix/sender.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'onix/identifier'
|
2
|
+
|
3
|
+
module ONIX
|
4
|
+
class Sender < SubsetDSL
|
5
|
+
include GlnMethods
|
6
|
+
|
7
|
+
elements "SenderIdentifier", :subset, :shortcut => :identifiers
|
8
|
+
element "SenderName", :text, :shortcut => :name
|
9
|
+
element "ContactName", :text
|
10
|
+
element "EmailAddress", :text
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
module ONIX
|
2
|
+
module Serializer
|
3
|
+
class Traverser
|
4
|
+
|
5
|
+
def self.serialize_subset(mod, xml, subset, parent_tag = nil, level = 0)
|
6
|
+
if subset.class.included_modules.include?(DateHelper)
|
7
|
+
mod.const_get("Date").serialize(xml, subset, parent_tag, level)
|
8
|
+
else
|
9
|
+
if subset.class.included_modules.include?(CodeHelper)
|
10
|
+
mod.const_get("Code").serialize(xml, subset, parent_tag, level)
|
11
|
+
else
|
12
|
+
if subset.class.included_modules.include?(EntityHelper)
|
13
|
+
mod.const_get("Entity").serialize(xml, subset, parent_tag, level)
|
14
|
+
else
|
15
|
+
mod.const_get("Subset").serialize(xml, parent_tag, subset, level)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.recursive_serialize(mod, xml, subset, parent_tag = nil, level = 0)
|
22
|
+
if subset.class.respond_to?(:ancestors_registered_elements)
|
23
|
+
subset.class.ancestors_registered_elements.each do |n, e|
|
24
|
+
unless e.short
|
25
|
+
v = subset.instance_variable_get(e.to_instance)
|
26
|
+
if v
|
27
|
+
if e.is_array?
|
28
|
+
v.each do |vv|
|
29
|
+
case e.type
|
30
|
+
when :subset
|
31
|
+
self.serialize_subset(mod, xml, vv, n, level)
|
32
|
+
when :text, :integer, :float, :bool
|
33
|
+
mod.const_get("Primitive").serialize(xml, n, vv, level)
|
34
|
+
when :ignore
|
35
|
+
else
|
36
|
+
end
|
37
|
+
end
|
38
|
+
else
|
39
|
+
case e.type
|
40
|
+
when :subset
|
41
|
+
self.serialize_subset(mod, xml, v, n, level)
|
42
|
+
when :text, :integer, :float, :bool
|
43
|
+
mod.const_get("Primitive").serialize(xml, n, e.serialize_lambda(v), level)
|
44
|
+
when :ignore
|
45
|
+
else
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module Default
|
57
|
+
class Subset
|
58
|
+
def self.serialize(xml, tag, subset, level = 0)
|
59
|
+
xml.send(tag, nil) {
|
60
|
+
ONIX::Serializer::Traverser.recursive_serialize(Default, xml, subset, tag, level+1)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Primitive
|
66
|
+
def self.serialize(xml, tag, data, level = 0)
|
67
|
+
unless data.respond_to?(:empty?) ? !!data.empty? : !data # rails blank?
|
68
|
+
xml.send(tag, data)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Date
|
74
|
+
def self.serialize(xml, date, parent_tag = nil, level = 0)
|
75
|
+
xml.send(parent_tag, nil) {
|
76
|
+
ONIX::Serializer::Traverser.recursive_serialize(Default, xml, date, parent_tag, level+1)
|
77
|
+
xml.DateFormat(date.date_format.code)
|
78
|
+
code_format=date.format_from_code(date.date_format.code)
|
79
|
+
xml.Date(date.date.strftime(code_format))
|
80
|
+
}
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Code
|
86
|
+
def self.serialize(xml, code, parent_tag = nil, level = 0)
|
87
|
+
xml.send(parent_tag, nil) {
|
88
|
+
xml.text(code.code)
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Entity
|
94
|
+
def self.serialize(xml, entity, parent_tag = nil, level = 0)
|
95
|
+
xml.send(parent_tag, nil) {
|
96
|
+
if entity.role
|
97
|
+
Code.serialize(xml, entity.role, entity.class.role_tag, level+1)
|
98
|
+
end
|
99
|
+
entity.identifiers.each do |identifier|
|
100
|
+
Subset.serialize(xml, entity.class.identifier_tag, identifier, level+1)
|
101
|
+
end
|
102
|
+
if entity.name
|
103
|
+
xml.send(entity.class.name_tag, entity.name)
|
104
|
+
end
|
105
|
+
ONIX::Serializer::Traverser.recursive_serialize(Default, xml, entity, parent_tag, level+1)
|
106
|
+
}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module Dump
|
112
|
+
class Subset
|
113
|
+
def self.serialize(io, tag, subset, level = 0)
|
114
|
+
io.write " "*level
|
115
|
+
io.write "#{tag}:\n"
|
116
|
+
ONIX::Serializer::Traverser.recursive_serialize(Dump, io, subset, tag, level+1)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class Primitive
|
121
|
+
def self.serialize(io, tag, data, level = 0)
|
122
|
+
unless data.respond_to?(:empty?) ? !!data.empty? : !data # rails blank?
|
123
|
+
io.write " "*level
|
124
|
+
io.write "#{tag} : #{data}\n"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Date
|
130
|
+
def self.serialize(io, date, parent_tag = nil, level = 0)
|
131
|
+
io.write " "*level
|
132
|
+
io.write "#{parent_tag}: #{date.date}\n"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class Code
|
137
|
+
def self.serialize(io, code, parent_tag = nil, level = 0)
|
138
|
+
io.write " "*level
|
139
|
+
io.write "#{parent_tag}: #{code.human}(#{code.code})\n"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
class Entity
|
144
|
+
def self.serialize(io, entity, parent_tag = nil, level = 0)
|
145
|
+
io.write " "*level
|
146
|
+
io.write "#{parent_tag}: #{entity.name}\n"
|
147
|
+
if entity.role
|
148
|
+
io.write " "*(level+1)
|
149
|
+
io.write "Role: #{entity.role.human}(#{entity.role.code})\n"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|