relaton-bib 1.12.6 → 1.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff390021e9158da2d1167e55d988d5dd920c7c9deba9e37838435c7f903d8852
4
- data.tar.gz: a0fd8d9929ff51df3604243e9dc28770d3b38721950e1886dc6995a90fa95b4c
3
+ metadata.gz: 86a0bd8757736f00d9823a2c7e054061070ca6a092a502f20f5598875db95aa0
4
+ data.tar.gz: c96b9564f71355be85fd8752bf93df410d71d3913e87e8463b070bcbcca7b1b1
5
5
  SHA512:
6
- metadata.gz: ec5005c4ae8ed03918f6933ed7329990977ab1347eb57626dfdaa1a9dddbd60eada93dc5dfdb365bb1ae06aaf60b8f7fd23ab75837022cbd1f3b6ce4009b797c
7
- data.tar.gz: 864a6000626e238808513075dc9343debc59a9440e5806092c4af5e90e38e8927e62b3767903e1fc6b65611c8af60e6c4c8b5cb697c91d666f7662501ce0b7ec
6
+ metadata.gz: 2c37155924af6e0a88b5c2883f439f16edeb27dbfa4114e7d3bf5fd9c1eb2e54c1c0d67a535ff0e06a9cda0a9810974de0bdecb96408d0adaeaf766fb18ac29d
7
+ data.tar.gz: 38ec500a5144b27b2dce3b6dfab3a7c76c6e936d54f4a2ec2933cb292f6aaf133471fd7b32a1521098c5bee25de789472c5ca6238c85c70310656c5ae00f3d8b
data/grammars/biblio.rng CHANGED
@@ -225,9 +225,9 @@
225
225
  <zeroOrMore>
226
226
  <ref name="forename"/>
227
227
  </zeroOrMore>
228
- <zeroOrMore>
229
- <ref name="initial"/>
230
- </zeroOrMore>
228
+ <optional>
229
+ <ref name="formatted-initials"/>
230
+ </optional>
231
231
  <ref name="surname"/>
232
232
  <zeroOrMore>
233
233
  <ref name="addition"/>
@@ -247,8 +247,8 @@
247
247
  <ref name="LocalizedString"/>
248
248
  </element>
249
249
  </define>
250
- <define name="initial">
251
- <element name="initial">
250
+ <define name="formatted-initials">
251
+ <element name="formatted-initials">
252
252
  <ref name="LocalizedString"/>
253
253
  </element>
254
254
  </define>
@@ -264,6 +264,9 @@
264
264
  </define>
265
265
  <define name="forename">
266
266
  <element name="forename">
267
+ <optional>
268
+ <attribute name="initial"/>
269
+ </optional>
267
270
  <ref name="LocalizedString"/>
268
271
  </element>
269
272
  </define>
data/grammars/isodoc.rng CHANGED
@@ -69,6 +69,17 @@
69
69
  </zeroOrMore>
70
70
  </element>
71
71
  </define>
72
+ <define name="AdmonitionType">
73
+ <choice>
74
+ <value>warning</value>
75
+ <value>note</value>
76
+ <value>tip</value>
77
+ <value>important</value>
78
+ <value>caution</value>
79
+ <value>statement</value>
80
+ <value>editorial</value>
81
+ </choice>
82
+ </define>
72
83
  <define name="index">
73
84
  <element name="index">
74
85
  <optional>
@@ -1274,7 +1285,12 @@
1274
1285
  </define>
1275
1286
  <define name="span">
1276
1287
  <element name="span">
1277
- <attribute name="class"/>
1288
+ <optional>
1289
+ <attribute name="class"/>
1290
+ </optional>
1291
+ <optional>
1292
+ <attribute name="style"/>
1293
+ </optional>
1278
1294
  <oneOrMore>
1279
1295
  <ref name="TextElement"/>
1280
1296
  </oneOrMore>
@@ -2493,6 +2509,16 @@
2493
2509
  <text/>
2494
2510
  </element>
2495
2511
  </optional>
2512
+ <optional>
2513
+ <element name="amendment">
2514
+ <text/>
2515
+ </element>
2516
+ </optional>
2517
+ <optional>
2518
+ <element name="corrigendum">
2519
+ <text/>
2520
+ </element>
2521
+ </optional>
2496
2522
  <optional>
