relaton-bib 1.12.7 → 1.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be4b986a04f391a2e552c13d8ee897e73c398f3acb27deda3bb203da627f585b
4
- data.tar.gz: 05540e11934396b938df0c902d926c37b1c49c8aa215b7888827bb42d19d4042
3
+ metadata.gz: 61c7501f15c50370c99043dafc2950b2bb5314725abae9e2c58fc4c2959ee5ac
4
+ data.tar.gz: b9bc6f11bd966f6155145cb9f9cc22a9ce1873b549ace92b356c29566ab02139
5
5
  SHA512:
6
- metadata.gz: f82094e85351832f3738216ce8ba72c68f7f26e9bcd7379cbe49b2e9a2bc0318ce1d4507462d3dbfed61ba57fc9bc692daf4998cbc84fb3bc2f54a14bed7e72a
7
- data.tar.gz: 66de7c5f7b612c203694d6adacb0fdbf09dd34380f24bfe6e3d298f50d61d52af844f2803f8e75644839ce0b256726db55fc9058a649f9f42c8c3198f6e279ab
6
+ metadata.gz: f8f4bdccc1d8d2de570471187b5484d49f18b4b58b1f3c87b91dc97ffbe69a277ed890261ca6cbbe298fb2f61f56ca827cb814e70a18015943e63e6d23209305
7
+ data.tar.gz: d343cbca3b0c3c22e3775c13573c0e06b553f557aa03b592cb249c863f23ecde405c794f0cdd594bdc292e9639d56a21a28ffdec50ee9d1c8a3b6a430056274a
@@ -10,4 +10,4 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- uses: relaton/support/.github/workflows/rake.yml@master
13
+ uses: relaton/support/.github/workflows/rake.yml@master
@@ -0,0 +1,22 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: release
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'skip'
13
+ push:
14
+ tags: [ v* ]
15
+
16
+ jobs:
17
+ release:
18
+ uses: relaton/support/.github/workflows/release.yml@master
19
+ with:
20
+ next_version: ${{ github.event.inputs.next_version }}
21
+ secrets:
22
+ rubygems-api-key: ${{ secrets.RELATON_CI_RUBYGEMS_API_KEY }}
data/docs/hash.adoc CHANGED
@@ -49,7 +49,7 @@ The structure below is given in YAML format:
49
49
  # bibliographic item anchor, used to crossreference within document
50
50
  id: ISO/TC211
51
51
  # date record was created
52
- fetched: 2019-06-30
52
+ fetched: '2019-06-30'
53
53
  # titles are an array, with a mandatory type and content, and optional format, language and script
54
54
  title:
55
55
  - type: main
@@ -66,9 +66,9 @@ docid:
66
66
  type: ISO
67
67
  id: TC211
68
68
  # document number
69
- docnumber: 211
69
+ docnumber: '211'
70
70
  # edition
71
- edition: 1
71
+ edition: '1'
72
72
  # language is an array
73
73
  language:
74
74
  - en
@@ -78,7 +78,7 @@ script:
78
78
  Latn
79
79
  # version contains revision date and draft (as array)
80
80
  version:
81
- revision_date: 2019-04-01
81
+ revision_date: '2019-04-01'
82
82
  draft: draft
83
83
  # note is an array of type and content
84
84
  biblionote:
@@ -94,12 +94,12 @@ docstatus:
94
94
  # date is an array, with mandatory type, and either an "on" value or a "from" and optional "to" value
95
95
  date:
96
96
  - type: issued
97
- value: 2014
97
+ value: '2014'
98
98
  - type: published
99
- from: 2014-04
100
- to: 2014-05
99
+ from: '2014-04'
100
+ to: '2014-05'
101
101
  - type: accessed
102
- value: 2015-05-20
102
+ value: '2015-05-20'
103
103
  # abstract is an array, with content, and optional language, script, format
104
104
  abstract:
105
105
  - content: >
@@ -114,7 +114,8 @@ abstract:
114
114
  # as the type.
115
115
  # Organisations have attributes name, url, abbreviation, subdivision, contacts, identifiers
116
116
  # Persons have attributes name, affiliation, contacts
117
- # Person names have attributes surname, completename, initials, forename, additions, prefixes.
117
+ # Person names have attributes, given, surname, additions, prefixes or completename.
118
+ # Given has formatted_initials or forename.
118
119
  # Initials, forename, additions, prefixes are arrays.
119
120
  # Name field values are either strings, or hashes, with content and language and script attributes.
120
121
  # The language and script attribute can also be given on the name.
@@ -126,9 +127,11 @@ abstract:
126
127
  # The affiliation description can be a single string, or a hash of content, language, script, and format.
127
128
  contributor:
128
129
  - organization:
129
- name: International Organization for Standardization
130
+ name:
131
+ content: International Organization for Standardization
130
132
  url: www.iso.org
131
- abbreviation: ISO
133
+ abbreviation:
134
+ content: ISO
132
135
  subdivision: division
133
136
  role:
134
137
  type: publisher
@@ -140,25 +143,29 @@ contributor:
140
143
  language: en
141
144
  affiliation:
142
145
  - organization:
143
- name: IETF
144
- abbreviation: IETF
145
- identifier:
146
- - type: uri
147
- id: www.ietf.org
146
+ name:
147
+ content: IETF
148
+ abbreviation:
149
+ content: IETF
150
+ identifier:
151
+ - type: uri
152
+ id: www.ietf.org
148
153
  description: Affiliation description
149
154
  contact:
150
- - street:
151
- - 8 Street St
152
- city: City
153
- postcode: 123456
154
- country: Country
155
- state: State
156
- - type: phone
157
- value: 223322
155
+ - address:
156
+ street:
157
+ - 8 Street St
158
+ city: City
159
+ postcode: '123456'
160
+ country: Country
161
+ state: State
162
+ - phone: '223322'
158
163
  role: author
