relaton-bib 1.11.7 → 1.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +50 -221
- data/grammars/biblio.rng +134 -39
- data/grammars/isodoc.rng +77 -0
- data/lib/relaton_bib/bib_item_locality.rb +1 -1
- data/lib/relaton_bib/biblio_version.rb +12 -15
- data/lib/relaton_bib/bibliographic_date.rb +2 -1
- data/lib/relaton_bib/bibliographic_item.rb +54 -41
- data/lib/relaton_bib/bibxml_parser.rb +10 -0
- data/lib/relaton_bib/contribution_info.rb +2 -2
- data/lib/relaton_bib/contributor.rb +9 -9
- data/lib/relaton_bib/document_identifier.rb +21 -12
- data/lib/relaton_bib/document_relation_collection.rb +2 -2
- data/lib/relaton_bib/edition.rb +55 -0
- data/lib/relaton_bib/hash_converter.rb +61 -66
- data/lib/relaton_bib/series.rb +16 -21
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +17 -10
- data/lib/relaton_bib.rb +25 -0
- metadata +3 -2
@@ -6,11 +6,11 @@ module RelatonBib
|
|
6
6
|
# @param args [Hash]
|
7
7
|
# @param neated [TrueClas, FalseClass] default false
|
8
8
|
# @return [Hash]
|
9
|
-
def hash_to_bib(args
|
9
|
+
def hash_to_bib(args)
|
10
10
|
return nil unless args.is_a?(Hash)
|
11
11
|
|
12
12
|
ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
|
13
|
-
timestamp_hash(ret) unless nested
|
13
|
+
# timestamp_hash(ret) unless nested
|
14
14
|
title_hash_to_bib(ret)
|
15
15
|
link_hash_to_bib(ret)
|
16
16
|
language_hash_to_bib(ret)
|
@@ -33,8 +33,8 @@ module RelatonBib
|
|
33
33
|
accesslocation_hash_to_bib(ret)
|
34
34
|
classification_hash_to_bib(ret)
|
35
35
|
validity_hash_to_bib(ret)
|
36
|
-
ret[:keyword] = array(ret[:keyword])
|
37
|
-
ret[:license] = array(ret[:license])
|
36
|
+
ret[:keyword] = RelatonBib.array(ret[:keyword])
|
37
|
+
ret[:license] = RelatonBib.array(ret[:license])
|
38
38
|
editorialgroup_hash_to_bib ret
|
39
39
|
ics_hash_to_bib ret
|
40
40
|
structuredidentifier_hash_to_bib ret
|
@@ -42,14 +42,14 @@ module RelatonBib
|
|
42
42
|
end
|
43
43
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
44
44
|
|
45
|
-
def timestamp_hash(ret)
|
46
|
-
|
47
|
-
end
|
45
|
+
# def timestamp_hash(ret)
|
46
|
+
# ret[:fetched] ||= Date.today.to_s
|
47
|
+
# end
|
48
48
|
|
49
49
|
def extent_hash_to_bib(ret)
|
50
50
|
return unless ret[:extent]
|
51
51
|
|
52
|
-
ret[:extent] = array(ret[:extent]).map do |e|
|
52
|
+
ret[:extent] = RelatonBib.array(ret[:extent]).map do |e|
|
53
53
|
locality e
|
54
54
|
# ret[:extent][i] = Locality.new(e[:type], e[:reference_from],
|
55
55
|
# e[:reference_to])
|
@@ -68,7 +68,7 @@ module RelatonBib
|
|
68
68
|
def size_hash_to_bib(ret)
|
69
69
|
return unless ret[:size]
|
70
70
|
|
71
|
-
ret[:size] = array(ret[:size])
|
71
|
+
ret[:size] = RelatonBib.array(ret[:size])
|
72
72
|
size = ret[:size]&.map do |val|
|
73
73
|
BibliographicSize::Value.new(**val)
|
74
74
|
end
|
@@ -78,7 +78,7 @@ module RelatonBib
|
|
78
78
|
def title_hash_to_bib(ret)
|
79
79
|
return unless ret[:title]
|
80
80
|
|
81
|
-
ret[:title] = array(ret[:title])
|
81
|
+
ret[:title] = RelatonBib.array(ret[:title])
|
82
82
|
.reduce(TypedTitleStringCollection.new) do |m, t|
|
83
83
|
if t.is_a?(Hash) then m << t
|
84
84
|
else
|
@@ -90,19 +90,19 @@ module RelatonBib
|
|
90
90
|
def language_hash_to_bib(ret)
|
91
91
|
return unless ret[:language]
|
92
92
|
|
93
|
-
ret[:language] = array(ret[:language])
|
93
|
+
ret[:language] = RelatonBib.array(ret[:language])
|
94
94
|
end
|
95
95
|
|
96
96
|
def script_hash_to_bib(ret)
|
97
97
|
return unless ret[:script]
|
98
98
|
|
99
|
-
ret[:script] = array(ret[:script])
|
99
|
+
ret[:script] = RelatonBib.array(ret[:script])
|
100
100
|
end
|
101
101
|
|
102
102
|
def abstract_hash_to_bib(ret)
|
103
103
|
return unless ret[:abstract]
|
104
104
|
|
105
|
-
ret[:abstract] = array(ret[:abstract]).map do |a|
|
105
|
+
ret[:abstract] = RelatonBib.array(ret[:abstract]).map do |a|
|
106
106
|
a.is_a?(String) ? FormattedString.new(content: a) : a
|
107
107
|
end
|
108
108
|
end
|
@@ -110,13 +110,13 @@ module RelatonBib
|
|
110
110
|
def link_hash_to_bib(ret)
|
111
111
|
return unless ret[:link]
|
112
112
|
|
113
|
-
ret[:link] = array(ret[:link])
|
113
|
+
ret[:link] = RelatonBib.array(ret[:link])
|
114
114
|
end
|
115
115
|
|
116
116
|
def place_hash_to_bib(ret)
|
117
117
|
return unless ret[:place]
|
118
118
|
|
119
|
-
ret[:place] = array(ret[:place]).map do |pl|
|
119
|
+
ret[:place] = RelatonBib.array(ret[:place]).map do |pl|
|
120
120
|
pl.is_a?(String) ? Place.new(name: pl) : Place.new(**pl)
|
121
121
|
end
|
122
122
|
end
|
@@ -124,13 +124,13 @@ module RelatonBib
|
|
124
124
|
def accesslocation_hash_to_bib(ret)
|
125
125
|
return unless ret[:accesslocation]
|
126
126
|
|
127
|
-
ret[:accesslocation] = array(ret[:accesslocation])
|
127
|
+
ret[:accesslocation] = RelatonBib.array(ret[:accesslocation])
|
128
128
|
end
|
129
129
|
|
130
130
|
def dates_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
|
131
131
|
return unless ret[:date]
|
132
132
|
|
133
|
-
ret[:date] = array(ret[:date])
|
133
|
+
ret[:date] = RelatonBib.array(ret[:date])
|
134
134
|
ret[:date].each_with_index do |d, i|
|
135
135
|
# value is synonym of on: it is reserved word in YAML
|
136
136
|
if d[:value]
|
@@ -143,28 +143,25 @@ module RelatonBib
|
|
143
143
|
def docid_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
|
144
144
|
return unless ret[:docid]
|
145
145
|
|
146
|
-
ret[:docid] = array(ret[:docid])
|
146
|
+
ret[:docid] = RelatonBib.array(ret[:docid])
|
147
147
|
ret[:docid]&.each_with_index do |id, i|
|
148
|
-
|
149
|
-
ret[:docid][i] = DocumentIdentifier.new(
|
150
|
-
id: id[:id], type: type, scope: id[:scope], primary: id[:primary],
|
151
|
-
)
|
148
|
+
id[:type] ||= id[:id].match(/^\w+(?=\s)/)&.to_s
|
149
|
+
ret[:docid][i] = DocumentIdentifier.new(**id)
|
152
150
|
end
|
153
151
|
end
|
154
152
|
|
155
153
|
def version_hash_to_bib(ret)
|
156
154
|
return unless ret[:version]
|
157
155
|
|
158
|
-
ret[:version]
|
159
|
-
|
160
|
-
|
161
|
-
)
|
156
|
+
ret[:version] = RelatonBib.array(ret[:version]).map do |v|
|
157
|
+
BibliographicItem::Version.new(v[:revision_date], v[:draft])
|
158
|
+
end
|
162
159
|
end
|
163
160
|
|
164
161
|
def biblionote_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
165
162
|
return unless ret[:biblionote]
|
166
163
|
|
167
|
-
ret[:biblionote] = array(ret[:biblionote])
|
164
|
+
ret[:biblionote] = RelatonBib.array(ret[:biblionote])
|
168
165
|
.reduce(BiblioNoteCollection.new([])) do |mem, n|
|
169
166
|
mem << if n.is_a?(String) then BiblioNote.new content: n
|
170
167
|
else BiblioNote.new(**n)
|
@@ -197,11 +194,11 @@ module RelatonBib
|
|
197
194
|
def contributors_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
|
198
195
|
return unless ret[:contributor]
|
199
196
|
|
200
|
-
ret[:contributor] = array(ret[:contributor])
|
197
|
+
ret[:contributor] = RelatonBib.array(ret[:contributor])
|
201
198
|
ret[:contributor]&.each_with_index do |c, i|
|
202
|
-
roles = array(ret[:contributor][i][:role]).map do |r|
|
199
|
+
roles = RelatonBib.array(ret[:contributor][i][:role]).map do |r|
|
203
200
|
if r.is_a? Hash
|
204
|
-
{ type: r[:type], description: array(r[:description]) }
|
201
|
+
{ type: r[:type], description: RelatonBib.array(r[:description]) }
|
205
202
|
# elsif r.is_a? Array
|
206
203
|
# { type: r[0], description: r.fetch(1) }
|
207
204
|
else
|
@@ -219,13 +216,13 @@ module RelatonBib
|
|
219
216
|
end
|
220
217
|
end
|
221
218
|
|
222
|
-
def org_hash_to_bib(org)
|
219
|
+
def org_hash_to_bib(org) # rubocop:disable Metrics/AbcSize
|
223
220
|
return nil if org.nil?
|
224
221
|
|
225
|
-
org[:identifier] = array(org[:identifier])&.map do |a|
|
222
|
+
org[:identifier] = RelatonBib.array(org[:identifier])&.map do |a|
|
226
223
|
OrgIdentifier.new(a[:type], a[:id])
|
227
224
|
end
|
228
|
-
org[:subdivision] = array(org[:subdivision]).map do |sd|
|
225
|
+
org[:subdivision] = RelatonBib.array(org[:subdivision]).map do |sd|
|
229
226
|
LocalizedString.new sd
|
230
227
|
end
|
231
228
|
org[:contact] = contacts_hash_to_bib(org)
|
@@ -244,17 +241,17 @@ module RelatonBib
|
|
244
241
|
def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
245
242
|
n = person[:name]
|
246
243
|
FullName.new(
|
247
|
-
forename: array(n[:forename])&.map { |f| localname(f, person) },
|
248
|
-
initial: array(n[:initial])&.map { |f| localname(f, person) },
|
249
|
-
addition: array(n[:addition])&.map { |f| localname(f, person) },
|
250
|
-
prefix: array(n[:prefix])&.map { |f| localname(f, person) },
|
244
|
+
forename: RelatonBib.array(n[:forename])&.map { |f| localname(f, person) },
|
245
|
+
initial: RelatonBib.array(n[:initial])&.map { |f| localname(f, person) },
|
246
|
+
addition: RelatonBib.array(n[:addition])&.map { |f| localname(f, person) },
|
247
|
+
prefix: RelatonBib.array(n[:prefix])&.map { |f| localname(f, person) },
|
251
248
|
surname: localname(n[:surname], person),
|
252
249
|
completename: localname(n[:completename], person),
|
253
250
|
)
|
254
251
|
end
|
255
252
|
|
256
253
|
def person_identifiers_hash_to_bib(person)
|
257
|
-
array(person[:identifier])&.map do |a|
|
254
|
+
RelatonBib.array(person[:identifier])&.map do |a|
|
258
255
|
PersonIdentifier.new(a[:type], a[:id])
|
259
256
|
end
|
260
257
|
end
|
@@ -262,8 +259,8 @@ module RelatonBib
|
|
262
259
|
def affiliation_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
263
260
|
return [] unless person[:affiliation]
|
264
261
|
|
265
|
-
array(person[:affiliation]).map do |a|
|
266
|
-
a[:description] = array(a[:description])&.map do |d|
|
262
|
+
RelatonBib.array(person[:affiliation]).map do |a|
|
263
|
+
a[:description] = RelatonBib.array(a[:description])&.map do |d|
|
267
264
|
cnt = if d.is_a?(Hash)
|
268
265
|
{ content: d[:content], language: d[:language],
|
269
266
|
script: d[:script], format: d[:format] }
|
@@ -281,14 +278,20 @@ module RelatonBib
|
|
281
278
|
def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
282
279
|
return [] unless entity[:contact]
|
283
280
|
|
284
|
-
array(entity[:contact]).map do |a|
|
285
|
-
if a[:city] || a[:country]
|
281
|
+
RelatonBib.array(entity[:contact]).map do |a|
|
282
|
+
if a[:city] || a[:country] # it's for old version compatibility, should be removed in the future
|
286
283
|
RelatonBib::Address.new(
|
287
284
|
street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
|
288
285
|
country: a[:country], state: a[:state]
|
289
286
|
)
|
290
|
-
|
287
|
+
elsif a[:address]
|
288
|
+
a[:address][:street] = RelatonBib.array(a[:address][:street])
|
289
|
+
RelatonBib::Address.new(**a[:address])
|
290
|
+
elsif a[:type] # it's for old version compatibility, should be removed in the future
|
291
291
|
RelatonBib::Contact.new(type: a[:type], value: a[:value])
|
292
|
+
else
|
293
|
+
type, value = a.flatten
|
294
|
+
RelatonBib::Contact.new(type: type.to_s, value: value)
|
292
295
|
end
|
293
296
|
end
|
294
297
|
end
|
@@ -297,8 +300,8 @@ module RelatonBib
|
|
297
300
|
def copyright_hash_to_bib(ret)
|
298
301
|
return unless ret[:copyright]
|
299
302
|
|
300
|
-
ret[:copyright] = array(ret[:copyright]).map do |c|
|
301
|
-
c[:owner] = array(c[:owner])
|
303
|
+
ret[:copyright] = RelatonBib.array(ret[:copyright]).map do |c|
|
304
|
+
c[:owner] = RelatonBib.array(c[:owner])
|
302
305
|
c
|
303
306
|
end
|
304
307
|
end
|
@@ -307,7 +310,7 @@ module RelatonBib
|
|
307
310
|
def relations_hash_to_bib(ret)
|
308
311
|
return unless ret[:relation]
|
309
312
|
|
310
|
-
ret[:relation] = array(ret[:relation])
|
313
|
+
ret[:relation] = RelatonBib.array(ret[:relation])
|
311
314
|
ret[:relation]&.each do |r|
|
312
315
|
if r[:description]
|
313
316
|
r[:description] = FormattedString.new(**r[:description])
|
@@ -321,7 +324,7 @@ module RelatonBib
|
|
321
324
|
# @param rel [Hash] relation
|
322
325
|
def relation_bibitem_hash_to_bib(rel)
|
323
326
|
if rel[:bibitem]
|
324
|
-
rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem]
|
327
|
+
rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem])
|
325
328
|
else
|
326
329
|
warn "[relaton-bib] bibitem missing: #{rel}"
|
327
330
|
rel[:bibitem] = nil
|
@@ -337,14 +340,15 @@ module RelatonBib
|
|
337
340
|
# @param rel [Hash] relation
|
338
341
|
# @return [RelatonBib::LocalityStack]
|
339
342
|
def relation_locality_hash_to_bib(rel)
|
340
|
-
rel[:locality] = array(rel[:locality])&.map do |bl|
|
343
|
+
rel[:locality] = RelatonBib.array(rel[:locality])&.map do |bl|
|
341
344
|
LocalityStack.new locality_locality_stack(bl)
|
342
345
|
end
|
343
346
|
end
|
344
347
|
|
345
348
|
def locality_locality_stack(lls)
|
346
349
|
if lls[:locality_stack]
|
347
|
-
array(lls[:locality_stack]).map do |
|
350
|
+
RelatonBib.array(lls[:locality_stack]).map do |lc|
|
351
|
+
l = lc[:locality] || lc
|
348
352
|
Locality.new(l[:type], l[:reference_from], l[:reference_to])
|
349
353
|
end
|
350
354
|
else
|
@@ -354,9 +358,9 @@ module RelatonBib
|
|
354
358
|
|
355
359
|
# @param rel [Hash] relation
|
356
360
|
def relation_source_locality_hash_to_bib(rel) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
357
|
-
rel[:source_locality] = array(rel[:source_locality])&.map do |sl|
|
361
|
+
rel[:source_locality] = RelatonBib.array(rel[:source_locality])&.map do |sl|
|
358
362
|
sls = if sl[:source_locality_stack]
|
359
|
-
array(sl[:source_locality_stack]).map do |l|
|
363
|
+
RelatonBib.array(sl[:source_locality_stack]).map do |l|
|
360
364
|
SourceLocality.new(l[:type], l[:reference_from],
|
361
365
|
l[:reference_to])
|
362
366
|
end
|
@@ -371,7 +375,7 @@ module RelatonBib
|
|
371
375
|
|
372
376
|
# @param ret [Hash]
|
373
377
|
def series_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
374
|
-
ret[:series] = array(ret[:series])&.map do |s|
|
378
|
+
ret[:series] = RelatonBib.array(ret[:series])&.map do |s|
|
375
379
|
s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
|
376
380
|
if s[:title]
|
377
381
|
s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
|
@@ -397,7 +401,7 @@ module RelatonBib
|
|
397
401
|
# @param ret [Hash]
|
398
402
|
def classification_hash_to_bib(ret)
|
399
403
|
if ret[:classification]
|
400
|
-
ret[:classification] = array(ret[:classification]).map do |cls|
|
404
|
+
ret[:classification] = RelatonBib.array(ret[:classification]).map do |cls|
|
401
405
|
Classification.new(**cls)
|
402
406
|
end
|
403
407
|
end
|
@@ -431,7 +435,7 @@ module RelatonBib
|
|
431
435
|
def editorialgroup_hash_to_bib(ret)
|
432
436
|
return unless ret[:editorialgroup]
|
433
437
|
|
434
|
-
technical_committee = array(ret[:editorialgroup]).map do |wg|
|
438
|
+
technical_committee = RelatonBib.array(ret[:editorialgroup]).map do |wg|
|
435
439
|
TechnicalCommittee.new WorkGroup.new(**wg)
|
436
440
|
end
|
437
441
|
ret[:editorialgroup] = EditorialGroup.new technical_committee
|
@@ -441,15 +445,15 @@ module RelatonBib
|
|
441
445
|
def ics_hash_to_bib(ret)
|
442
446
|
return unless ret[:ics]
|
443
447
|
|
444
|
-
ret[:ics] = array(ret[:ics]).map { |ics| ICS.new(**ics) }
|
448
|
+
ret[:ics] = RelatonBib.array(ret[:ics]).map { |ics| ICS.new(**ics) }
|
445
449
|
end
|
446
450
|
|
447
451
|
# @param ret [Hash]
|
448
452
|
def structuredidentifier_hash_to_bib(ret)
|
449
453
|
return unless ret[:structuredidentifier]
|
450
454
|
|
451
|
-
sids = array(ret[:structuredidentifier]).map do |si|
|
452
|
-
si[:agency] = array si[:agency]
|
455
|
+
sids = RelatonBib.array(ret[:structuredidentifier]).map do |si|
|
456
|
+
si[:agency] = RelatonBib.array si[:agency]
|
453
457
|
StructuredIdentifier.new(**si)
|
454
458
|
end
|
455
459
|
ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
|
@@ -469,15 +473,6 @@ module RelatonBib
|
|
469
473
|
end
|
470
474
|
end
|
471
475
|
|
472
|
-
# @param arr [NilClass, Array, #is_a?]
|
473
|
-
# @return [Array]
|
474
|
-
def array(arr)
|
475
|
-
return [] unless arr
|
476
|
-
return [arr] unless arr.is_a?(Array)
|
477
|
-
|
478
|
-
arr
|
479
|
-
end
|
480
|
-
|
481
476
|
# @param name [Hash, String, NilClass]
|
482
477
|
# @param person [Hash]
|
483
478
|
# @return [RelatonBib::LocalizedString]
|
data/lib/relaton_bib/series.rb
CHANGED
@@ -13,7 +13,7 @@ module RelatonBib
|
|
13
13
|
# @return [RelatonBib::FormattedRef, nil]
|
14
14
|
attr_reader :formattedref
|
15
15
|
|
16
|
-
# @return [RelatonBib::TypedTitleString
|
16
|
+
# @return [RelatonBib::TypedTitleString] title
|
17
17
|
attr_reader :title
|
18
18
|
|
19
19
|
# @return [String, nil]
|
@@ -26,8 +26,7 @@ module RelatonBib
|
|
26
26
|
|
27
27
|
# @param type [String, nil]
|
28
28
|
# @param formattedref [RelatonBib::FormattedRef, nil]
|
29
|
-
# @param title [RelatonBib::TypedTitleString
|
30
|
-
# formattedref argument should be passed
|
29
|
+
# @param title [RelatonBib::TypedTitleString] title
|
31
30
|
# @param place [String, nil]
|
32
31
|
# @param orgaization [String, nil]
|
33
32
|
# @param abbreviation [RelatonBib::LocalizedString, nil]
|
@@ -37,9 +36,8 @@ module RelatonBib
|
|
37
36
|
# @param partnumber [String, nil]
|
38
37
|
# @param run [String, nil]
|
39
38
|
def initialize(**args)
|
40
|
-
unless args[:title].is_a?(RelatonBib::TypedTitleString)
|
41
|
-
|
42
|
-
raise ArgumentError, "argument `title` or `formattedref` should present"
|
39
|
+
unless args[:title].is_a?(RelatonBib::TypedTitleString)
|
40
|
+
raise ArgumentError, "argument `title` should present in series"
|
43
41
|
end
|
44
42
|
|
45
43
|
# if args[:type] && !TYPES.include?(args[:type])
|
@@ -65,19 +63,16 @@ module RelatonBib
|
|
65
63
|
# @param builder [Nokogiri::XML::Builder]
|
66
64
|
def to_xml(builder) # rubocop:disable Metrics/MethodLength
|
67
65
|
xml = builder.series do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
builder.partnumber partnumber if partnumber
|
79
|
-
builder.run run if run
|
80
|
-
end
|
66
|
+
formattedref&.to_xml builder
|
67
|
+
builder.title { title.to_xml builder }
|
68
|
+
builder.place place if place
|
69
|
+
builder.organization organization if organization
|
70
|
+
builder.abbreviation { abbreviation.to_xml builder } if abbreviation
|
71
|
+
builder.from from if from
|
72
|
+
builder.to to if to
|
73
|
+
builder.number number if number
|
74
|
+
builder.partnumber partnumber if partnumber
|
75
|
+
builder.run run if run
|
81
76
|
end
|
82
77
|
xml[:type] = type if type
|
83
78
|
end
|
@@ -89,7 +84,7 @@ module RelatonBib
|
|
89
84
|
hash = {}
|
90
85
|
hash["type"] = type if type
|
91
86
|
hash["formattedref"] = formattedref.to_hash if formattedref
|
92
|
-
hash["title"] = title.to_hash
|
87
|
+
hash["title"] = title.to_hash
|
93
88
|
hash["place"] = place if place
|
94
89
|
hash["organization"] = organization if organization
|
95
90
|
hash["abbreviation"] = abbreviation.to_hash if abbreviation
|
@@ -109,7 +104,7 @@ module RelatonBib
|
|
109
104
|
out = count > 1 ? "#{pref}::\n" : ""
|
110
105
|
out += "#{pref}.type:: #{type}\n" if type
|
111
106
|
out += formattedref.to_asciibib pref if formattedref
|
112
|
-
out += title.to_asciibib pref
|
107
|
+
out += title.to_asciibib pref
|
113
108
|
out += "#{pref}.place:: #{place}\n" if place
|
114
109
|
out += "#{pref}.organization:: #{organization}\n" if organization
|
115
110
|
out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -33,7 +33,7 @@ module RelatonBib
|
|
33
33
|
docnumber: bibitem.at("./docnumber")&.text,
|
34
34
|
date: fetch_dates(bibitem),
|
35
35
|
contributor: fetch_contributors(bibitem),
|
36
|
-
edition: bibitem
|
36
|
+
edition: fetch_edition(bibitem),
|
37
37
|
version: fetch_version(bibitem),
|
38
38
|
biblionote: fetch_note(bibitem),
|
39
39
|
language: fetch_language(bibitem),
|
@@ -62,12 +62,18 @@ module RelatonBib
|
|
62
62
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
63
63
|
|
64
64
|
def fetch_version(item)
|
65
|
-
|
66
|
-
|
65
|
+
item.xpath("./version").map do |v|
|
66
|
+
revision_date = v.at("revision-date")&.text
|
67
|
+
draft = v.at("draft")&.text
|
68
|
+
RelatonBib::BibliographicItem::Version.new revision_date, draft
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def fetch_edition(item)
|
73
|
+
edt = item.at("./edition")
|
74
|
+
return unless edt
|
67
75
|
|
68
|
-
|
69
|
-
draft = version.xpath("draft").map &:text
|
70
|
-
RelatonBib::BibliographicItem::Version.new revision_date, draft
|
76
|
+
Edition.new content: edt.text, number: edt[:number]
|
71
77
|
end
|
72
78
|
|
73
79
|
def fetch_place(item)
|
@@ -189,10 +195,11 @@ module RelatonBib
|
|
189
195
|
# @param item [Nokogiri::XML::Element]
|
190
196
|
# @return [Array<RelatonBib::DocumentIdentifier>]
|
191
197
|
def fetch_docid(item)
|
192
|
-
item.xpath("./docidentifier").map do |
|
193
|
-
|
194
|
-
|
195
|
-
|
198
|
+
item.xpath("./docidentifier").map do |id|
|
199
|
+
did = id.to_h.transform_keys(&:to_sym)
|
200
|
+
did[:id] = id.text
|
201
|
+
did[:primary] = id[:primary] == "true" ? true : nil
|
202
|
+
DocumentIdentifier.new(**did)
|
196
203
|
end
|
197
204
|
end
|
198
205
|
|
data/lib/relaton_bib.rb
CHANGED
@@ -36,6 +36,31 @@ module RelatonBib
|
|
36
36
|
str ? $~[:date] : Date.strptime($~[:date], "%Y")
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
# @param arr [NilClass, Array, #is_a?]
|
41
|
+
# @return [Array]
|
42
|
+
def array(arr)
|
43
|
+
return [] unless arr
|
44
|
+
return [arr] unless arr.is_a?(Array)
|
45
|
+
|
46
|
+
arr
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Parse yaml content
|
51
|
+
#
|
52
|
+
# @param [String] yaml content
|
53
|
+
#
|
54
|
+
# @return [Hash] data
|
55
|
+
#
|
56
|
+
def parse_yaml(yaml, classes = [])
|
57
|
+
# Newer versions of Psych uses the `permitted_classes:` parameter
|
58
|
+
if YAML.method(:safe_load).parameters.map(&:last).include? :permitted_classes
|
59
|
+
YAML.safe_load(yaml, permitted_classes: classes)
|
60
|
+
else
|
61
|
+
YAML.safe_load(yaml, classes)
|
62
|
+
end
|
63
|
+
end
|
39
64
|
end
|
40
65
|
|
41
66
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-bib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- lib/relaton_bib/document_relation.rb
|
250
250
|
- lib/relaton_bib/document_relation_collection.rb
|
251
251
|
- lib/relaton_bib/document_status.rb
|
252
|
+
- lib/relaton_bib/edition.rb
|
252
253
|
- lib/relaton_bib/editorial_group.rb
|
253
254
|
- lib/relaton_bib/formatted_ref.rb
|
254
255
|
- lib/relaton_bib/formatted_string.rb
|