2497
2523
  <element name="language">
2498
2524
  <text/>
@@ -265,7 +265,11 @@ module RelatonBib
265
265
  # we should pass the fetched arg from scrappers
266
266
  @fetched = args.fetch :fetched, nil
267
267
  @keyword = (args[:keyword] || []).map do |kw|
268
- LocalizedString.new(kw)
268
+ case kw
269
+ when Hash then LocalizedString.new(kw[:content], kw[:language], kw[:script])
270
+ when String then LocalizedString.new(kw)
271
+ else kw
272
+ end
269
273
  end
270
274
  @license = args.fetch :license, []
271
275
  @doctype = args[:doctype]
@@ -1013,17 +1017,19 @@ module RelatonBib
1013
1017
  if person.name.completename
1014
1018
  builder.parent[:fullname] = person.name.completename.content
1015
1019
  elsif person.name.forename.any?
1016
- builder.parent[:fullname] = person.name.forename.map(&:content).join
1020
+ builder.parent[:fullname] = person.name.forename.map do |n|
1021
+ n.content || n.initial
1022
+ end.join " "
1017
1023
  end
1018
- if person.name.initial.any?
1019
- builder.parent[:initials] = person.name.initial.map(&:content).join
1024
+ if person.name.initials
1025
+ builder.parent[:initials] = person.name.initials.content
1020
1026
  elsif person.name.forename.any?
1021
1027
  builder.parent[:initials] = person.name.forename.map do |f|
1022
- "#{f.content[0]}."
1028
+ "#{f.initial || f.content[0]}."
1023
1029
  end.join
1024
1030
  end
1025
1031
  if person.name.surname
1026
- if person.name.forename.any?
1032
+ if !person.name.completename && person.name.forename.any? && person.name.surname
1027
1033
  builder.parent[:fullname] += " #{person.name.surname}"
1028
1034
  end
1029
1035
  builder.parent[:surname] = person.name.surname.content
@@ -25,7 +25,7 @@ module RelatonBib
25
25
  link: fetch_link(bt),
26
26
  language: fetch_language(bt),
27
27
  classification: fetch_classification(bt),
28
- keyword: fetch_keyword(bt)
28
+ keyword: fetch_keyword(bt),
29
29
  )
30
30
  h
31
31
  end
@@ -123,7 +123,7 @@ module RelatonBib
123
123
  parts = name.split ", "
124
124
  surname = LocalizedString.new parts.first
125
125
  fname = parts.size > 1 ? parts[1].split : []
126
- forename = fname.map { |fn| LocalizedString.new fn }
126
+ forename = fname.map { |fn| Forename.new content: fn }
127
127
  Person.new name: FullName.new(surname: surname, forename: forename)
128
128
  end
129
129
  end
@@ -264,13 +264,30 @@ module RelatonBib
264
264
  # @return [RelatonBib::FullName]
265
265
  def full_name(author, reference)
266
266
  lang = language reference
267
+ initials = localized_string(author[:initials], lang) if author[:initials]
267
268
  FullName.new(
268
269
  completename: localized_string(author[:fullname], lang),
269
- initial: [localized_string(author[:initials], lang)].compact,
270
- surname: localized_string(author[:surname], lang),
270
+ initials: initials, forename: forename(author[:initials], lang),
271
+ surname: localized_string(author[:surname], lang)
271
272
  )
272
273
  end
273
274
 
275
+ #
276
+ # Create forenames with initials
277
+ #
278
+ # @param [String] initials initials
279
+ # @param [String] lang language
280
+ #
281
+ # @return [Array<RelatonBib::Forename>] forenames
282
+ #
283
+ def forename(initials, lang)
284
+ return [] unless initials
285
+
286
+ initials.split(/\.-?\s?|\s/).map do |i|
287
+ Forename.new(initial: i, language: lang)
288
+ end
289
+ end
290
+
274
291
  # @param author [Nokogiri::XML::Element]
275
292
  # @return [Array<RelatonBib::Affiliation>]
276
293
  def affiliation(author)
