relaton-bib 1.16.1 → 1.16.2

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: 6165095300e083fe287e6c6cd187f26f0449d0de89a32aade55d3dc5481c939f
4
- data.tar.gz: fca1f9e076e2d6ed8267c86be8bc0b3fa2bae34a19feddfac306958a2d400016
3
+ metadata.gz: 8098843fe273de5162b5c7f640ed970e78829a22a71aef66675a65bd9eaa60aa
4
+ data.tar.gz: 89e952252458837ebbec87cec74801414f676e0aafea76bf69a7c98157e96c32
5
5
  SHA512:
6
- metadata.gz: 1bf3f71377b6ee41cc12ee9bf80be44c0ab81d10f237535c17372f1ebdd5a17f7f6685ceda9dc684764c85663015be88ecb7a5060680b3a4a7e8af1c8c65ddaf
7
- data.tar.gz: e2fbf83739f64942dc259573446f9925e613a29c822b3158db261d69d5fb9aa42e1468104368a2668cc535b9ee5a3e9b65ce9cdfa1e0b444d03f8d78a95ad079
6
+ metadata.gz: cc73ddea87f2eed0caca6361ec228aaac81d609ac1309d54d6da77aec9f9bdb6ec64182288b670f85c42f80115eb60c6372a3fd7ed240bd9e191ea253e350b9b
7
+ data.tar.gz: f58d6eb817231bc984a8d7928ca4f1d2319497e30debdaa46781a610949056ec5a2bdd768e7a742be77fc30dfd3288ff3006a6cc2dcf0476c7548ac48becc878
@@ -123,20 +123,13 @@ module RelatonBib
123
123
  # @return [RelatonBib::LocalizedString, nil]
124
124
  attr_reader :name
125
125
 
126
- # @return [Array<RelatonBib::FormattedString>]
127
- attr_reader :description
128
-
129
126
  # @return [RelatonBib::Organization]
130
127
  attr_reader :organization
131
128
 
132
- # @param organization [RelatonBib::Organization]
129
+ # @param organization [RelatonBib::Organization, nil]
133
130
  # @param name [RelatonBib::LocalizedString, nil]
134
131
  # @param description [Array<RelatonBib::FormattedString>]
135
- def initialize(organization:, name: nil, description: [])
136
- unless organization.is_a? RelatonBib::Organization
137
- raise ArgumentError, "organization should be an instance of RelatonBib::Organization"
138
- end
139
-
132
+ def initialize(organization: nil, name: nil, description: [])
140
133
  @name = name
141
134
  @organization = organization
142
135
  @description = description
@@ -145,19 +138,44 @@ module RelatonBib
145
138
  # @param opts [Hash]
146
139
  # @option opts [Nokogiri::XML::Builder] :builder XML builder
147
140
  # @option opts [String] :lang language
148
- def to_xml(**opts) # rubocop:disable Metrics/AbcSize
141
+ def to_xml(**opts)
142
+ return unless organization || name || description&.any?
143
+
149
144
  opts[:builder].affiliation do |builder|
150
- builder.name { name.to_xml builder } if name
151
- desc = description.select { |d| d.language&.include? opts[:lang] }
152
- desc = description unless desc.any?
153
- desc.each { |d| builder.description { d.to_xml builder } }
154
- organization.to_xml(**opts)
145
+ name_xml builder
146
+ description_xml builder
147
+ organization&.to_xml(**opts)
155
148
  end
156
149
  end
157
150
 
151
+ def name_xml(builder)
152
+ builder.name { name.to_xml builder } if name
153
+ end
154
+
155
+ def description_xml(builder)
156
+ description.each { |d| builder.description { d.to_xml builder } }
157
+ end
158
+
159
+ #
160
+ # Get description.
161
+ #
162
+ # @param [String, nil] lang language if nil return all description
163
+ #
164
+ # @return return [Array<RelatonBib::FormattedString>] description
165
+ #
166
+ def description(lang = nil)
167
+ return @description unless lang
168
+
169
+ @description.select { |d| d.language&.include? lang }
170
+ end
171
+
172
+ #
173
+ # Render affiliation as hash.
174
+ #
158
175
  # @return [Hash]
