relaton-bib 1.12.7 → 1.13.0

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: be4b986a04f391a2e552c13d8ee897e73c398f3acb27deda3bb203da627f585b
4
- data.tar.gz: 05540e11934396b938df0c902d926c37b1c49c8aa215b7888827bb42d19d4042
3
+ metadata.gz: 99408aa20e1cd2228d00656949182896e8acaf845e5e223024b262b915636b8f
4
+ data.tar.gz: 3fb73b6ee0381499a955f7b9c082c1a49aa9c1944d22c26ca8064ff008608bb0
5
5
  SHA512:
6
- metadata.gz: f82094e85351832f3738216ce8ba72c68f7f26e9bcd7379cbe49b2e9a2bc0318ce1d4507462d3dbfed61ba57fc9bc692daf4998cbc84fb3bc2f54a14bed7e72a
7
- data.tar.gz: 66de7c5f7b612c203694d6adacb0fdbf09dd34380f24bfe6e3d298f50d61d52af844f2803f8e75644839ce0b256726db55fc9058a649f9f42c8c3198f6e279ab
6
+ metadata.gz: 0e04458e0ab8bbe38e464f84a0c3de36e4db43361efeec0246a09b476171eeb8050283b7d8ef18eeb1432505985879c30d6d9202f27f6536cd65195a4e6d9938
7
+ data.tar.gz: 25241fe59416e9dad9af8b1c11579cf309194acfcbce167d603105c7264d67a744f452a0f3ee9f8fad9fa23e857d282b2ad79e17e67372f8940e21021594fb44
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]
@@ -1015,11 +1019,11 @@ module RelatonBib
1015
1019
  elsif person.name.forename.any?
1016
1020
  builder.parent[:fullname] = person.name.forename.map(&:content).join
1017
1021
  end
1018
- if person.name.initial.any?
1019
- builder.parent[:initials] = person.name.initial.map(&:content).join
1022
+ if person.name.initials
1023
+ builder.parent[:initials] = person.name.initials.content
1020
1024
  elsif person.name.forename.any?
1021
1025
  builder.parent[:initials] = person.name.forename.map do |f|
1022
- "#{f.content[0]}."
1026
+ "#{f.initial || f.content[0]}."
1023
1027
  end.join
1024
1028
  end
1025
1029
  if person.name.surname
@@ -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,9 +264,10 @@ 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
+ initials: initials,
270
271
  surname: localized_string(author[:surname], lang),
271
272
  )
272
273
  end
@@ -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
@@ -125,9 +133,10 @@ module RelatonBib
125
133
  # @return [Hash]
126
134
  def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
127
135
  if content.is_a? String
128
- return content unless language || script
136
+ # return content unless language || script
129
137
 
130
- hash = { "content" => content }
138
+ hash = {}
139
+ hash["content"] = content unless empty?
131
140
  hash["language"] = single_element_array(language) if language&.any?
132
141
  hash["script"] = single_element_array(script) if script&.any?
133
142
  hash
@@ -140,7 +149,8 @@ module RelatonBib
140
149
  # @return [String]
141
150
  def to_asciibib(prefix = "", count = 1, has_attrs = false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
142
151
  pref = prefix.empty? ? prefix : "#{prefix}."
143
- if content.is_a? String
152
+ case content
153
+ when String
144
154
  unless language&.any? || script&.any? || has_attrs
145
155
  return "#{prefix}:: #{content}\n"
146
156
  end
@@ -150,8 +160,9 @@ module RelatonBib
150
160
  language&.each { |l| out += "#{pref}language:: #{l}\n" }
151
161
  script&.each { |s| out += "#{pref}script:: #{s}\n" }
152
162
  out
153
- else
163
+ when Array
154
164
  content.map { |c| c.to_asciibib "#{pref}variant", content.size }.join
165
+ else count > 1 ? "#{prefix}::\n" : ""
155
166
  end
156
167
  end
157
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"
@@ -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.7".freeze
2
+ VERSION = "1.13.0".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]
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"
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.7
4
+ version: 1.13.0
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-16 00:00:00.000000000 Z
11
+ date: 2022-08-21 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