@@ -0,0 +1,65 @@
1
+ module RelatonBib
2
+ class Forename < LocalizedString
3
+ # @return [RelatonBib::Forename] forename
4
+ attr_accessor :initial
5
+
6
+ #
7
+ # Initialize Forename instance
8
+ #
9
+ # @param [String] content content of forename, can be empty
10
+ # @param [Array<String>] language languages, `en`, `fr`, `de` etc.
11
+ # @param [Array<String>] script scripts `Latn`, `Cyrl` etc.
12
+ # @param [String, nil] initial initial of forename
13
+ #
14
+ def initialize(content: nil, language: [], script: [], initial: nil)
15
+ @initial = initial
16
+ super content, language, script
17
+ end
18
+
19
+ def to_s
20
+ content.nil? ? initial : super
21
+ end
22
+
23
+ #
24
+ # Render forename to XML
25
+ #
26
+ # @param [Nokogiri::XML::Builder] builder XML builder
27
+ #
28
+ def to_xml(builder)
29
+ node = builder.forename { super }
30
+ node[:initial] = initial if initial
31
+ end
32
+
33
+ #
34
+ # Render forename to hash
35
+ #
36
+ # @return [Hash, String] forename hash or string representation
37
+ #
38
+ def to_hash
39
+ ls = super
40
+ # if initial
41
+ hash = ls.is_a?(Hash) ? ls : { "content" => ls }
42
+ hash["initial"] = initial if initial
43
+ hash
44
+ # else
45
+ # ls
46
+ # end
47
+ end
48
+
49
+ #
50
+ # Render forename to asciibib
51
+ #
52
+ # @param [String] pref prefix
53
+ # @param [Integer] count size of array
54
+ #
55
+ # @return [String] asciibib string
56
+ #
57
+ def to_asciibib(pref, count = 1)
58
+ prf = pref.empty? ? pref : "#{pref}."
59
+ prf += "forename"
60
+ out = super prf, count
61
+ out += "#{prf}.initial:: #{initial}\n" if initial
62
+ out
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,103 @@
1
+ module RelatonBib
2
+ # Person's full name
3
+ class FullName
4
+ include RelatonBib
5
+
6
+ # @return [Array<RelatonBib::Forename>]
7
+ attr_accessor :forename
8
+
9
+ # @return [Array<RelatonBib::LocalizedString>]
10
+ attr_accessor :initials
11
+
12
+ # @return [RelatonBib::LocalizedString, nil]
13
+ attr_accessor :surname, :completename
14
+
15
+ # @return [Array<RelatonBib::LocalizedString>]
16
+ attr_accessor :addition
17
+
18
+ # @return [Array<RelatonBib::LocalizedString>]
19
+ attr_accessor :prefix
20
+
21
+ #
22
+ # Initialize FullName instance
23
+ #
24
+ # @param surname [RelatonBib::LocalizedString, nil] surname or completename
25
+ # should be present
26
+ # @param forename [Array<RelatonBib::Forename>] forename
27
+ # @param initials [RelatonBib::LocalizedString, String, nil] string of initials
28
+ # @param addition [Array<RelatonBib::LocalizedString>] array of additions
29
+ # @param prefix [Array<RelatonBib::LocalizedString>] array of prefixes
30
+ # @param completename [RelatonBib::LocalizedString, nil] completename or
31
+ # surname should be present
32
+ #
33
+ def initialize(**args)
34
+ unless args[:surname] || args[:completename]
35
+ raise ArgumentError, "Should be given :surname or :completename"
36
+ end
37
+
38
+ @surname = args[:surname]
39
+ @forename = args.fetch :forename, []
40
+ @initials = args[:initials].is_a?(String) ? LocalizedString.new(args[:initials]) : args[:initials]
41
+ @addition = args.fetch :addition, []
42
+ @prefix = args.fetch :prefix, []
43
+ @completename = args[:completename]
44
+ end
45
+
46
+ # @param opts [Hash]
47
+ # @option opts [Nokogiri::XML::Builder] :builder XML builder
48
+ # @option opts [String] :lang language
49
+ def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
50
+ opts[:builder].name do |builder|
51
+ if completename
52
+ builder.completename { completename.to_xml builder }
53
+ else
54
+ pref = prefix.select { |p| p.language&.include? opts[:lang] }
55
+ pref = prefix unless pref.any?
56
+ pref.each { |p| builder.prefix { p.to_xml builder } }
57
+ frnm = forename.select { |f| f.language&.include? opts[:lang] }
58
+ frnm = forename unless frnm.any?
59
+ frnm.each { |f| f.to_xml builder }
60
+ builder.send(:"formatted-initials") { initials.to_xml builder } if initials
61
+ builder.surname { surname.to_xml builder }
62
+ addn = addition.select { |a| a.language&.include? opts[:lang] }
63
+ addn = addition unless addn.any?
64
+ addn.each { |a| builder.addition { a.to_xml builder } }
65
+ end
66
+ end
67
+ end
68
+
69
+ # @return [Hash]
70
+ def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
71
+ hash = {}
72
+ if forename.any? || initials
73
+ hash["given"] = {}
74
+ hash["given"]["forename"] = single_element_array(forename) if forename&.any?
75
+ hash["given"]["formatted_initials"] = initials.to_hash if initials
76
+ end
77
+ hash["surname"] = surname.to_hash if surname
78
+ hash["addition"] = single_element_array(addition) if addition&.any?
79
+ hash["prefix"] = single_element_array(prefix) if prefix&.any?
80
+ hash["completename"] = completename.to_hash if completename
81
+ hash
82
+ end
83
+
84
+ # @param pref [String]
85
+ # @return [String]
86
+ def to_asciibib(pref) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
87
+ prf = pref.empty? ? pref : "#{pref}."
88
+ prf += "name"
89
+ given = "#{pref}.given"
90
+ out = forename.map do |fn|
91
+ fn.to_asciibib given, forename.size
92
+ end.join
93
+ out += initials.to_asciibib "#{given}.formatted-initials" if initials
94
+ out += surname.to_asciibib "#{prf}.surname" if surname
95
+ addition.each do |ad|
96
+ out += ad.to_asciibib "#{prf}.addition", addition.size
97
+ end
98
+ prefix.each { |pr| out += pr.to_asciibib "#{prf}.prefix", prefix.size }
99
+ out += completename.to_asciibib "#{prf}.completename" if completename
100
+ out
101
+ end
102
+ end
103
+ end
@@ -33,7 +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] = RelatonBib.array(ret[:keyword])
36
+ keyword_hash_to_bib(ret)
37
+ # ret[:keyword] = RelatonBib.array(ret[:keyword])
37
38
  ret[:license] = RelatonBib.array(ret[:license])
38
39
  editorialgroup_hash_to_bib ret
39
40
  ics_hash_to_bib ret
@@ -42,9 +43,11 @@ module RelatonBib
42
43
  end
43
44
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
44
45
 
45
- # def timestamp_hash(ret)
46
- # ret[:fetched] ||= Date.today.to_s
47
- # end
46
+ def keyword_hash_to_bib(ret)
47
+ ret[:keyword] = RelatonBib.array(ret[:keyword]).map do |keyword|
48
+ localizedstring keyword
49
+ end
50
+ end
48
51
 
49
52
  def extent_hash_to_bib(ret)
50
53
  return unless ret[:extent]
@@ -198,7 +201,8 @@ module RelatonBib
198
201
  ret[:contributor]&.each_with_index do |c, i|
199
202
  roles = RelatonBib.array(ret[:contributor][i][:role]).map do |r|
200
203
  if r.is_a? Hash
201
- { type: r[:type], description: RelatonBib.array(r[:description]) }
204
+ desc = RelatonBib.array(r[:description]).map { |d| d.is_a?(String) ? d : d[:content] }
205
+ { type: r[:type], description: desc }
202
206
  # elsif r.is_a? Array
203
207
  # { type: r[0], description: r.fetch(1) }
204
208
  else
@@ -238,18 +242,33 @@ module RelatonBib
238
242
  )
239
243
  end
240
244
 
241
- def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
245
+ def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize
242
246
  n = person[:name]