176
+ #
159
177
  def to_hash
160
- hash = organization.to_hash
178
+ hash = organization&.to_hash || {}
161
179
  hash["name"] = name.to_hash if name
162
180
  if description&.any?
163
181
  hash["description"] = single_element_array(description)
@@ -175,7 +193,7 @@ module RelatonBib
175
193
  description.each do |d|
176
194
  out += d.to_asciibib "#{pref}affiliation.description", description.size
177
195
  end
178
- out += organization.to_asciibib "#{pref}affiliation.*"
196
+ out += organization.to_asciibib "#{pref}affiliation.*" if organization
179
197
  out
180
198
  end
181
199
  end
@@ -288,9 +288,10 @@ module RelatonBib
288
288
  end
289
289
  FormattedString.new(**cnt)
290
290
  end
291
+ name = LocalizedString.new(a[:name][:content], a[:name][:language], a[:name][:script]) if a[:name]
291
292
  Affiliation.new(
292
293
  organization: Organization.new(**org_hash_to_bib(a[:organization])),
293
- description: a[:description],
294
+ description: a[:description], name: name
294
295
  )
295
296
  end
296
297
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.16.1".freeze
2
+ VERSION = "1.16.2".freeze
3
3
  end
@@ -180,13 +180,11 @@ module RelatonBib
180
180
  #