159
- - person:
160
- name: IETF
161
- abbreviation: IETF
164
+ - organization:
165
+ name:
166
+ content: Internet Engineering Task Force
167
+ abbreviation:
168
+ content: IETF
162
169
  identifier:
163
170
  - type: uri
164
171
  id: www.ietf.org
@@ -166,18 +173,24 @@ contributor:
166
173
  publisher
167
174
  - person:
168
175
  name:
169
- language: en
170
- initial:
171
- - A.
172
- surname: Bierman
176
+ given:
177
+ forename:
178
+ initial: A
179
+ language: en
180
+ formatted_initials:
181
+ content: A.
182
+ surname:
183
+ content: Bierman
173
184
  affiliation:
174
- - organization:
175
- name: IETF
176
- abbreviation: IETF
177
- description:
178
- content: Affiliation description
179
- language: en
180
- script: Latn
185
+ - organization:
186
+ name:
187
+ content: IETF
188
+ abbreviation:
189
+ content: IETF
190
+ description:
191
+ content: Affiliation description
192
+ language: en
193
+ script: Latn
181
194
  identifier:
182
195
  - type: uri
183
196
  id: www.person.com
@@ -187,11 +200,13 @@ contributor:
187
200
  # a "from" date, and an optional "to" date
188
201
  copyright:
189
202
  owner:
190
- name: International Organization for Standardization
191
- abbreviation: ISO
203
+ name:
204
+ content: International Organization for Standardization
205
+ abbreviation:
206
+ content: ISO
192
207
  url: www.iso.org
193
- from: 2014
194
- to: 2020
208
+ from: '2014'
209
+ to: '2020'
195
210
  # link is an array of URIs, with a type and content
196
211
  link:
197
212
  - type: src
@@ -206,15 +221,17 @@ link:
206
221
  relation:
207
222
  - type: updates
208
223
  bibitem:
209
- formattedref: ISO 19115:2003
224
+ formattedref:
225
+ content: ISO 19115:2003
210
226
  bib_locality:
211
227
  type: page
212
- reference_from: 7
213
- reference_to: 10
228
+ reference_from: '7'
229
+ reference_to: '10'
214
230
  - type: updates
215
231
  bibitem:
216
232
  type: standard
217
- formattedref: ISO 19115:2003/Cor 1:2006
233
+ formattedref:
234
+ content: ISO 19115:2003/Cor 1:2006
218
235
  # series are an array, containing a type, and either a formattedref, or:
219
236
  # a title, a place, an organization (string),
220
237
  # an abbreviation, a from, a to, a number, and a partnumber.
@@ -236,8 +253,8 @@ series:
236
253
  content: ABVR
237
254
  language: en
238
255
  script: Latn
239
- from: 2009-02-01
240
- to: 2010-12-20
256
+ from: '2009-02-01'
257
+ to: '2010-12-20'
241
258
  number: serie1234
242
259
  partnumber: part5678
243
260
  - type: alt
@@ -255,7 +272,7 @@ place: bib place
255
272
  # extent is an array, containing type, a reference_from, and an optional reference_to
256
273
  extent:
257
274
  type: section
258
- reference_from: 7
275
+ reference_from: '7'
259
276
  # accesslocation is an array of strings
260
277
  accesslocation:
261
278
  - accesslocation1
@@ -266,9 +283,9 @@ classification:
266
283
  value: value
267
284
  # validity contains a begins date, an ends date, and a revision date
268
285
  validity:
269
- begins: 2010-10-10 12:21
270
- ends: 2011-02-03 18:30
271
- revision: 2011-03-04 09:00
286
+ begins: '2010-10-10 12:21'
287
+ ends: '2011-02-03 18:30'
288
+ revision: '2011-03-04 09:00'
272
289
  ----
273
290
 
274
291
  == Metanorma structure (AsciiBib): nested definition list
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/>
@@ -115,7 +115,7 @@ module RelatonBib
115
115
  attr_reader :validity
116
116
 
117
117
  # @return [Date]
118
- attr_reader :fetched
118
+ attr_accessor :fetched
119
119
 
120
120
  # @return [Array<RelatonBib::LocalizedString>]
121
121
  attr_reader :keyword
@@ -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
@@ -124,10 +132,11 @@ module RelatonBib
124
132
 
125
133
  # @return [Hash]
126
134
  def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
127
- if content.is_a? String
128
- return content unless language || script
135
+ if content.nil? || content.is_a?(String)
136
+ # return content unless language || script
129
137
 
130
- hash = { "content" => content }
138
+ hash = {}
139
+ hash["content"] = content unless content.nil? || content.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.2".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.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-08-16 00:00:00.000000000 Z
11
+ date: 2022-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -214,6 +214,7 @@ extensions: []
214
214
  extra_rdoc_files: []
215
215
  files:
216
216
  - ".github/workflows/rake.yml"
217
+ - ".github/workflows/release.yml"
217
218
  - ".gitignore"
218
219
  - ".gitmodules"
219
220
  - ".hound.yml"
@@ -251,8 +252,10 @@ files:
251
252
  - lib/relaton_bib/document_status.rb
252
253
  - lib/relaton_bib/edition.rb
253
254
  - lib/relaton_bib/editorial_group.rb
255
+ - lib/relaton_bib/forename.rb
254
256
  - lib/relaton_bib/formatted_ref.rb
255
257
  - lib/relaton_bib/formatted_string.rb
258
+ - lib/relaton_bib/full_name.rb
256
259
  - lib/relaton_bib/hash_converter.rb
257
260
  - lib/relaton_bib/hit.rb
258
261
  - lib/relaton_bib/hit_collection.rb