247
+ fname, inits = given_hash_to_bib n[:given] || n # `n` is for backward compatibility
243
248
  FullName.new(
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) },
248
- surname: localname(n[:surname], person),
249
- completename: localname(n[:completename], person),
249
+ forename: fname, initials: inits,
250
+ addition: RelatonBib.array(n[:addition])&.map { |f| localizedstring(f) },
251
+ prefix: RelatonBib.array(n[:prefix])&.map { |f| localizedstring(f) },
252
+ surname: localizedstring(n[:surname]),
253
+ completename: localizedstring(n[:completename])
250
254
  )
251
255
  end
252
256
 
257
+ def given_hash_to_bib(given)
258
+ return [[], nil] unless given
259
+
260
+ fname = RelatonBib.array(given[:forename])&.map { |f| forename_hash_to_bib(f) }
261
+ inits = localizedstring(given[:formatted_initials])
262
+ [fname, inits]
263
+ end
264
+
265
+ def forename_hash_to_bib(fname)
266
+ case fname
267
+ when Hash then Forename.new(**fname)
268
+ when String then Forename.new(content: fname)
269
+ end
270
+ end
271
+
253
272
  def person_identifiers_hash_to_bib(person)
254
273
  RelatonBib.array(person[:identifier])&.map do |a|
255
274
  PersonIdentifier.new(a[:type], a[:id])
@@ -275,7 +294,7 @@ module RelatonBib
275
294
  end
276
295
  end
277
296
 
278
- def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
297
+ def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
279
298
  return [] unless entity[:contact]
280
299
 
281
300
  RelatonBib.array(entity[:contact]).map do |a|
@@ -473,28 +492,14 @@ module RelatonBib
473
492
  end
474
493
  end
475
494
 
476
- # @param name [Hash, String, NilClass]
477
- # @param person [Hash]
478
- # @return [RelatonBib::LocalizedString]
479
- def localname(name, person) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
480
- return nil if name.nil?
481
-
482
- lang = name[:language] if name.is_a?(Hash)
483
- lang ||= person[:name][:language]
484
- script = name[:script] if name.is_a?(Hash)
485
- script ||= person[:name][:script]
486
- n = name.is_a?(Hash) ? name[:content] : name
487
- RelatonBib::LocalizedString.new(n, lang, script)
488
- end
489
-
490
- # @param lst [Hash, Array<RelatonBib::LocalizedString>]
495
+ # @param lst [Hash, Array<RelatonBib::LocalizedString>, String]
491
496
  # @return [RelatonBib::LocalizedString]
492
497
  def localizedstring(lst)
498
+ return unless lst
499
+
493
500
  if lst.is_a?(Hash)
494
- RelatonBib::LocalizedString.new(lst[:content], lst[:language],
495
- lst[:script])
496
- else
497
- RelatonBib::LocalizedString.new(lst)
501
+ LocalizedString.new(lst[:content], lst[:language], lst[:script])
502
+ else LocalizedString.new(lst)
498
503
  end
499
504
  end
500
505
 
@@ -37,12 +37,20 @@ module RelatonBib
37
37
  end
38
38
  end
39
39
 
40
+ #
41
+ # String representation.
42
+ #
40
43
  # @return [String]
44
+ #
41
45
  def to_s
42
46
  content.is_a?(Array) ? content.first.to_s : content.to_s
43
47
  end
44
48
 
45
- # @return [TrueClass, FalseClass]
49
+ #
50
+ # Returns true if content is empty.
51
+ #
52
+ # @return [Boolean]
53
+ #
46
54
  def empty?
47
55
  content.empty?
48
56
  end
@@ -68,14 +76,17 @@ module RelatonBib
68
76
  # @return [String] encoded content
69
77
  #
70
78
  def encode(cnt) # rubocop:disable Metrics/MethodLength
71
- regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)>.*<\/\k<tag>>)(?<sfx>.*)/m
79
+ return unless cnt
80
+
81
+ # regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)>.*<\/\k<tag>>)(?<sfx>.*)/m
82
+ regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)[^>]*(?:>.*<\/\k<tag>)?>)(?<rest>.*)/m
72
83
  if cnt.match(regex)
73
84
  prf = Regexp.last_match(:prf).lstrip
