relaton-nist 1.12.4 → 1.12.5

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: a08c33ae20e118a973b19b9697114dd4be09331bc3322a3d75250959c4cb0880
4
- data.tar.gz: 1066aab4db2167b2551fd59a76248a96bbcfddbbcc11e0894cb16d91af0fe69c
3
+ metadata.gz: 4c73a4a75166a362d34e2d1a4bec088d74863cf1ac9a4eee0798cfa84cbceca6
4
+ data.tar.gz: 398bd9b074c7c10da66c86047e617e7b643ea6cc3e45f1daa6fdd6f43d38bb4c
5
5
  SHA512:
6
- metadata.gz: e0b46445fda68e042630f4eccfc925a317dbe22a3331fe5ef86eebcceb7a036134bedba1a2b6679987d4a2b727ee2590887d52a26c014adbbd27b382b70b2adc
7
- data.tar.gz: cdc10291398c3f037a00f7a2b013f3a159ed1b8803a0d401522cfb4df0119036cd7b1a9cbfb28ebdf05819a4f365fd4bc0d284fc3031ef34311418e279e35eba
6
+ metadata.gz: 7695197e53d2d8b8b2048f034c6d47db2ce293f7f8dedafacefae8efb4ad85ed96169f5b317957a228b32bfa1e9a8899b80238aa8be594edd94e89619c9fbb51
7
+ data.tar.gz: 1b2eb51d32d0b0eb9456242e5727b891468509a55cdc2ce2251fa84857b83d6d29966bb3799557672da7cabc126949f0cc18d6581cb9464caa38293a317a7265
@@ -137,26 +137,10 @@ module RelatonNist
137
137
 
138
138
  # @param doc [Nokogiri::XML::Element]
139
139
  # @return [Array<Hash>]
140
- def fetch_contributor(doc) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
140
+ def fetch_contributor(doc)
141
141
  contribs = doc.xpath("contributors/person_name").map do |p|
142
- forename = []
143
- initial = []
144
- p.at("given_name")&.text&.split&.each do |fn|
145
- if /^(?<init>\w)\.?$/ =~ fn
146
- initial << RelatonBib::LocalizedString.new(init, doc["language"], "Latn")
147
- else
148
- forename << RelatonBib::LocalizedString.new(fn, doc["language"], "Latn")
149
- end
150
- end
151
- sname = p.at("surname").text
152
- surname = RelatonBib::LocalizedString.new sname, doc["language"], "Latn"
153
- ident = p.xpath("ORCID").map do |id|
154
- RelatonBib::PersonIdentifier.new "orcid", id.text
155
- end
156
- fullname = RelatonBib::FullName.new(
157
- surname: surname, forename: forename, initial: initial, identifier: ident,
158
- )
159
- person = RelatonBib::Person.new name: fullname, affiliation: affiliation(doc)
142
+ person = RelatonBib::Person.new(name: fullname(p, doc),
143
+ affiliation: affiliation(doc))
160
144
  { entity: person, role: [{ type: p["contributor_role"] }] }
161
145
  end
162
146
  contribs + doc.xpath("publisher").map do |p|
@@ -164,6 +148,57 @@ module RelatonNist
164
148
  end
165
149
  end
166
150
 
151
+ #
152
+ # Create full name object from person name element.
153
+ #
154
+ # @param [Nokogiri::XML::Element] person name element
155
+ # @param [Nokogiri::XML::Element] doc document element
156
+ #
157
+ # @return [RelatonBib::FullName] full name object
158
+ #
159
+ def fullname(person, doc)
160
+ forename, initial = forename_initial(person, doc)
161
+ surname = localized_string person.at("surname").text, doc
162
+ ident = person.xpath("ORCID").map do |id|
163
+ RelatonBib::PersonIdentifier.new "orcid", id.text
164
+ end
165
+ RelatonBib::FullName.new(surname: surname, forename: forename,
166
+ initial: initial, identifier: ident)
167
+ end
168
+
169
+ #
170
+ # Create forename and initials objects from person name element.
171
+ #
172
+ # @param [Nokogiri::XML::Element] person person name element
173
+ # @param [Nokogiri::XML::Element] doc document element
174
+ #
175
+ # @return [Array<Array<RelatonBib::LocalizedString>>] forename and initials
176
+ #
177
+ def forename_initial(person, doc)
178
+ forename = []
179
+ initial = []
180
+ fname = person.at("given_name")&.text
181
+ if fname
182
+ if /^(?<inits>(?:\w[.\s]+|[A-Z]{1,2}$)+)$/ =~ fname
183
+ inits.split(/[.\s]*/).each { |i| initial << localized_string(i, doc) }
184
+ else forename << localized_string(fname, doc)
185
+ end
186
+ end
187
+ [forename, initial]
188
+ end
189
+
190
+ #
191
+ # Create localized string
192
+ #
193
+ # @param [String] content content of string
194
+ # @param [Nokogiri::XML::Elemrnt] doc XML element
195
+ #
196
+ # @return [RelatonBib::LocalizedString] localized string
197
+ #
198
+ def localized_string(content, doc)
199
+ RelatonBib::LocalizedString.new content, doc["language"], "Latn"
200
+ end
201
+
167
202
  #
168
203
  # Create publisher organization
169
204
  #
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.12.4".freeze
2
+ VERSION = "1.12.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.4
4
+ version: 1.12.5
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-07-17 00:00:00.000000000 Z
11
+ date: 2022-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml