relaton-bib 1.2.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ubuntu.yml +1 -0
- data/.rubocop.yml +2 -2
- data/README.adoc +60 -18
- data/grammars/isodoc.rng +130 -21
- data/grammars/reqt.rng +2 -8
- data/lib/relaton_bib.rb +15 -15
- data/lib/relaton_bib/bib_item_locality.rb +13 -1
- data/lib/relaton_bib/biblio_note.rb +11 -0
- data/lib/relaton_bib/biblio_version.rb +12 -0
- data/lib/relaton_bib/bibliographic_date.rb +13 -0
- data/lib/relaton_bib/bibliographic_item.rb +93 -25
- data/lib/relaton_bib/classification.rb +11 -0
- data/lib/relaton_bib/contribution_info.rb +27 -1
- data/lib/relaton_bib/contributor.rb +55 -1
- data/lib/relaton_bib/copyright_association.rb +14 -1
- data/lib/relaton_bib/document_identifier.rb +49 -9
- data/lib/relaton_bib/document_relation.rb +14 -4
- data/lib/relaton_bib/document_relation_collection.rb +12 -0
- data/lib/relaton_bib/document_status.rb +10 -0
- data/lib/relaton_bib/editorial_group.rb +14 -0
- data/lib/relaton_bib/formatted_ref.rb +7 -0
- data/lib/relaton_bib/formatted_string.rb +11 -0
- data/lib/relaton_bib/hash_converter.rb +55 -36
- data/lib/relaton_bib/ics.rb +11 -0
- data/lib/relaton_bib/localized_string.rb +23 -6
- data/lib/relaton_bib/medium.rb +11 -0
- data/lib/relaton_bib/organization.rb +27 -7
- data/lib/relaton_bib/person.rb +54 -7
- data/lib/relaton_bib/place.rb +13 -1
- data/lib/relaton_bib/series.rb +25 -4
- data/lib/relaton_bib/structured_identifier.rb +30 -0
- data/lib/relaton_bib/technical_committee.rb +11 -0
- data/lib/relaton_bib/typed_title_string.rb +13 -7
- data/lib/relaton_bib/typed_uri.rb +11 -0
- data/lib/relaton_bib/validity.rb +11 -0
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/workgroup.rb +10 -0
- data/lib/relaton_bib/xml_parser.rb +54 -39
- metadata +5 -5
data/lib/relaton_bib.rb
CHANGED
@@ -10,31 +10,31 @@ module RelatonBib
|
|
10
10
|
class RequestError < StandardError; end
|
11
11
|
|
12
12
|
class << self
|
13
|
-
#
|
14
|
-
|
15
|
-
# @param date [String]
|
13
|
+
# @param date [String, Integer, Date]
|
16
14
|
# @return [Date, NilClass]
|
17
|
-
def parse_date(
|
18
|
-
if
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
def parse_date(date) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
16
|
+
return date if date.is_a?(Date)
|
17
|
+
|
18
|
+
sdate = date.to_s
|
19
|
+
case sdate
|
20
|
+
when /(?<date>\w+\s\d{4})/ # February 2012
|
21
|
+
Date.strptime($~[:date], "%B %Y")
|
22
|
+
when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012
|
23
|
+
Date.strptime($~[:date], "%B %d, %Y")
|
24
|
+
when /(?<date>\d{4}-\d{2}-\d{2})/ # 2012-02-11
|
25
|
+
Date.parse($~[:date])
|
26
|
+
when /(?<date>\d{4}-\d{2})/ # 2012-02
|
26
27
|
Date.strptime date, "%Y-%m"
|
27
|
-
|
28
|
+
when /(?<date>\d{4})/ then Date.strptime $~[:date], "%Y" # 2012
|
28
29
|
end
|
29
30
|
end
|
30
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
31
31
|
end
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
35
|
# @param array [Array]
|
36
36
|
# @return [Array<String>, String]
|
37
|
-
def single_element_array(array)
|
37
|
+
def single_element_array(array) # rubocop:disable Metrics/CyclomaticComplexity
|
38
38
|
if array.size > 1
|
39
39
|
array.map { |e| e.is_a?(String) ? e : e.to_hash }
|
40
40
|
else
|
@@ -17,7 +17,7 @@ module RelatonBib
|
|
17
17
|
type_ptrn = %r{section|clause|part|paragraph|chapter|page|whole|table|
|
18
18
|
annex|figure|note|list|example|volume|issue|time|
|
19
19
|
locality:[a-zA-Z0-9_]+}x
|
20
|
-
unless type
|
20
|
+
unless type.match? type_ptrn
|
21
21
|
warn "[relaton-bib] WARNING: invalid locality type: #{type}"
|
22
22
|
end
|
23
23
|
|
@@ -39,6 +39,18 @@ module RelatonBib
|
|
39
39
|
hash["reference_to"] = reference_to if reference_to
|
40
40
|
hash
|
41
41
|
end
|
42
|
+
|
43
|
+
# @param prefix [String]
|
44
|
+
# @param count [Integeg] number of localities
|
45
|
+
# @return [String]
|
46
|
+
def to_asciibib(prefix = "", count = 1)
|
47
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
48
|
+
out = count > 1 ? "#{prefix}::\n" : ""
|
49
|
+
out += "#{pref}type:: #{type}\n"
|
50
|
+
out += "#{pref}reference_from:: #{reference_from}\n"
|
51
|
+
out += "#{pref}reference_to:: #{reference_to}\n" if reference_to
|
52
|
+
out
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
56
|
class Locality < BibItemLocality
|
@@ -29,5 +29,16 @@ module RelatonBib
|
|
29
29
|
hash["type"] = type
|
30
30
|
hash
|
31
31
|
end
|
32
|
+
|
33
|
+
# @param prefix [String]
|
34
|
+
# @param count [Integer] number of notes
|
35
|
+
# @return [String]
|
36
|
+
def to_asciibib(prefix = "", count = 1)
|
37
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
38
|
+
out = count > 1 ? "#{pref}biblionote::\n" : ""
|
39
|
+
out + "#{pref}biblionote.type:: #{type}\n" if type
|
40
|
+
out += super "#{pref}biblionote"
|
41
|
+
out
|
42
|
+
end
|
32
43
|
end
|
33
44
|
end
|
@@ -32,6 +32,18 @@ module RelatonBib
|
|
32
32
|
hash["draft"] = single_element_array(draft) if draft&.any?
|
33
33
|
hash
|
34
34
|
end
|
35
|
+
|
36
|
+
# @param prefix [String]
|
37
|
+
# @return [String]
|
38
|
+
def to_asciibib(prefix = "")
|
39
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
40
|
+
out = ""
|
41
|
+
if revision_date
|
42
|
+
out += "#{pref}version.revision_date:: #{revision_date}\n"
|
43
|
+
end
|
44
|
+
draft&.each { |d| out += "#{pref}version.draft:: #{d}\n" }
|
45
|
+
out
|
46
|
+
end
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
@@ -60,6 +60,19 @@ module RelatonBib
|
|
60
60
|
hash
|
61
61
|
end
|
62
62
|
|
63
|
+
# @param prefix [String]
|
64
|
+
# @param count [Integer] number of dates
|
65
|
+
# @return [String]
|
66
|
+
def to_asciibib(prefix = "", count = 1)
|
67
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
68
|
+
out = count > 1 ? "#{pref}date::\n" : ""
|
69
|
+
out += "#{pref}date.type:: #{type}\n"
|
70
|
+
out += "#{pref}date.on:: #{on}\n" if on
|
71
|
+
out += "#{pref}date.from:: #{from}\n" if from
|
72
|
+
out += "#{pref}date.to:: #{to}\n" if to
|
73
|
+
out
|
74
|
+
end
|
75
|
+
|
63
76
|
private
|
64
77
|
|
65
78
|
# Formats date
|
@@ -237,13 +237,18 @@ module RelatonBib
|
|
237
237
|
end
|
238
238
|
@series = args.fetch :series, []
|
239
239
|
@medium = args[:medium]
|
240
|
-
@place = args.fetch(:place, []).map
|
240
|
+
@place = args.fetch(:place, []).map do |pl|
|
241
|
+
pl.is_a?(String) ? Place.new(name: pl) : pl
|
242
|
+
end
|
241
243
|
@extent = args[:extent] || []
|
242
244
|
@accesslocation = args.fetch :accesslocation, []
|
243
245
|
@classification = args.fetch :classification, []
|
244
246
|
@validity = args[:validity]
|
245
|
-
|
246
|
-
@
|
247
|
+
# we should pass the fetched arg from scrappers
|
248
|
+
@fetched = args.fetch :fetched, nil
|
249
|
+
@keyword = (args[:keyword] || []).map do |kw|
|
250
|
+
LocalizedString.new(kw)
|
251
|
+
end
|
247
252
|
@license = args.fetch :license, []
|
248
253
|
@doctype = args[:doctype]
|
249
254
|
@editorialgroup = args[:editorialgroup]
|
@@ -263,6 +268,9 @@ module RelatonBib
|
|
263
268
|
end
|
264
269
|
end
|
265
270
|
|
271
|
+
# @param id [RelatonBib::DocumentIdentifier]
|
272
|
+
# @param attribute [boolean, nil]
|
273
|
+
# @return [String]
|
266
274
|
def makeid(id, attribute)
|
267
275
|
return nil if attribute && !@id_attribute
|
268
276
|
|
@@ -277,8 +285,12 @@ module RelatonBib
|
|
277
285
|
idstr.strip
|
278
286
|
end
|
279
287
|
|
288
|
+
# @param identifier [RelatonBib::DocumentIdentifier]
|
289
|
+
# @param options [Hash]
|
290
|
+
# @option options [boolean, nil] :no_year
|
291
|
+
# @option options [boolean, nil] :all_parts
|
280
292
|
# @return [String]
|
281
|
-
def shortref(identifier, **opts)
|
293
|
+
def shortref(identifier, **opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
|
282
294
|
pubdate = date.select { |d| d.type == "published" }
|
283
295
|
year = if opts[:no_year] || pubdate.empty? then ""
|
284
296
|
else ":" + pubdate&.first&.on&.year.to_s
|
@@ -300,10 +312,8 @@ module RelatonBib
|
|
300
312
|
end
|
301
313
|
end
|
302
314
|
|
303
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
304
|
-
|
305
315
|
# @return [Hash]
|
306
|
-
def to_hash
|
316
|
+
def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
307
317
|
hash = {}
|
308
318
|
hash["id"] = id if id
|
309
319
|
hash["title"] = single_element_array(title) if title&.any?
|
@@ -312,7 +322,9 @@ module RelatonBib
|
|
312
322
|
hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
|
313
323
|
hash["docnumber"] = docnumber if docnumber
|
314
324
|
hash["date"] = single_element_array(date) if date&.any?
|
315
|
-
|
325
|
+
if contributor&.any?
|
326
|
+
hash["contributor"] = single_element_array(contributor)
|
327
|
+
end
|
316
328
|
hash["edition"] = edition if edition
|
317
329
|
hash["version"] = version.to_hash if version
|
318
330
|
hash["revdate"] = revdate if revdate
|
@@ -328,25 +340,30 @@ module RelatonBib
|
|
328
340
|
hash["medium"] = medium.to_hash if medium
|
329
341
|
hash["place"] = single_element_array(place) if place&.any?
|
330
342
|
hash["extent"] = single_element_array(extent) if extent&.any?
|
331
|
-
|
332
|
-
|
343
|
+
if accesslocation&.any?
|
344
|
+
hash["accesslocation"] = single_element_array(accesslocation)
|
345
|
+
end
|
346
|
+
if classification&.any?
|
347
|
+
hash["classification"] = single_element_array(classification)
|
348
|
+
end
|
333
349
|
hash["validity"] = validity.to_hash if validity
|
334
350
|
hash["fetched"] = fetched.to_s if fetched
|
335
351
|
hash["keyword"] = single_element_array(keyword) if keyword&.any?
|
336
352
|
hash["license"] = single_element_array(license) if license&.any?
|
337
353
|
hash["doctype"] = doctype if doctype
|
338
|
-
|
354
|
+
if editorialgroup&.presence?
|
355
|
+
hash["editorialgroup"] = editorialgroup.to_hash
|
356
|
+
end
|
339
357
|
hash["ics"] = single_element_array ics if ics.any?
|
340
358
|
if structuredidentifier&.presence?
|
341
359
|
hash["structuredidentifier"] = structuredidentifier.to_hash
|
342
360
|
end
|
343
361
|
hash
|
344
362
|
end
|
345
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
346
363
|
|
347
364
|
# @param bibtex [BibTeX::Bibliography, NilClass]
|
348
365
|
# @return [String]
|
349
|
-
def to_bibtex(bibtex = nil)
|
366
|
+
def to_bibtex(bibtex = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
350
367
|
item = BibTeX::Entry.new
|
351
368
|
item.type = bibtex_type
|
352
369
|
item.key = id
|
@@ -369,7 +386,6 @@ module RelatonBib
|
|
369
386
|
bibtex << item
|
370
387
|
bibtex.to_s
|
371
388
|
end
|
372
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
373
389
|
|
374
390
|
# @param lang [String] language code Iso639
|
375
391
|
# @return [Array<RelatonIsoBib::TypedTitleString>]
|
@@ -391,7 +407,7 @@ module RelatonBib
|
|
391
407
|
|
392
408
|
def deep_clone
|
393
409
|
dump = Marshal.dump self
|
394
|
-
Marshal.load dump
|
410
|
+
Marshal.load dump # rubocop:disable Security/MarshalLoad
|
395
411
|
end
|
396
412
|
|
397
413
|
def disable_id_attribute
|
@@ -399,17 +415,19 @@ module RelatonBib
|
|
399
415
|
end
|
400
416
|
|
401
417
|
# remove title part components and abstract
|
402
|
-
def to_all_parts
|
418
|
+
def to_all_parts # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
|
403
419
|
me = deep_clone
|
404
420
|
me.disable_id_attribute
|
405
|
-
me.relation <<
|
406
|
-
type: "instance", bibitem: self,
|
407
|
-
)
|
421
|
+
me.relation << DocumentRelation.new(type: "instance", bibitem: self)
|
408
422
|
me.language.each do |l|
|
409
423
|
me.title.delete_if { |t| t.type == "title-part" }
|
410
|
-
ttl = me.title.select
|
424
|
+
ttl = me.title.select do |t|
|
425
|
+
t.type != "main" && t.title.language&.include?(l)
|
426
|
+
end
|
411
427
|
tm_en = ttl.map { |t| t.title.content }.join " – "
|
412
|
-
me.title.detect
|
428
|
+
me.title.detect do |t|
|
429
|
+
t.type == "main" && t.title.language&.include?(l)
|
430
|
+
end&.title&.content = tm_en
|
413
431
|
end
|
414
432
|
me.abstract = []
|
415
433
|
me.docidentifier.each(&:remove_part)
|
@@ -440,7 +458,7 @@ module RelatonBib
|
|
440
458
|
|
441
459
|
# If revision_date exists then returns it else returns published date or nil
|
442
460
|
# @return [String, NilClass]
|
443
|
-
def revdate
|
461
|
+
def revdate # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
444
462
|
@revdate ||= if version&.revision_date
|
445
463
|
version.revision_date
|
446
464
|
else
|
@@ -448,6 +466,53 @@ module RelatonBib
|
|
448
466
|
end
|
449
467
|
end
|
450
468
|
|
469
|
+
# @param prefix [String]
|
470
|
+
# @return [String]
|
471
|
+
def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
472
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
473
|
+
out = prefix.empty? ? "[%bibitem]\n== {blank}\n" : ""
|
474
|
+
out += "#{pref}id:: #{id}\n" if id
|
475
|
+
out += "#{pref}fetched:: #{fetched}\n" if fetched
|
476
|
+
title.each { |t| out += t.to_asciibib(prefix, title.size) }
|
477
|
+
out += "#{pref}type:: #{type}\n" if type
|
478
|
+
docidentifier.each do |di|
|
479
|
+
out += di.to_asciibib prefix, docidentifier.size
|
480
|
+
end
|
481
|
+
out += "#{pref}docnumber:: #{docnumber}\n" if docnumber
|
482
|
+
out += "#{pref}edition:: #{edition}\n" if edition
|
483
|
+
language.each { |l| out += "#{pref}language:: #{l}\n" }
|
484
|
+
script.each { |s| out += "#{pref}script:: #{s}\n" }
|
485
|
+
out += version.to_asciibib prefix if version
|
486
|
+
biblionote&.each { |b| out += b.to_asciibib prefix, biblionote.size }
|
487
|
+
out += status.to_asciibib prefix if status
|
488
|
+
date.each { |d| out += d.to_asciibib prefix, date.size }
|
489
|
+
abstract.each do |a|
|
490
|
+
out += a.to_asciibib "#{pref}abstract", abstract.size
|
491
|
+
end
|
492
|
+
copyright.each { |c| out += c.to_asciibib prefix, copyright.size }
|
493
|
+
link.each { |l| out += l.to_asciibib prefix, link.size }
|
494
|
+
out += medium.to_asciibib prefix if medium
|
495
|
+
place.each { |pl| out += pl.to_asciibib prefix, place.size }
|
496
|
+
extent.each { |ex| out += ex.to_asciibib "#{pref}extent", extent.size }
|
497
|
+
accesslocation.each { |al| out += "#{pref}accesslocation:: #{al}\n" }
|
498
|
+
classification.each do |cl|
|
499
|
+
out += cl.to_asciibib prefix, classification.size
|
500
|
+
end
|
501
|
+
out += validity.to_asciibib prefix if validity
|
502
|
+
contributor.each do |c|
|
503
|
+
out += c.to_asciibib "contributor.*", contributor.size
|
504
|
+
end
|
505
|
+
out += relation.to_asciibib prefix if relation
|
506
|
+
series.each { |s| out += s.to_asciibib prefix, series.size }
|
507
|
+
out += "#{pref}doctype:: #{doctype}\n" if doctype
|
508
|
+
out += "#{pref}formattedref:: #{formattedref}\n" if formattedref
|
509
|
+
keyword.each { |kw| out += kw.to_asciibib "#{pref}keyword", keyword.size }
|
510
|
+
out += editorialgroup.to_asciibib prefix if editorialgroup
|
511
|
+
ics.each { |i| out += i.to_asciibib prefix, ics.size }
|
512
|
+
out += structuredidentifier.to_asciibib prefix if structuredidentifier
|
513
|
+
out
|
514
|
+
end
|
515
|
+
|
451
516
|
private
|
452
517
|
|
453
518
|
# @return [String]
|
@@ -470,7 +535,7 @@ module RelatonBib
|
|
470
535
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
471
536
|
|
472
537
|
# @param [BibTeX::Entry]
|
473
|
-
def bibtex_author(item)
|
538
|
+
def bibtex_author(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
474
539
|
authors = contributor.select do |c|
|
475
540
|
c.entity.is_a?(Person) && c.role.map(&:type).include?("author")
|
476
541
|
end.map &:entity
|
@@ -487,7 +552,7 @@ module RelatonBib
|
|
487
552
|
end
|
488
553
|
|
489
554
|
# @param [BibTeX::Entry]
|
490
|
-
def bibtex_contributor(item)
|
555
|
+
def bibtex_contributor(item) # rubocop:disable Metrics/CyclomaticComplexity
|
491
556
|
contributor.each do |c|
|
492
557
|
rls = c.role.map(&:type)
|
493
558
|
if rls.include?("publisher") then item.publisher = c.entity.name
|
@@ -504,7 +569,7 @@ module RelatonBib
|
|
504
569
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
505
570
|
|
506
571
|
# @param [BibTeX::Entry]
|
507
|
-
def bibtex_note(item)
|
572
|
+
def bibtex_note(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
|
508
573
|
biblionote.each do |n|
|
509
574
|
case n.type
|
510
575
|
when "annote" then item.annote = n.content
|
@@ -621,6 +686,9 @@ module RelatonBib
|
|
621
686
|
builder.edition edition if edition
|
622
687
|
version&.to_xml builder
|
623
688
|
biblionote.each { |n| n.to_xml builder }
|
689
|
+
opts[:note]&.each do |n|
|
690
|
+
builder.note(n[:text], format: "text/plain", type: n[:type])
|
691
|
+
end
|
624
692
|
language.each { |l| builder.language l }
|
625
693
|
script.each { |s| builder.script s }
|
626
694
|
abstract.each { |a| builder.abstract { a.to_xml(builder) } }
|
@@ -25,5 +25,16 @@ module RelatonBib
|
|
25
25
|
hash["type"] = type if type
|
26
26
|
hash
|
27
27
|
end
|
28
|
+
|
29
|
+
# @param prefix [String]
|
30
|
+
# @param count [Integer] number of classifications
|
31
|
+
# @return [String]
|
32
|
+
def to_asciibib(prefix = "", count = 1)
|
33
|
+
pref = prefix.empty? ? "classification" : prefix + ".classification"
|
34
|
+
out = count > 1 ? "#{pref}::\n" : ""
|
35
|
+
out += "#{pref}.type:: #{type}\n" if type
|
36
|
+
out += "#{pref}.value:: #{value}\n"
|
37
|
+
out
|
38
|
+
end
|
28
39
|
end
|
29
40
|
end
|
@@ -26,7 +26,9 @@ module RelatonBib
|
|
26
26
|
end
|
27
27
|
|
28
28
|
@type = args[:type]
|
29
|
-
@description = args.fetch(:description, []).map
|
29
|
+
@description = args.fetch(:description, []).map do |d|
|
30
|
+
FormattedString.new content: d, format: nil
|
31
|
+
end
|
30
32
|
end
|
31
33
|
|
32
34
|
# @param builder [Nokogiri::XML::Builder]
|
@@ -48,6 +50,19 @@ module RelatonBib
|
|
48
50
|
type
|
49
51
|
end
|
50
52
|
end
|
53
|
+
|
54
|
+
# @param prefix [String]
|
55
|
+
# @param count [Integer] number of contributors
|
56
|
+
# 2return [String]
|
57
|
+
def to_asciibib(prefix = "", count = 1)
|
58
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
59
|
+
out = count > 1 ? "#{prefix}::\n" : ""
|
60
|
+
description.each do |d|
|
61
|
+
out += d.to_asciibib "#{pref}role.description", description.size
|
62
|
+
end
|
63
|
+
out += "#{pref}role.type:: #{type}\n" if type
|
64
|
+
out
|
65
|
+
end
|
51
66
|
end
|
52
67
|
|
53
68
|
# Contribution info.
|
@@ -79,5 +94,16 @@ module RelatonBib
|
|
79
94
|
hash["role"] = single_element_array(role) if role&.any?
|
80
95
|
hash
|
81
96
|
end
|
97
|
+
|
98
|
+
# @param prefix [String]
|
99
|
+
# @param count [Integer] number of contributors
|
100
|
+
# @return [String]
|
101
|
+
def to_asciibib(prefix = "", count = 1)
|
102
|
+
pref = prefix.split(".").first
|
103
|
+
out = count > 1 ? "#{pref}::\n" : ""
|
104
|
+
out += entity.to_asciibib prefix
|
105
|
+
role.each { |r| out += r.to_asciibib pref, role.size }
|
106
|
+
out
|
107
|
+
end
|
82
108
|
end
|
83
109
|
end
|
@@ -54,6 +54,20 @@ module RelatonBib
|
|
54
54
|
hash["postcode"] = postcode if postcode
|
55
55
|
hash
|
56
56
|
end
|
57
|
+
|
58
|
+
# @param prefix [String]
|
59
|
+
# @param count [Integer] number of addresses
|
60
|
+
# @return [String]
|
61
|
+
def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
|
62
|
+
pref = prefix.empty? ? "address" : prefix + ".address"
|
63
|
+
out = count > 1 ? "#{pref}::\n" : ""
|
64
|
+
street.each { |st| out += "#{pref}.street:: #{st}\n" }
|
65
|
+
out += "#{pref}.city:: #{city}\n"
|
66
|
+
out += "#{pref}.state:: #{state}\n" if state
|
67
|
+
out += "#{pref}.country:: #{country}\n"
|
68
|
+
out += "#{pref}.postcode:: #{postcode}\n" if postcode
|
69
|
+
out
|
70
|
+
end
|
57
71
|
end
|
58
72
|
|
59
73
|
# Contact class.
|
@@ -80,6 +94,17 @@ module RelatonBib
|
|
80
94
|
def to_hash
|
81
95
|
{ "type" => type, "value" => value }
|
82
96
|
end
|
97
|
+
|
98
|
+
# @param prefix [String]
|
99
|
+
# @param count [Integer] number of contacts
|
100
|
+
# @return [string]
|
101
|
+
def to_asciibib(prefix = "", count = 1)
|
102
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
103
|
+
out = count > 1 ? "#{pref}contact::\n" : ""
|
104
|
+
out += "#{pref}contact.type:: #{type}\n"
|
105
|
+
out += "#{pref}contact.value:: #{value}\n"
|
106
|
+
out
|
107
|
+
end
|
83
108
|
end
|
84
109
|
|
85
110
|
# Affiliation.
|
@@ -117,9 +142,25 @@ module RelatonBib
|
|
117
142
|
def to_hash
|
118
143
|
hash = organization.to_hash
|
119
144
|
hash["name"] = name.to_hash if name
|
120
|
-
|
145
|
+
if description&.any?
|
146
|
+
hash["description"] = single_element_array(description)
|
147
|
+
end
|
121
148
|
hash
|
122
149
|
end
|
150
|
+
|
151
|
+
# @param prefix [String]
|
152
|
+
# @param count [Integer]
|
153
|
+
# @return [String]
|
154
|
+
def to_asciibib(prefix = "", count = 1)
|
155
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
156
|
+
out = count > 1 ? "#{pref}affiliation::\n" : ""
|
157
|
+
out += name.to_asciibib "#{pref}affiliation.name" if name
|
158
|
+
description.each do |d|
|
159
|
+
out += d.to_asciibib "#{pref}affiliation.description", description.size
|
160
|
+
end
|
161
|
+
out += organization.to_asciibib "#{pref}affiliation.*"
|
162
|
+
out
|
163
|
+
end
|
123
164
|
end
|
124
165
|
|
125
166
|
# Contributor.
|
@@ -157,5 +198,18 @@ module RelatonBib
|
|
157
198
|
hash["contact"] = single_element_array(contact) if contact&.any?
|
158
199
|
hash
|
159
200
|
end
|
201
|
+
|
202
|
+
# @param prefix [String]
|
203
|
+
# @return [String]
|
204
|
+
def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
205
|
+
pref = prefix.empty? ? prefix : prefix + "."
|
206
|
+
out = ""
|
207
|
+
out += "#{pref}url:: #{uri}\n" if uri
|
208
|
+
addr = contact.select { |c| c.is_a? RelatonBib::Address }
|
209
|
+
addr.each { |ct| out += ct.to_asciibib prefix, addr.size }
|
210
|
+
cont = contact.select { |c| c.is_a? RelatonBib::Contact }
|
211
|
+
cont.each { |ct| out += ct.to_asciibib prefix, cont.size }
|
212
|
+
out
|
213
|
+
end
|
160
214
|
end
|
161
215
|
end
|