74
85
  xml = Regexp.last_match[:xml]
75
- sfx = Regexp.last_match(:sfx).rstrip
76
- parts = xml.scan(/\s*<(?<tago>\w+)>(?<cnt1>.*?)(?=<\/?\w+>)|(?<cnt2>.*?)<\/(?<tagc>\w+)>/)
86
+ rest = Regexp.last_match(:rest).rstrip
87
+ parts = xml.scan(/\s*<(?<tago>\w+)(?<attrs>[^>]*)>(?:(?<cnt1>.*?)(?=<\/\w+>|<\w+[^>]*>))?|(?<cnt2>.*?)<\/(?<tagc>\w+)>/)
77
88
  out = scan_xml parts
78
- "#{escp(prf)}#{out}#{escp(sfx)}"
89
+ "#{escp(prf)}#{out}#{encode(rest)}"
79
90
  else
80
91
  escp cnt
81
92
  end
@@ -84,22 +95,24 @@ module RelatonBib
84
95
  #
85
96
  # Scan XML and escape HTML entities.
86
97
  #
87
- # @param [Array<Array<String,nik>>] parts XML parts
98
+ # @param [Array<Array<String,nil>>] parts XML parts
88
99
  #
89
100
  # @return [String] output string
90
101
  #
91
102
  def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
92
103
  return "" unless parts.any? && parts.first[0]
93
104
 
94
- tago, cnt1, = parts.shift
95
- if tago && tago == parts.first[3]
96
- _, _, cnt2, tagc = parts.shift
97
- "<#{tago}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
105
+ tago, attrs, cnt1, = parts.shift
106
+ if tago && tago == parts.first&.last
107
+ _, _, _, cnt2, tagc = parts.shift
108
+ "<#{tago}#{attrs}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
109
+ elsif tago && attrs && attrs[-1] == "/"
110
+ "<#{tago}#{attrs}>"
98
111
  elsif tago
99
112
  inr = scan_xml parts
100
- _, _, cnt2, tagc = parts.shift
113
+ _, _, _, cnt2, tagc = parts.shift
101
114
  if tago == tagc
102
- "<#{tago}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
115
+ "<#{tago}#{attrs}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
103
116
  else
104
117
  "#{escp("<#{tago}>#{cnt1}")}#{inr}#{escp("#{cnt2}</#{tagc}>")}"
105
118
  end
@@ -119,10 +132,11 @@ module RelatonBib
119
132
 
120
133
  # @return [Hash]
121
134
  def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
122
- if content.is_a? String
123
- return content unless language || script
135
+ if content.nil? || content.is_a?(String)
136
+ # return content unless language || script
124
137
 
125
- hash = { "content" => content }
138
+ hash = {}
139
+ hash["content"] = content unless content.nil? || content.empty?
126
140
  hash["language"] = single_element_array(language) if language&.any?
127
141
  hash["script"] = single_element_array(script) if script&.any?
128
142
  hash
@@ -135,7 +149,8 @@ module RelatonBib
135
149
  # @return [String]