181
181
  def fetch_series(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/MethodLength,Metrics/PerceivedComplexity
182
182
  item.xpath("./series").reduce([]) do |mem, sr|
183
- abbr = sr.at "abbreviation"
184
- abbreviation = abbr &&
185
- LocalizedString.new(abbr.text, abbr[:language], abbr[:script])
186
183
  formattedref = fref(sr)
187
184
  title = ttitle(sr.at("title"))
188
185
  next mem unless formattedref || title
189
186
 
187
+ abbreviation = localized_string sr.at("abbreviation")
190
188
  mem << Series.new(
191
189
  type: sr[:type], formattedref: formattedref,
192
190
  title: title, place: sr.at("place")&.text,
@@ -310,9 +308,7 @@ module RelatonBib
310
308
  # @param title [Nokogiri::XML::Element]
311
309
  # @return [Array<RelatonBib::LocalizedString>]
312
310
  def variants(elm)
313
- elm.xpath("variant").map do |v|
314
- LocalizedString.new v.text, v[:language], v[:script]
315
- end
311
+ elm.xpath("variant").map { |v| localized_string v }
316
312
  end
317
313
 
318
314
  #
@@ -388,27 +384,20 @@ module RelatonBib
388
384
  #
389
385
  # @param [Nokogiri::XML::Element] person XML element
390
386
  #
391
- # @return [RelatonBib::Person] person
387
+ # @return [RelatonBib::Person, nil] person
392
388
  #
393
- def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
394
- affiliations = person.xpath("./affiliation").map do |a|
395
- org = a.at "./organization"
396
- desc = a.xpath("./description").map do |e|
397
- FormattedString.new(content: e.text, language: e[:language],
398
- script: e[:script], format: e[:format])
399
- end
400
- Affiliation.new organization: get_org(org), description: desc
401
- end
389
+ def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
390
+ return unless person
391
+
392
+ affiliations = person.xpath("./affiliation").map { |a| fetch_affiliation a }
402
393
 
403
394
  contact = parse_contact person
404
395
  identifier = person.xpath("./identifier").map do |pi|
405
396
  PersonIdentifier.new pi[:type], pi.text
406
397
  end
407
398
 
408
- cn = person.at "./name/completename"
409
- cname = cn && LocalizedString.new(cn.text, cn[:language], cn[:script])
410
- sn = person.at "./name/surname"
411
- sname = sn && LocalizedString.new(sn.text, sn[:language], sn[:script])
399
+ cname = localized_string person.at("./name/completename")
400
+ sname = localized_string person.at("./name/surname")
412
401
 
413
402
  name = FullName.new(
414
403
  completename: cname, surname: sname,
@@ -426,6 +415,22 @@ module RelatonBib
426
415
  )
427
416
  end
428
417
 
418
+ def fetch_affiliation(elm)
419
+ org = get_org elm.at("./organization")
420
+ desc = elm.xpath("./description").map do |e|
421
+ FormattedString.new(content: e.text, language: e[:language],
422
+ script: e[:script], format: e[:format])
423
+ end
424
+ name = localized_string elm.at("./name")
425
+ Affiliation.new organization: org, description: desc, name: name
426
+ end
427
+
428
+ def localized_string(elm)
429
+ return unless elm
430
+
431
+ LocalizedString.new(elm.text, elm[:language], elm[:script])
432
+ end
433
+
429
434
  #
430
435
  # Parse contact information
431
436
  #
@@ -467,10 +472,7 @@ module RelatonBib
467
472
  # @return [RelatonBib::LocalizedString, nil] initials
468
473
  #
469
474
  def parse_initials(person)
470
- inits = person.at "./name/formatted-initials"
471
- return unless inits
472
-
473
- LocalizedString.new(inits.text, inits[:language], inits[:script])
475
+ localized_string person.at("./name/formatted-initials")
474
476
  end
475
477
 
476
478
  #
@@ -497,24 +499,21 @@ module RelatonBib
497
499
  # @return [Array<RelatonBib::LocalizedString>] name parts
498
500
  #
499
501
  def name_part(person, part)
500
- person.xpath("./name/#{part}").map do |np|
501
- LocalizedString.new np.text, np[:language], np[:script]
502
- end
502
+ person.xpath("./name/#{part}").map { |np| localized_string np }
503
503
  end
504
504
 
505
505
  # @param item [Nokogiri::XML::Element]
506
506
  # @return [Array<RelatonBib::ContributionInfo>]
507
507
  def fetch_contributors(item)
508
- item.xpath("./contributor").map do |c|
509
- entity = if (org = c.at "./organization") then get_org(org)
510
- elsif (person = c.at "./person") then get_person(person)
511
- end
512
- role = c.xpath("./role").map do |r|
513
- { type: r[:type],
514
- description: r.xpath("./description").map(&:text) }
515
- end
516
- ContributionInfo.new entity: entity, role: role
508
+ item.xpath("./contributor").map { |c| fetch_contribution_info c }
509
+ end
510
+
511
+ def fetch_contribution_info(contrib)
512
+ entity = get_org(contrib.at("./organization")) || get_person(contrib.at("./person"))
513
+ role = contrib.xpath("./role").map do |r|
514
+ { type: r[:type], description: r.xpath("./description").map(&:text) }
517
515
  end
516
+ ContributionInfo.new entity: entity, role: role
518
517
  end
519
518
 
520
519
  # @param item [Nokogiri::XML::Element]
@@ -529,16 +528,13 @@ module RelatonBib
529
528
 
530
529
  # @param item [Nokogiri::XML::Element]
531
530
  # @return [Array<RelatonBib::CopyrightAssociation>]
532
- def fetch_copyright(item) # rubocop:disable Metrics/AbcSize
531
+ def fetch_copyright(item)
533
532
  item.xpath("./copyright").map do |cp|
534
- owner = cp.xpath("owner").map do |o|
535
- ContributionInfo.new entity: get_org(o.at("organization"))
536
- end
533
+ owner = cp.xpath("owner").map { |o| fetch_contribution_info o }
537
534
  from = cp.at("from")&.text
538
535
  to = cp.at("to")&.text
539
536
  scope = cp.at("scope")&.text
540
- CopyrightAssociation.new(owner: owner, from: from, to: to,
541
- scope: scope)
537
+ CopyrightAssociation.new(owner: owner, from: from, to: to, scope: scope)
542
538
  end
543
539
  end
544
540
 
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.16.1
4
+ version: 1.16.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: 2023-09-19 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable