im_onix 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc-src/handlers.rb +32 -2
- data/im_onix.gemspec +1 -1
- data/lib/onix/audience_range.rb +1 -0
- data/lib/onix/code.rb +3 -0
- data/lib/onix/collection.rb +3 -0
- data/lib/onix/content_item.rb +6 -0
- data/lib/onix/contributor.rb +18 -4
- data/lib/onix/copyright_statement.rb +1 -0
- data/lib/onix/date.rb +16 -1
- data/lib/onix/descriptive_detail.rb +42 -24
- data/lib/onix/entity.rb +4 -0
- data/lib/onix/helper.rb +3 -12
- data/lib/onix/identifier.rb +3 -0
- data/lib/onix/onix_message.rb +4 -0
- data/lib/onix/price.rb +13 -4
- data/lib/onix/product.rb +10 -0
- data/lib/onix/product_part.rb +5 -0
- data/lib/onix/product_supply.rb +1 -0
- data/lib/onix/publishing_detail.rb +6 -0
- data/lib/onix/related_material.rb +4 -0
- data/lib/onix/related_product.rb +4 -0
- data/lib/onix/related_work.rb +1 -0
- data/lib/onix/resource_version.rb +3 -0
- data/lib/onix/sales_outlet.rb +2 -0
- data/lib/onix/sales_restriction.rb +1 -0
- data/lib/onix/subject.rb +1 -0
- data/lib/onix/subset.rb +6 -0
- data/lib/onix/supply_detail.rb +8 -0
- data/lib/onix/supporting_resource.rb +2 -0
- data/lib/onix/territory.rb +4 -0
- data/lib/onix/title_detail.rb +1 -0
- data/lib/onix/title_element.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 956b2f80b2309dd983629d3e3ec2e14f854c8514ae5fe0cf2030c6929c6db371
|
4
|
+
data.tar.gz: 60b6cfbd37b72e1ee40db946dfff209b18479c1a360fbb7123c4e91da87734f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 898d6346b0e55f4c1b7521e7f3a91d3c03565503833b3acd481fa964ce31b18d8c44df63cbf6eb9848bce854390464f4c2979fff55421d7f48ad9078517fbc56
|
7
|
+
data.tar.gz: 55b9ace6c959c0d6397d42c1ae01d4bef0c8aba84d073258a7fe8855b1c08ef3697cc1a65a53c307de3895ca319f2ca0a6cfb840a33322f318aae646da768e32
|
data/doc-src/handlers.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'yaml'
|
1
2
|
class DSLHelpers
|
2
3
|
def self.inflectors
|
3
4
|
[['ox', 'oxes'],
|
@@ -47,6 +48,10 @@ class ElementDSLAttributeHandler < YARD::Handlers::Ruby::Base
|
|
47
48
|
handles method_call(:element)
|
48
49
|
namespace_only
|
49
50
|
|
51
|
+
def n
|
52
|
+
Float::INFINITY
|
53
|
+
end
|
54
|
+
|
50
55
|
process do
|
51
56
|
name = statement.parameters[0].jump(:tstring_content, :ident).source
|
52
57
|
type = statement.parameters[1].jump(:tstring_content, :ident).source
|
@@ -93,6 +98,10 @@ class ElementsDSLAttributeHandler < YARD::Handlers::Ruby::Base
|
|
93
98
|
handles method_call(:elements)
|
94
99
|
namespace_only
|
95
100
|
|
101
|
+
def n
|
102
|
+
Float::INFINITY
|
103
|
+
end
|
104
|
+
|
96
105
|
process do
|
97
106
|
name = statement.parameters[0].jump(:tstring_content, :ident).source
|
98
107
|
type = statement.parameters[1].jump(:tstring_content, :ident).source
|
@@ -133,10 +142,8 @@ class ElementsDSLAttributeHandler < YARD::Handlers::Ruby::Base
|
|
133
142
|
register(object)
|
134
143
|
end
|
135
144
|
end
|
136
|
-
|
137
145
|
end
|
138
146
|
|
139
|
-
|
140
147
|
class DefDelegatorAttributeHandler < YARD::Handlers::Ruby::Base
|
141
148
|
handles method_call(:def_delegator)
|
142
149
|
namespace_only
|
@@ -152,3 +159,26 @@ class DefDelegatorAttributeHandler < YARD::Handlers::Ruby::Base
|
|
152
159
|
register(object)
|
153
160
|
end
|
154
161
|
end
|
162
|
+
|
163
|
+
class CodeAttributeHandler < YARD::Handlers::Ruby::Base
|
164
|
+
handles method_call(:code_identifier)
|
165
|
+
namespace_only
|
166
|
+
|
167
|
+
process do
|
168
|
+
name = statement.parameters[0].jump(:tstring_content, :ident).source
|
169
|
+
codelist_filename = File.dirname(__FILE__) + "/../data/codelists/codelist-#{name}.yml"
|
170
|
+
if File.exist?(codelist_filename)
|
171
|
+
codelist = YAML.load(File.read(codelist_filename))[:codelist]
|
172
|
+
humanized = []
|
173
|
+
codelist.each do |k,v|
|
174
|
+
humanized << "#{v} (#{k})"
|
175
|
+
end
|
176
|
+
returns = YARD::DocstringParser.new.parse("@return [String] humanized name (from code): "+humanized.join(", ")).to_docstring.tags.first
|
177
|
+
object = YARD::CodeObjects::MethodObject.new(namespace, "human", :instance)
|
178
|
+
object.dynamic = true
|
179
|
+
object.add_tag(returns) if returns
|
180
|
+
object[:group] = 'Low level'
|
181
|
+
register(object)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
data/im_onix.gemspec
CHANGED
data/lib/onix/audience_range.rb
CHANGED
@@ -3,6 +3,7 @@ module ONIX
|
|
3
3
|
element "AudienceRangeQualifier", :subset, :cardinality => 1
|
4
4
|
element "AudienceRangePrecision", :subset, :cardinality => 1
|
5
5
|
element "AudienceRangeValue", :integer, :cardinality => 1
|
6
|
+
|
6
7
|
# element "AudienceRangePrecision", :subset, :cardinality => 0..1
|
7
8
|
# element "AudienceRangeValue", :integer, :cardinality => 0..1
|
8
9
|
end
|
data/lib/onix/code.rb
CHANGED
@@ -13,11 +13,13 @@ module ONIX
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Humanized string code
|
16
|
+
# @return [String]
|
16
17
|
def human
|
17
18
|
@human
|
18
19
|
end
|
19
20
|
|
20
21
|
# ONIX code
|
22
|
+
# @return [String]
|
21
23
|
def onix
|
22
24
|
@code
|
23
25
|
end
|
@@ -89,6 +91,7 @@ module ONIX
|
|
89
91
|
|
90
92
|
class CodeFromYamlWithMime < CodeFromYaml
|
91
93
|
# main formats
|
94
|
+
# @return [String]
|
92
95
|
def mimetype
|
93
96
|
case self.human
|
94
97
|
when "Epub"
|
data/lib/onix/collection.rb
CHANGED
@@ -17,6 +17,7 @@ module ONIX
|
|
17
17
|
# @!group High level
|
18
18
|
|
19
19
|
# collection title string
|
20
|
+
# @return [String]
|
20
21
|
def title
|
21
22
|
if collection_title_element
|
22
23
|
collection_title_element.title
|
@@ -24,12 +25,14 @@ module ONIX
|
|
24
25
|
end
|
25
26
|
|
26
27
|
# collection subtitle string
|
28
|
+
# @return [String]
|
27
29
|
def subtitle
|
28
30
|
if collection_title_element
|
29
31
|
collection_title_element.subtitle
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
35
|
+
# @return [TitleElement]
|
33
36
|
def collection_title_element
|
34
37
|
distinctive_title = @title_details.distinctive_title.first
|
35
38
|
#select { |td| td.type.human=~/DistinctiveTitle/}.first
|
data/lib/onix/content_item.rb
CHANGED
@@ -13,7 +13,10 @@ module ONIX
|
|
13
13
|
class ContentItem < SubsetDSL
|
14
14
|
element "LevelSequenceNumber", :integer, :cardinality => 0..1
|
15
15
|
element "TextItem", :subset, :cardinality => 0..1
|
16
|
+
|
16
17
|
# element "AVItem", :subset, :cardinality => 0..1
|
18
|
+
|
19
|
+
|
17
20
|
element "ComponentTypeName", :text, :cardinality => 0..1
|
18
21
|
element "ComponentNumber", :text, :cardinality => 0..1
|
19
22
|
elements "TitleDetail", :subset, :cardinality => 0..n
|
@@ -22,7 +25,10 @@ module ONIX
|
|
22
25
|
element "NoContributor", :bool, :cardinality => 0..1
|
23
26
|
elements "Language", :subset, :cardinality => 0..n
|
24
27
|
elements "Subject", :subset, :cardinality => 0..n
|
28
|
+
|
25
29
|
# elements "NameAsSubject", :subset, :cardinality => 0..n
|
30
|
+
|
31
|
+
|
26
32
|
elements "TextContent", :subset, :cardinality => 0..n
|
27
33
|
elements "CitedContent", :subset, :cardinality => 0..n
|
28
34
|
elements "SupportingResource", :subset, :cardinality => 0..n
|
data/lib/onix/contributor.rb
CHANGED
@@ -9,7 +9,10 @@ module ONIX
|
|
9
9
|
element "ContributorRole", :subset, :shortcut => :role, :cardinality => 1..n
|
10
10
|
elements "FromLanguage", :subset, :klass => "LanguageCode", :cardinality => 0..n
|
11
11
|
elements "ToLanguage", :subset, :klass => "LanguageCode", :cardinality => 0..n
|
12
|
+
|
12
13
|
# element "NameType", :subset, :cardinality => 0..1
|
14
|
+
|
15
|
+
|
13
16
|
elements "NameIdentifier", :subset, :shortcut => :identifiers, :cardinality => 0..n
|
14
17
|
element "PersonName", :text, :cardinality => 0..1
|
15
18
|
element "PersonNameInverted", :text, :cardinality => 0..1
|
@@ -21,11 +24,17 @@ module ONIX
|
|
21
24
|
element "SuffixToKey", :text, :cardinality => 0..1
|
22
25
|
element "LettersAfterNames", :text, :cardinality => 0..1
|
23
26
|
element "TitlesAfterNames", :text, :cardinality => 0..1
|
27
|
+
|
24
28
|
# element "Gender", :subset, :cardinality => 0..1
|
29
|
+
|
30
|
+
|
25
31
|
element "CorporateName", :text, :cardinality => 0..1
|
26
32
|
element "CorporateNameInverted", :text, :cardinality => 0..1
|
33
|
+
|
27
34
|
# element "UnnamedPersons", :subset, :cardinality => 0..1
|
28
35
|
# elements "AlternativeName", :subset, :cardinality => 0..n
|
36
|
+
|
37
|
+
|
29
38
|
elements "ContributorDate", :subset, :shortcut => :dates, :cardinality => 0..n
|
30
39
|
elements "ProfessionalAffiliation", :subset, :cardinality => 0..n
|
31
40
|
elements "Prize", :subset, :cardinality => 0..n
|
@@ -34,6 +43,15 @@ module ONIX
|
|
34
43
|
elements "ContributorDescription", :text, :cardinality => 0..n
|
35
44
|
elements "ContributorPlace", :subset, :shortcut => :places, :cardinality => 0..n
|
36
45
|
|
46
|
+
# @!group Shortcuts
|
47
|
+
|
48
|
+
# @return [ContributorPlace]
|
49
|
+
def place
|
50
|
+
self.places.first
|
51
|
+
end
|
52
|
+
|
53
|
+
# !@endgroup
|
54
|
+
|
37
55
|
# @!group High level
|
38
56
|
# flatten person name (firstname lastname)
|
39
57
|
# @return [String]
|
@@ -63,10 +81,6 @@ module ONIX
|
|
63
81
|
self.biographies.first
|
64
82
|
end
|
65
83
|
|
66
|
-
def place
|
67
|
-
self.places.first
|
68
|
-
end
|
69
|
-
|
70
84
|
# raw biography string without HTML
|
71
85
|
# @return [String]
|
72
86
|
def raw_biography
|
data/lib/onix/date.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module ONIX
|
2
2
|
module DateHelper
|
3
|
-
|
3
|
+
# @return [DateFormat]
|
4
|
+
attr_accessor :date_format
|
5
|
+
# @return [Date]
|
6
|
+
attr_accessor :date
|
7
|
+
# @return [Time]
|
8
|
+
attr_accessor :datetime
|
4
9
|
|
5
10
|
def parse_date
|
6
11
|
if @date_format
|
@@ -15,6 +20,9 @@ module ONIX
|
|
15
20
|
@date = @datetime ? @datetime.to_date : nil
|
16
21
|
end
|
17
22
|
|
23
|
+
# @param [String] date_txt
|
24
|
+
# @param [DateFormat] date_format
|
25
|
+
# @return [Time]
|
18
26
|
def strpdate!(date_txt, date_format)
|
19
27
|
date_format ||= DateFormat.from_code("00")
|
20
28
|
code_format = format_from_code(date_format.code)
|
@@ -36,6 +44,8 @@ module ONIX
|
|
36
44
|
datetime
|
37
45
|
end
|
38
46
|
|
47
|
+
# @param [String] code
|
48
|
+
# @return [String]
|
39
49
|
def format_from_code(code)
|
40
50
|
case code
|
41
51
|
when "00"
|
@@ -55,6 +65,7 @@ module ONIX
|
|
55
65
|
end
|
56
66
|
end
|
57
67
|
|
68
|
+
# @param [String] str
|
58
69
|
def format_from_string(str)
|
59
70
|
case str
|
60
71
|
when /^\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}/
|
@@ -72,6 +83,7 @@ module ONIX
|
|
72
83
|
end
|
73
84
|
end
|
74
85
|
|
86
|
+
# @return [Time]
|
75
87
|
def time
|
76
88
|
@datetime
|
77
89
|
end
|
@@ -124,6 +136,9 @@ module ONIX
|
|
124
136
|
include DateHelper
|
125
137
|
element "DateFormat", :subset
|
126
138
|
element "Date", :text
|
139
|
+
|
140
|
+
# use former date representation
|
141
|
+
# @return [Boolean]
|
127
142
|
attr_accessor :deprecated_date_format
|
128
143
|
|
129
144
|
def initialize
|
@@ -43,14 +43,20 @@ module ONIX
|
|
43
43
|
elements "Contributor", :subset, :cardinality => 0..n
|
44
44
|
elements "ContributorStatement", :text, :cardinality => 0..n
|
45
45
|
element "NoContributor", :bool, :cardinality => 0..1
|
46
|
+
|
46
47
|
# elements "Conference", :subset, :cardinality => 0..n
|
47
48
|
# elements "Event", :subset, :cardinality => 0..n
|
49
|
+
|
50
|
+
|
48
51
|
element "EditionType", :subset, :cardinality => 0..n
|
49
52
|
element "EditionNumber", :integer, :cardinality => 0..1
|
50
53
|
element "EditionVersionNumber", :text, :cardinality => 0..1
|
51
54
|
elements "EditionStatement", :text, :cardinality => 0..n
|
52
55
|
element "NoEdition", :bool, :cardinality => 0..1
|
56
|
+
|
53
57
|
# element "ReligiousText", :subset, :cardinality => 0..1
|
58
|
+
|
59
|
+
|
54
60
|
elements "Language", :subset, :cardinality => 0..1
|
55
61
|
elements "Extent", :subset, :cardinality => 0..n
|
56
62
|
element "Illustrated", :subset, :cardinality => 0..1
|
@@ -58,7 +64,10 @@ module ONIX
|
|
58
64
|
elements "IllustrationsNote", :text, :cardinality => 0..n
|
59
65
|
elements "AncillaryContent", :subset, :cardinality => 0..n
|
60
66
|
elements "Subject", :subset, :cardinality => 0..n
|
67
|
+
|
61
68
|
# elements "NameAsSubject", :subset, :cardinality => 0..n
|
69
|
+
|
70
|
+
|
62
71
|
elements "AudienceCode", :subset, :cardinality => 0..n
|
63
72
|
elements "Audience", :subset, :cardinality => 0..n
|
64
73
|
elements "AudienceRange", :subset, :cardinality => 0..n
|
@@ -67,18 +76,48 @@ module ONIX
|
|
67
76
|
|
68
77
|
# @!group Shortcuts
|
69
78
|
|
79
|
+
# @return [Extent]
|
70
80
|
def pages_extent
|
71
81
|
@extents.page.first
|
72
82
|
end
|
73
83
|
|
84
|
+
# @return [TitleElement]
|
74
85
|
def product_title_element
|
75
86
|
@title_details.distinctive_title.first.title_elements.product_level.first if @title_details.distinctive_title.first
|
76
87
|
end
|
77
88
|
|
89
|
+
# @return [Array<ProductFormDetail>]
|
78
90
|
def file_formats
|
79
91
|
@product_form_details.select { |fd| fd.code =~ /^E1.*/ }
|
80
92
|
end
|
81
93
|
|
94
|
+
# @return [Collection]
|
95
|
+
def publisher_collection
|
96
|
+
@collections.publisher.first
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [Extent]
|
100
|
+
def filesize_extent
|
101
|
+
@extents.filesize.first
|
102
|
+
end
|
103
|
+
|
104
|
+
# @return [Array<ProductFormDetail>]
|
105
|
+
def audio_formats
|
106
|
+
@product_form_details.select { |fd| fd.code =~ /^A.*/ }
|
107
|
+
end
|
108
|
+
|
109
|
+
# BISAC categories
|
110
|
+
# @return [Array<Subject>]
|
111
|
+
def bisac_categories
|
112
|
+
@subjects.bisac
|
113
|
+
end
|
114
|
+
|
115
|
+
# CLIL categories
|
116
|
+
# @return [Array<Subject>]
|
117
|
+
def clil_categories
|
118
|
+
@subjects.clil
|
119
|
+
end
|
120
|
+
|
82
121
|
# @!endgroup
|
83
122
|
|
84
123
|
# @!group High level
|
@@ -103,10 +142,6 @@ module ONIX
|
|
103
142
|
end
|
104
143
|
end
|
105
144
|
|
106
|
-
def filesize_extent
|
107
|
-
@extents.filesize.first
|
108
|
-
end
|
109
|
-
|
110
145
|
# file size in bytes
|
111
146
|
# @return [Integer]
|
112
147
|
def filesize
|
@@ -145,14 +180,11 @@ module ONIX
|
|
145
180
|
not audio_formats.empty?
|
146
181
|
end
|
147
182
|
|
183
|
+
# @return [String]
|
148
184
|
def audio_format
|
149
185
|
self.audio_formats.first.human if self.audio_formats.first
|
150
186
|
end
|
151
187
|
|
152
|
-
def audio_formats
|
153
|
-
@product_form_details.select { |fd| fd.code =~ /^A.*/ }
|
154
|
-
end
|
155
|
-
|
156
188
|
# is digital offer a bundle ?
|
157
189
|
# @return [Boolean]
|
158
190
|
def bundle?
|
@@ -200,6 +232,7 @@ module ONIX
|
|
200
232
|
end
|
201
233
|
|
202
234
|
# language of text
|
235
|
+
# @return [String]
|
203
236
|
def language_of_text
|
204
237
|
l = @languages.of_text.first
|
205
238
|
if l
|
@@ -207,10 +240,6 @@ module ONIX
|
|
207
240
|
end
|
208
241
|
end
|
209
242
|
|
210
|
-
def publisher_collection
|
211
|
-
@collections.publisher.first
|
212
|
-
end
|
213
|
-
|
214
243
|
# publisher collection title
|
215
244
|
# @return [String]
|
216
245
|
def publisher_collection_title
|
@@ -219,24 +248,12 @@ module ONIX
|
|
219
248
|
end
|
220
249
|
end
|
221
250
|
|
222
|
-
# BISAC categories
|
223
|
-
# @return [Array<Subject>]
|
224
|
-
def bisac_categories
|
225
|
-
@subjects.bisac
|
226
|
-
end
|
227
|
-
|
228
251
|
# BISAC categories identifiers string array (eg: FIC000000)
|
229
252
|
# @return [Array<String>]
|
230
253
|
def bisac_categories_codes
|
231
254
|
self.bisac_categories.map { |c| c.code }.uniq
|
232
255
|
end
|
233
256
|
|
234
|
-
# BISAC categories
|
235
|
-
# @return [Array<Subject>]
|
236
|
-
def clil_categories
|
237
|
-
@subjects.clil
|
238
|
-
end
|
239
|
-
|
240
257
|
# CLIL categories identifier string array
|
241
258
|
# @return [Array<String>]
|
242
259
|
def clil_categories_codes
|
@@ -244,6 +261,7 @@ module ONIX
|
|
244
261
|
end
|
245
262
|
|
246
263
|
# keywords string array
|
264
|
+
# @return [Array<String>]
|
247
265
|
def keywords
|
248
266
|
kws = @subjects.keyword.map { |kw| kw.heading_text }.compact
|
249
267
|
kws = kws.flat_map { |kw| kw.split(/;|,|\n/) }.map { |kw| kw.strip }
|
data/lib/onix/entity.rb
CHANGED
@@ -10,18 +10,22 @@ module ONIX
|
|
10
10
|
include GlnMethods
|
11
11
|
include EntityHelper
|
12
12
|
|
13
|
+
# @return [String]
|
13
14
|
def self.role_tag
|
14
15
|
"#{self.prefix}Role"
|
15
16
|
end
|
16
17
|
|
18
|
+
# @return [String]
|
17
19
|
def self.name_tag
|
18
20
|
"#{self.prefix}Name"
|
19
21
|
end
|
20
22
|
|
23
|
+
# @return [String]
|
21
24
|
def self.identifier_tag
|
22
25
|
"#{self.prefix}Identifier"
|
23
26
|
end
|
24
27
|
|
28
|
+
# @return [String]
|
25
29
|
def self.prefix
|
26
30
|
end
|
27
31
|
|
data/lib/onix/helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module ONIX
|
2
2
|
class Helper
|
3
3
|
# convert arbitrary arg to File/String
|
4
|
+
# @param [String, File] arg
|
4
5
|
def self.arg_to_data(arg)
|
5
6
|
data = ""
|
6
7
|
case arg
|
@@ -33,18 +34,8 @@ module ONIX
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
n.at_xpath(xpath).text.strip
|
39
|
-
else
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.mandatory_text_at(n, xpath)
|
45
|
-
self.text_at(n, xpath)
|
46
|
-
end
|
47
|
-
|
37
|
+
# @param [String] html
|
38
|
+
# @return [String]
|
48
39
|
def self.strip_html(html)
|
49
40
|
html.gsub(/ /, " ").gsub(/<[^>]*(>+|\s*\z)/m, '')
|
50
41
|
end
|
data/lib/onix/identifier.rb
CHANGED
@@ -74,6 +74,7 @@ module ONIX
|
|
74
74
|
|
75
75
|
module EanMethods
|
76
76
|
# EAN string identifier from identifiers
|
77
|
+
# @return [String]
|
77
78
|
def ean
|
78
79
|
if ean_identifier
|
79
80
|
ean_identifier.value
|
@@ -90,6 +91,7 @@ module ONIX
|
|
90
91
|
|
91
92
|
module IsbnMethods
|
92
93
|
# ISBN-13 string identifier from identifiers
|
94
|
+
# @return [String]
|
93
95
|
def isbn13
|
94
96
|
if isbn13_identifier
|
95
97
|
isbn13_identifier.value
|
@@ -106,6 +108,7 @@ module ONIX
|
|
106
108
|
|
107
109
|
module GlnMethods
|
108
110
|
# GLN string identifier from identifiers
|
111
|
+
# @return [String]
|
109
112
|
def gln
|
110
113
|
if gln_identifier
|
111
114
|
if gln_identifier.value =~ /\d{13}/
|
data/lib/onix/onix_message.rb
CHANGED
@@ -89,6 +89,7 @@ module ONIX
|
|
89
89
|
end
|
90
90
|
|
91
91
|
# open with arg detection
|
92
|
+
# @param [String, File] arg
|
92
93
|
def open(arg, force_encoding = nil)
|
93
94
|
data = ONIX::Helper.arg_to_data(arg)
|
94
95
|
|
@@ -104,6 +105,7 @@ module ONIX
|
|
104
105
|
end
|
105
106
|
|
106
107
|
# release as an integer eg: 210, 300, 301
|
108
|
+
# @return [Number]
|
107
109
|
def version
|
108
110
|
if @release
|
109
111
|
@release.gsub(/\./, "").to_i * 10 ** (3 - @release.scan(".").length - 1)
|
@@ -111,6 +113,7 @@ module ONIX
|
|
111
113
|
end
|
112
114
|
|
113
115
|
# detect ONIX version from XML tags
|
116
|
+
# @return [String]
|
114
117
|
def detect_release(element)
|
115
118
|
if element
|
116
119
|
return "3.0" if element.search("//DescriptiveDetail").length > 0
|
@@ -144,6 +147,7 @@ module ONIX
|
|
144
147
|
end
|
145
148
|
|
146
149
|
# parse filename or file
|
150
|
+
# @param [String, File] arg
|
147
151
|
def parse(arg, force_encoding = nil, force_release = nil)
|
148
152
|
@products = []
|
149
153
|
xml = open(arg, force_encoding)
|
data/lib/onix/price.rb
CHANGED
@@ -8,25 +8,33 @@ require 'onix/comparison_product_price'
|
|
8
8
|
module ONIX
|
9
9
|
class Price < SubsetDSL
|
10
10
|
# elements "PriceIdentifier", :subset, :cardinality => 0..n
|
11
|
+
|
12
|
+
|
11
13
|
element "PriceType", :subset, :shortcut => :type, :cardinality => 0..1
|
12
14
|
element "PriceQualifier", :subset, :shortcut => :qualifier, :cardinality => 0..1
|
13
15
|
elements "EpubTechnicalProtection", :subset, :cardinality => 0..n
|
16
|
+
|
14
17
|
# elements "PriceConstraint", :subset, :cardinality => 0..n
|
18
|
+
|
19
|
+
|
15
20
|
element "EpubLicense", :subset, :cardinality => 0..1
|
16
21
|
element "PriceTypeDescription", :text, :cardinality => 0..n
|
22
|
+
|
17
23
|
# element "PricePer", :subset, :cardinality => 0..1
|
18
24
|
# elements "PriceCondition", :subset, :cardinality => 0..n
|
19
25
|
# element "MinimumOrderQuantity", :integer, :cardinality => 0..1
|
20
26
|
# elements "BatchBonus", :subset, :cardinality => 0..n
|
27
|
+
|
28
|
+
|
21
29
|
elements "DiscountCoded", :subset, :cardinality => 0..n
|
22
30
|
elements "Discount", :subset, :cardinality => 0..n
|
23
31
|
element "PriceStatus", :subset
|
24
32
|
element "PriceAmount", :float,
|
25
33
|
{
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
:shortcut => :amount,
|
35
|
+
:parse_lambda => lambda { |v| (v * 100).round },
|
36
|
+
:serialize_lambda => lambda { |v| format("%.2f", v / 100.0) },
|
37
|
+
:cardinality => 0..1
|
30
38
|
}
|
31
39
|
element "Tax", :subset, :cardinality => 0..n
|
32
40
|
element "TaxExempt", :bool, :cardinality => 0..1
|
@@ -39,6 +47,7 @@ module ONIX
|
|
39
47
|
element "PositionOnProduct", :subset, :cardinality => 0..1
|
40
48
|
|
41
49
|
# FIXME discount_coded != discount
|
50
|
+
# @return [DiscountCoded]
|
42
51
|
def discount
|
43
52
|
self.discount_codeds.first
|
44
53
|
end
|
data/lib/onix/product.rb
CHANGED
@@ -29,10 +29,16 @@ module ONIX
|
|
29
29
|
elements "RecordSourceIdentifier", :subset, :cardinality => 0..n
|
30
30
|
element "RecordSourceName", :text, :cardinality => 0..1
|
31
31
|
elements "ProductIdentifier", :subset, :shortcut => :identifiers, :cardinality => 0..n
|
32
|
+
|
32
33
|
# elements "Barcode", :subset, :cardinality => 0..n
|
34
|
+
|
35
|
+
|
33
36
|
element "DescriptiveDetail", :subset, :cardinality => 0..1
|
34
37
|
element "CollateralDetail", :subset, :cardinality => 0..1
|
38
|
+
|
35
39
|
# element "PromotionDetail", :subset, :cardinality => 0..1
|
40
|
+
|
41
|
+
|
36
42
|
element "ContentDetail", :subset, :cardinality => 0..1
|
37
43
|
element "PublishingDetail", :subset, :cardinality => 0..1
|
38
44
|
element "RelatedMaterial", :subset, :cardinality => 0..1
|
@@ -99,19 +105,23 @@ module ONIX
|
|
99
105
|
def_delegator :publishing_detail, :imprint
|
100
106
|
def_delegator :publishing_detail, :publisher
|
101
107
|
|
108
|
+
# @return [CollateralDetail]
|
102
109
|
def collateral_detail
|
103
110
|
@collateral_detail || CollateralDetail.new
|
104
111
|
end
|
105
112
|
|
113
|
+
# @return [DescriptiveDetail]
|
106
114
|
def descriptive_detail
|
107
115
|
@descriptive_detail || DescriptiveDetail.new
|
108
116
|
end
|
109
117
|
|
118
|
+
# @return [PublishingDetail]
|
110
119
|
def publishing_detail
|
111
120
|
@publishing_detail || PublishingDetail.new
|
112
121
|
end
|
113
122
|
|
114
123
|
# product LanguageCode of text
|
124
|
+
# @return [String]
|
115
125
|
def language_of_text
|
116
126
|
@descriptive_detail.language_of_text || @default_language_of_text
|
117
127
|
end
|
data/lib/onix/product_part.rb
CHANGED
@@ -9,7 +9,10 @@ module ONIX
|
|
9
9
|
element "ProductForm", :subset, :shortcut => :form, :cardinality => 1
|
10
10
|
elements "ProductFormDetail", :subset, :shortcut => :form_details, :cardinality => 0..n
|
11
11
|
elements "ProductFormFeature", :subset, :cardinality => 0..n
|
12
|
+
|
12
13
|
# element "ProductPackaging", :subset, :cardinality => 0..1
|
14
|
+
|
15
|
+
|
13
16
|
elements "ProductFormDescription", :text, :shortcut => :file_description, :cardinality => 0..n
|
14
17
|
elements "ProductContentType", :subset, :shortcut => :content_types, :cardinality => 0..n
|
15
18
|
elements "Measure", :subset, :cardinality => 0..n
|
@@ -21,11 +24,13 @@ module ONIX
|
|
21
24
|
@product_form_details.select { |fd| fd.code =~ /^E1.*/ }
|
22
25
|
end
|
23
26
|
|
27
|
+
# @return [ProductFormDescription]
|
24
28
|
def product_form_description
|
25
29
|
product_form_descriptions.first
|
26
30
|
end
|
27
31
|
|
28
32
|
# full Product if referenced in ONIXMessage
|
33
|
+
# @return [Product]
|
29
34
|
attr_accessor :product
|
30
35
|
|
31
36
|
# this ProductPart is part of Product
|
data/lib/onix/product_supply.rb
CHANGED
@@ -21,6 +21,7 @@ module ONIX
|
|
21
21
|
|
22
22
|
# @!group High level
|
23
23
|
|
24
|
+
# @return [Publisher]
|
24
25
|
def publisher
|
25
26
|
main_publishers = @publishers.select { |p| p.role.human == "Publisher" }
|
26
27
|
return nil if main_publishers.empty?
|
@@ -31,6 +32,7 @@ module ONIX
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
# @return [Imprint]
|
34
36
|
def imprint
|
35
37
|
if @imprints.length > 0
|
36
38
|
if @imprints.length == 1
|
@@ -42,6 +44,7 @@ module ONIX
|
|
42
44
|
end
|
43
45
|
|
44
46
|
# date of publication
|
47
|
+
# @return [Date]
|
45
48
|
def publication_date
|
46
49
|
pub = @publishing_dates.publication.first
|
47
50
|
if pub
|
@@ -50,6 +53,7 @@ module ONIX
|
|
50
53
|
end
|
51
54
|
|
52
55
|
# date of embargo
|
56
|
+
# @return [Date]
|
53
57
|
def embargo_date
|
54
58
|
pub = @publishing_dates.embargo.first
|
55
59
|
if pub
|
@@ -57,6 +61,7 @@ module ONIX
|
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
64
|
+
# @return [Date]
|
60
65
|
def preorder_embargo_date
|
61
66
|
pub = @publishing_dates.preorder_embargo.first
|
62
67
|
if pub
|
@@ -64,6 +69,7 @@ module ONIX
|
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
72
|
+
# @return [Date]
|
67
73
|
def public_announcement_date
|
68
74
|
pub = @publishing_dates.public_announcement.first
|
69
75
|
if pub
|
@@ -7,21 +7,25 @@ module ONIX
|
|
7
7
|
|
8
8
|
# @!group High level
|
9
9
|
|
10
|
+
# @return [Array<RelatedProduct>]
|
10
11
|
def linking(human)
|
11
12
|
@related_products.select{|rp| rp.code.human==human}
|
12
13
|
end
|
13
14
|
|
14
15
|
# print products RelatedProduct array
|
16
|
+
# @return [Array<RelatedProduct>]
|
15
17
|
def print_products
|
16
18
|
linking("EpublicationBasedOnPrintProduct") + self.alternative_format_products.select{|rp| rp.form && rp.form.code=~/^B/}
|
17
19
|
end
|
18
20
|
|
19
21
|
# is part of products RelatedProduct array
|
22
|
+
# @return [Array<RelatedProduct>]
|
20
23
|
def part_of_products
|
21
24
|
linking("IsPartOf")
|
22
25
|
end
|
23
26
|
|
24
27
|
# alternative format products RelatedProduct array
|
28
|
+
# @return [Array<RelatedProduct>]
|
25
29
|
def alternative_format_products
|
26
30
|
linking("AlternativeFormat")
|
27
31
|
end
|
data/lib/onix/related_product.rb
CHANGED
@@ -9,19 +9,23 @@ module ONIX
|
|
9
9
|
elements "ProductFormDetail", :subset, :shortcut => :form_details, :cardinality => 0..n
|
10
10
|
|
11
11
|
# full Product if referenced in ONIXMessage
|
12
|
+
# @return [Product]
|
12
13
|
attr_accessor :product
|
13
14
|
|
15
|
+
# @return [ProductRelationCode]
|
14
16
|
def code
|
15
17
|
self.codes.first
|
16
18
|
end
|
17
19
|
|
18
20
|
# @!group High level
|
21
|
+
# @return [String]
|
19
22
|
def file_format
|
20
23
|
file_formats.first.human if file_formats.first
|
21
24
|
end
|
22
25
|
|
23
26
|
# @!endgroup
|
24
27
|
|
28
|
+
# @return [Array<ProductFormDetail>]
|
25
29
|
def file_formats
|
26
30
|
@product_form_details.select { |fd| fd.code =~ /^E1.*/ }
|
27
31
|
end
|
data/lib/onix/related_work.rb
CHANGED
@@ -7,16 +7,19 @@ module ONIX
|
|
7
7
|
elements "ResourceLink", :text, :shortcut => :links, :cardinality => 1..n
|
8
8
|
elements "ContentDate", :subset, :cardinality => 0..n
|
9
9
|
|
10
|
+
# @return [String]
|
10
11
|
def filename
|
11
12
|
if @resource_form.human == "DownloadableFile"
|
12
13
|
resource_links.first
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
17
|
+
# @return [ResourceVersionFeature]
|
16
18
|
def file_format_feature
|
17
19
|
@resource_version_features.select { |f| f.type.human == "FileFormat" }.first
|
18
20
|
end
|
19
21
|
|
22
|
+
# @return [String]
|
20
23
|
def file_format
|
21
24
|
if ["DownloadableFile", "LinkableResource"].include?(@resource_form.human)
|
22
25
|
if file_format_feature
|
data/lib/onix/sales_outlet.rb
CHANGED
@@ -3,10 +3,12 @@ module ONIX
|
|
3
3
|
elements "SalesOutletIdentifier", :subset, :shortcut => :identifiers, :cardinality => 0..n
|
4
4
|
element "SalesOutletName", :text, :shortcut => :name, :cardinality => 0..1
|
5
5
|
|
6
|
+
# @return [SalesOutletIdentifier]
|
6
7
|
def sales_outlet_identifier
|
7
8
|
self.sales_outlet_identifiers.first
|
8
9
|
end
|
9
10
|
|
11
|
+
# @return [SalesOutletIdentifier]
|
10
12
|
def identifier
|
11
13
|
self.identifiers.first
|
12
14
|
end
|
data/lib/onix/subject.rb
CHANGED
data/lib/onix/subset.rb
CHANGED
@@ -26,8 +26,10 @@ module ONIX
|
|
26
26
|
end
|
27
27
|
|
28
28
|
module Attributes
|
29
|
+
# @return [Hash<String,Code>]
|
29
30
|
attr_accessor :attributes
|
30
31
|
|
32
|
+
# @return [Hash<String,String>]
|
31
33
|
def serialized_attributes
|
32
34
|
if @attributes and @attributes.length > 0
|
33
35
|
attrs = {}
|
@@ -38,6 +40,8 @@ module ONIX
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
# @param [String] attr
|
44
|
+
# @return [Class]
|
41
45
|
def self.attribute_class(attr)
|
42
46
|
case attr
|
43
47
|
when "textcase"
|
@@ -68,6 +72,7 @@ module ONIX
|
|
68
72
|
include Attributes
|
69
73
|
|
70
74
|
# instanciate Subset form Nokogiri::XML::Element
|
75
|
+
# @param [Nokogiri::XML::Element] n
|
71
76
|
def self.parse(n)
|
72
77
|
o = self.new
|
73
78
|
o.parse(n)
|
@@ -75,6 +80,7 @@ module ONIX
|
|
75
80
|
end
|
76
81
|
|
77
82
|
# parse Nokogiri::XML::Element
|
83
|
+
# @param [Nokogiri::XML::Element] n
|
78
84
|
def parse(n) end
|
79
85
|
|
80
86
|
def unsupported(tag)
|
data/lib/onix/supply_detail.rb
CHANGED
@@ -12,18 +12,26 @@ module ONIX
|
|
12
12
|
element "ProductAvailability", :subset, :shortcut => :availability, :cardinality => 1
|
13
13
|
elements "SupplyDate", :subset, :cardinality => 0..n
|
14
14
|
element "OrderTime", :integer, :cardinality => 0..1
|
15
|
+
|
15
16
|
# element "NewSupplier", :subset, :cardinality => 0..1
|
16
17
|
# elements "Stock", :subset, :cardinality => 0..n
|
18
|
+
|
19
|
+
|
17
20
|
element "PackQuantity", :integer, :cardinality => 0..1
|
18
21
|
element "PalletQuantity", :integer, :cardinality => 0..1
|
19
22
|
element "OrderQuantityMinimum", :integer, :cardinality => 0..1
|
23
|
+
|
20
24
|
# element "OrderQuantityMinimum", :integer, :cardinality => 0..1
|
25
|
+
|
26
|
+
|
21
27
|
element "OrderQuantityMultiple", :integer, :cardinality => 0..1
|
22
28
|
element "UnpricedItemType", :subset, :cardinality => 0..1
|
23
29
|
elements "Price", :subset, :cardinality => 0..n
|
30
|
+
|
24
31
|
# element "Reissue", :subset, :cardinality => 0..1
|
25
32
|
|
26
33
|
# @!group Shortcuts
|
34
|
+
# @return [Array<Supplier>]
|
27
35
|
def distributors
|
28
36
|
@suppliers.select { |s| s.role.human =~ /Distributor/ }.uniq
|
29
37
|
end
|
@@ -17,10 +17,12 @@ module ONIX
|
|
17
17
|
scope :image, lambda { human_code_match(:resource_mode, "Image") }
|
18
18
|
scope :text, lambda { human_code_match(:resource_mode, "Text") }
|
19
19
|
|
20
|
+
# @return [ResourceFeature]
|
20
21
|
def caption_feature
|
21
22
|
self.features.caption.first
|
22
23
|
end
|
23
24
|
|
25
|
+
# @return [String]
|
24
26
|
def caption
|
25
27
|
if self.caption_feature
|
26
28
|
self.caption_feature.value
|
data/lib/onix/territory.rb
CHANGED
@@ -33,6 +33,7 @@ module ONIX
|
|
33
33
|
self.class.worldwide?(self.countries)
|
34
34
|
end
|
35
35
|
|
36
|
+
# @param [Array<String>] v
|
36
37
|
def countries= v
|
37
38
|
if (v.uniq & CountryCode.list).length == CountryCode.list.length
|
38
39
|
@regions_included = "WORLD"
|
@@ -43,6 +44,8 @@ module ONIX
|
|
43
44
|
|
44
45
|
# !@endgroup
|
45
46
|
|
47
|
+
# @param [String] region
|
48
|
+
# @return [Array<String>]
|
46
49
|
def self.region_to_countries(region)
|
47
50
|
case region
|
48
51
|
when "WORLD"
|
@@ -55,6 +58,7 @@ module ONIX
|
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
61
|
+
# @return [Boolean]
|
58
62
|
def self.worldwide?(countries)
|
59
63
|
(countries & CountryCode.list).length == CountryCode.list.length
|
60
64
|
end
|
data/lib/onix/title_detail.rb
CHANGED
data/lib/onix/title_element.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: im_onix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Boulnois
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|