136
150
  def to_asciibib(prefix = "", count = 1, has_attrs = false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
137
151
  pref = prefix.empty? ? prefix : "#{prefix}."
138
- if content.is_a? String
152
+ case content
153
+ when String
139
154
  unless language&.any? || script&.any? || has_attrs
140
155
  return "#{prefix}:: #{content}\n"
141
156
  end
@@ -145,8 +160,9 @@ module RelatonBib
145
160
  language&.each { |l| out += "#{pref}language:: #{l}\n" }
146
161
  script&.each { |s| out += "#{pref}script:: #{s}\n" }
147
162
  out
148
- else
163
+ when Array
149
164
  content.map { |c| c.to_asciibib "#{pref}variant", content.size }.join
165
+ else count > 1 ? "#{prefix}::\n" : ""
150
166
  end
151
167
  end
152
168
  end
@@ -1,104 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "relaton_bib/contributor"
4
-
5
3
  module RelatonBib
6
- # Person's full name
7
- class FullName
8
- include RelatonBib
9
-
10
- # @return [Array<RelatonBib::LocalizedString>]
11
- attr_accessor :forename
12
-
13
- # @return [Array<RelatonBib::LocalizedString>]
14
- attr_accessor :initial
15
-
16
- # @return [RelatonBib::LocalizedString, nil]
17
- attr_accessor :surname, :completename
18
-
19
- # @return [Array<RelatonBib::LocalizedString>]
20
- attr_accessor :addition
21
-
22
- # @return [Array<RelatonBib::LocalizedString>]
23
- attr_accessor :prefix
24
-
25
- # @param surname [RelatonBib::LocalizedString, nil] surname or completename
26
- # should be present
27
- # @param forename [Array<RelatonBib::LocalizedString>]
28
- # @param initial [Array<RelatonBib::LocalizedString>]
29
- # @param addition [Array<RelatonBib::LocalizedString>]
30
- # @param prefix [Array<RelatonBib::LocalizedString>]
31
- # @param completename [RelatonBib::LocalizedString, nil] completename or
32
- # surname should be present
33
- def initialize(**args)
34
- unless args[:surname] || args[:completename]
35
- raise ArgumentError, "Should be given :surname or :completename"
36
- end
37
-
38
- @surname = args[:surname]
39
- @forename = args.fetch :forename, []
40
- @initial = args.fetch :initial, []
41
- @addition = args.fetch :addition, []
42
- @prefix = args.fetch :prefix, []
43
- @completename = args[:completename]
44
- end
45
-
46
- # @param opts [Hash]
47
- # @option opts [Nokogiri::XML::Builder] :builder XML builder
48
- # @option opts [String] :lang language
49
- def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
50
- opts[:builder].name do |builder|
51
- if completename
52
- builder.completename { completename.to_xml builder }
53
- else
54
- pref = prefix.select { |p| p.language&.include? opts[:lang] }
55
- pref = prefix unless pref.any?
56
- pref.each { |p| builder.prefix { p.to_xml builder } }
57
- frnm = forename.select { |f| f.language&.include? opts[:lang] }
58
- frnm = forename unless frnm.any?
59
- frnm.each { |f| builder.forename { f.to_xml builder } }
60
- init = initial.select { |i| i.language&.include? opts[:lang] }
61
- init = initial unless init.any?
62
- init.each { |i| builder.initial { i.to_xml builder } }
63
- builder.surname { surname.to_xml builder }
64
- addn = addition.select { |a| a.language&.include? opts[:lang] }
65
- addn = addition unless addn.any?
66
- addn.each { |a| builder.addition { a.to_xml builder } }
67
- end
68
- end
69
- end
70
-
71
- # @return [Hash]
72
- def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
73
- hash = {}
74
- hash["forename"] = single_element_array(forename) if forename&.any?
75
- hash["initial"] = single_element_array(initial) if initial&.any?
76
- hash["surname"] = surname.to_hash if surname
77
- hash["addition"] = single_element_array(addition) if addition&.any?
78
- hash["prefix"] = single_element_array(prefix) if prefix&.any?
79
- hash["completename"] = completename.to_hash if completename
80
- hash
81
- end
82
-
83
- # @param pref [String]
84
- # @return [String]
85
- def to_asciibib(pref) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
86
- prf = pref.empty? ? pref : pref + "."
87
- prf += "name."
88
- out = forename.map do |fn|
89
- fn.to_asciibib "#{prf}forename", forename.size
90
- end.join
91
- initial.each { |i| out += i.to_asciibib "#{prf}initial", initial.size }
92
- out += surname.to_asciibib "#{prf}surname" if surname
93
- addition.each do |ad|
94
- out += ad.to_asciibib "#{prf}addition", addition.size
95
- end
96
- prefix.each { |pr| out += pr.to_asciibib "#{prf}prefix", prefix.size }
97
- out += completename.to_asciibib "#{prf}completename" if completename
98
- out
99
- end
100
- end
101
-
102
4
  # Person identifier type.
103
5
  module PersonIdentifierType
104
6
  ISNI = "isni"
@@ -68,7 +68,7 @@ module RelatonBib
68
68
  # @param [BibTeX::Entry] item bibtex entry
69
69
  #
70
70
  def to_bibtex(item)
71
- tl = titles.detect { |t| t.type == "main" }
71
+ tl = titles.detect { |t| t.type == "main" } || titles.first
72
72
  return unless tl
73
73
 
74
74
  item.title = tl.title.content
@@ -158,13 +158,14 @@ module RelatonBib
158
158
  th = title.to_hash
159
159
  return th unless type
160
160
 
161
- hash = { "type" => type }
162
- if th.is_a? String
163
- hash["content"] = th
164
- else
165
- hash.merge! th
166
- end
167
- hash
161
+ # hash = { "type" => type }
162
+ # if th.is_a? String
163
+ # hash["content"] = th
164
+ # else
165
+ # hash.merge! th
166
+ # end
167
+ # hash
168
+ th.merge "type" => type
168
169
  end
169
170
 
170
171
  # @param prefix [String]
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.12.6".freeze
2
+ VERSION = "1.13.1".freeze
3
3
  end
@@ -305,8 +305,8 @@ module RelatonBib
305
305
 
306
306
  name = FullName.new(
307
307
  completename: cname, surname: sname,
308
- initial: name_part(person, "initial"),
309
- forename: name_part(person, "forename"),
308
+ initials: parse_initials(person),
309
+ forename: parse_forename(person),
310
310
  addition: name_part(person, "addition"),
311
311
  prefix: name_part(person, "prefix")
312
312
  )
@@ -336,6 +336,21 @@ module RelatonBib
336
336
  end
337
337
  end
338
338
 
339
+ def parse_initials(person)
340
+ inits = person.at "./name/formatted-initials"
341
+ return unless inits
342
+
343
+ LocalizedString.new(inits.text, inits[:language], inits[:script])
344
+ end
345
+
346
+ def parse_forename(person)
347
+ person.xpath("./name/forename").map do |np|
348
+ args = np.attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v.to_s }
349
+ args[:content] = np.text
350
+ Forename.new(**args)
351
+ end
352
+ end
353
+
339
354
  def name_part(person, part)
340
355
  person.xpath("./name/#{part}").map do |np|
341
356
  LocalizedString.new np.text, np[:language], np[:script]
@@ -472,7 +487,7 @@ module RelatonBib
472
487
  return unless ident
473
488
 
474
489
  FormattedRef.new(
475
- content: ident&.text, format: ident[:format],
490
+ content: ident.children.to_s, format: ident[:format],
476
491
  language: ident[:language], script: ident[:script]
477
492
  )
478
493
  end
data/lib/relaton_bib.rb CHANGED
@@ -4,6 +4,9 @@ require "htmlentities"
4
4
  require "relaton_bib/version"
5
5
  require "relaton_bib/deep_dup"
6
6
  require "relaton_bib/localized_string"
7
+ require "relaton_bib/forename"
8
+ require "relaton_bib/full_name"
9
+ require "relaton_bib/contributor"
7
10
  require "relaton_bib/bibliographic_item"
8
11
  require "relaton_bib/hit_collection"
9
12
  require "relaton_bib/hit"
@@ -40,7 +43,8 @@ module RelatonBib
40
43
  #
41
44
  # @param [String] date date string
42
45
  # @param [String] format format string
43
- # @param [Boolean] str return string or Date if true
46
+ # @param [Boolean] str return string if true in other case return Date
47
+ # @param [String, nil] outformat output format
44
48
  #
45
49
  # @return [Date, String] date object or formatted date string
46
50
  #
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.12.6
4
+ version: 1.13.1
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-08-11 00:00:00.000000000 Z
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -251,8 +251,10 @@ files:
251
251
  - lib/relaton_bib/document_status.rb
252
252
  - lib/relaton_bib/edition.rb
253
253
  - lib/relaton_bib/editorial_group.rb
254
+ - lib/relaton_bib/forename.rb
254
255
  - lib/relaton_bib/formatted_ref.rb
255
256
  - lib/relaton_bib/formatted_string.rb
257
+ - lib/relaton_bib/full_name.rb
256
258
  - lib/relaton_bib/hash_converter.rb
257
259
  - lib/relaton_bib/hit.rb
258
260
  - lib/relaton_bib/hit_collection.rb