relaton-bib 1.9.18 → 1.9.22

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: 974c021271bddc8c3ab783eae039697f62010c33f035e24b2bb96051a6138b8a
4
- data.tar.gz: 71157a9ac56ec96549886354db9b6a301ead662e43ec8abefea1bdc27ec8539c
3
+ metadata.gz: d003dbfecade683b1474dfc3923c2210997574d956f3c96ef0b7b0f113100d66
4
+ data.tar.gz: 6829735611e2ad3807ecb8014b6dddc115f8a2b8799328a11a7b7a229174a49c
5
5
  SHA512:
6
- metadata.gz: fec9fcd2fad29d5128b739fb478b0198bdeeb1a6ab2b9806d8dc73c51290ddcea19fe3481fdc5f104369c34f26fd6e7661a02d5927cf3eed7416b58516cbd915
7
- data.tar.gz: 85890cd5bde2fee2e9fefe9188f4a892019b92414b235bbde5e91453b878b6bbe31d5d8d364939ec6662859c0ec0f9362836d938447ac0b2921fd2ce7863a40c
6
+ metadata.gz: fbb7e6611505b14b7b321893dd4c1941e91b0d52cd2de4ea4f6fe083e1e2378c6f8c34a6fe3c39bb9d028ee81e5548ba435a893483c6e42e16f01030dd230eaa
7
+ data.tar.gz: 01aef015aefc3a321442118ccafd9ae310e9fccab9f57bce7d4e3e2c8c0abf70b9b5d4a1ad3877866daabc2054f572fec72be93311e7d66446c77f119b4ce781
@@ -29,14 +29,22 @@ module RelatonBib
29
29
 
30
30
  # @param part [Symbol] :year, :month, :day, :date
31
31
  # @return [String, Date, nil]
32
- def from(part = nil)
32
+ def from(part = nil) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
33
33
  d = instance_variable_get "@#{__callee__}".to_sym
34
34
  return d unless part && d
35
35
 
36
- date = parse_date(d)
37
- return date if part == :date
36
+ # date = parse_date(d)
37
+ # return date if part == :date
38
38
 
39
- date.is_a?(Date) ? date.send(part) : date
39
+ parts = d.split "-"
40
+ case part
41
+ when :year then parts[0]&.to_i
42
+ when :month then parts[1]&.to_i
43
+ when :day then parts[2]&.to_i
44
+ else parse_date(d)
45
+ end
46
+
47
+ # date.is_a?(Date) ? date.send(part) : date
40
48
  end
41
49
 
42
50
  alias_method :to, :from
@@ -71,7 +79,7 @@ module RelatonBib
71
79
  # @param count [Integer] number of dates
72
80
  # @return [String]
73
81
  def to_asciibib(prefix = "", count = 1)
74
- pref = prefix.empty? ? prefix : prefix + "."
82
+ pref = prefix.empty? ? prefix : "#{prefix}."
75
83
  out = count > 1 ? "#{pref}date::\n" : ""
76
84
  out += "#{pref}date.type:: #{type}\n"
77
85
  out += "#{pref}date.on:: #{on}\n" if on
@@ -165,8 +165,8 @@ module RelatonBib
165
165
  # @option date [String, nil] :to
166
166
  # @option date [String, nil] :on required if :from is nil
167
167
  #
168
- # @param contributor [Array<Hash>]
169
- # @option contributor [RealtonBib::Organization, RelatonBib::Person]
168
+ # @param contributor [Array<Hash, RelatonBib::ContributionInfo>]
169
+ # @option contributor [RealtonBib::Organization, RelatonBib::Person] :entity
170
170
  # @option contributor [String] :type
171
171
  # @option contributor [String] :from
172
172
  # @option contributor [String] :to
@@ -766,8 +766,8 @@ module RelatonBib
766
766
  # @param [Nokogiri::XML::Builder] builder
767
767
  #
768
768
  def render_bibxml(builder)
769
- target = link.detect { |l| l.type == "src" } ||
770
- link.detect { |l| l.type == "doi" }
769
+ target = link.detect { |l| l.type.casecmp("src").zero? } ||
770
+ link.detect { |l| l.type.casecmp("doi").zero? }
771
771
  bxml = if docnumber&.match(/^BCP/) || docidentifier[0].id.include?("BCP")
772
772
  render_bibxml_refgroup(builder)
773
773
  else
@@ -860,9 +860,9 @@ module RelatonBib
860
860
  builder.seriesInfo(name: di.type, value: di.id)
861
861
  end
862
862
  end
863
- di_types = docidentifier.map(&:type)
863
+ # di_types = docidentifier.map(&:type)
864
864
  series.select do |s|
865
- s.title && !di_types.include?(s.title.title.to_s) &&
865
+ s.title && # !di_types.include?(s.title.title.to_s) &&
866
866
  !BibXMLParser::SERIESINFONAMES.include?(s.title.title.to_s)
867
867
  end.uniq { |s| s.title.title.to_s }.each do |s|
868
868
  si = builder.seriesInfo(name: s.title.title.to_s)
@@ -920,13 +920,22 @@ module RelatonBib
920
920
  def render_person(builder, person)
921
921
  render_organization builder, person.affiliation.first&.organization
922
922
  if person.name.completename
923
- builder.parent[:fullname] = person.name.completename
923
+ builder.parent[:fullname] = person.name.completename.content
924
+ elsif person.name.forename.any?
925
+ builder.parent[:fullname] = person.name.forename.map(&:content).join
924
926
  end
925
927
  if person.name.initial.any?
926
928
  builder.parent[:initials] = person.name.initial.map(&:content).join
929
+ elsif person.name.forename.any?
930
+ builder.parent[:initials] = person.name.forename.map do |f|
931
+ "#{f.content[0]}."
932
+ end.join
927
933
  end
928
934
  if person.name.surname
929
- builder.parent[:surname] = person.name.surname
935
+ if person.name.forename.any?
936
+ builder.parent[:fullname] += " #{person.name.surname}"
937
+ end
938
+ builder.parent[:surname] = person.name.surname.content
930
939
  end
931
940
  end
932
941
 
@@ -937,10 +946,8 @@ module RelatonBib
937
946
 
938
947
  ab = org.abbreviation&.content
939
948
  on = org.name.first&.content
940
- orgname = if ab == "IEEE" || on == "Istitute of Electrical and Electronics Engineers"
941
- "IEEE"
942
- elsif ab == "W3C" || on == "World Wide Web Consortium" then "W3C"
943
- else on || ab
949
+ orgname = if BibXMLParser::ORGNAMES.key?(ab) then ab
950
+ else BibXMLParser::ORGNAMES.key(on) || on || ab
944
951
  end
945
952
  o = builder.organization orgname
946
953
  o[:abbrev] = ab if ab
@@ -1,8 +1,15 @@
1
1
  module RelatonBib
2
2
  module BibXMLParser
3
+ # SeriesInfo what should be saved as docidentifiers in the Relaton model.
3
4
  SERIESINFONAMES = ["DOI", "Internet-Draft"].freeze
5
+
4
6
  FLAVOR = nil
5
7
 
8
+ ORGNAMES = {
9
+ "IEEE" => "Istitute of Electrical and Electronics Engineers",
10
+ "W3C" => "World Wide Web Consortium",
11
+ }.freeze
12
+
6
13
  def parse(bibxml, url: nil, is_relation: false, ver: nil)
7
14
  doc = Nokogiri::XML bibxml
8
15
  fetch_rfc doc.at("/referencegroup", "/reference"), url: url, is_relation: is_relation, ver: ver
@@ -209,7 +216,8 @@ module RelatonBib
209
216
  # "front/author[not(@surname)][not(@fullname)]/organization",
210
217
  # ).map do |org|
211
218
  org = contrib.at("./organization")
212
- { entity: new_org(org.text, org[:abbrev]), role: [contributor_role(contrib)] }
219
+ name = ORGNAMES[org.text] || org.text
220
+ { entity: new_org(name, org[:abbrev]), role: [contributor_role(contrib)] }
213
221
  # end
214
222
  end
215
223
 
@@ -307,13 +315,15 @@ module RelatonBib
307
315
  # @return [Array<RelatonBib::BibliographicDate>] published data.
308
316
  #
309
317
  def dates(reference)
310
- return unless (date = reference.at "./front/date")
311
-
312
- d = [date[:year], month(date[:month]), (date[:day] || 1)].compact.join "-"
313
- date = Time.parse(d).strftime "%Y-%m-%d"
314
- [BibliographicDate.new(type: "published", on: date)]
315
- rescue ArgumentError
316
- []
318
+ return [] unless (date = reference.at "./front/date")
319
+
320
+ d = date[:year]
321
+ d += "-#{month(date[:month])}" if date[:month] && !date[:month].empty?
322
+ d += "-#{date[:day]}" if date[:day]
323
+ # date = Time.parse(d).strftime "%Y-%m-%d"
324
+ [BibliographicDate.new(type: "published", on: d)]
325
+ # rescue ArgumentError
326
+ # []
317
327
  end
318
328
 
319
329
  # @param reference [Nokogiri::XML::Element]
@@ -333,10 +343,10 @@ module RelatonBib
333
343
  end
334
344
 
335
345
  def month(mon)
336
- return 1 if !mon || mon.empty?
346
+ # return 1 if !mon || mon.empty?
337
347
  return mon if /^\d+$/.match? mon
338
348
 
339
- Date::MONTHNAMES.index(mon)
349
+ Date::MONTHNAMES.index(mon).to_s.rjust 2, "0"
340
350
  end
341
351
 
342
352
  #
@@ -347,7 +357,7 @@ module RelatonBib
347
357
  #
348
358
  def series(reference)
349
359
  reference.xpath("./seriesInfo", "./front/seriesInfo").map do |si|
350
- next if si[:name] == "DOI" || si[:stream] || si[:status]
360
+ next if SERIESINFONAMES.include?(si[:name]) || si[:stream] || si[:status]
351
361
 
352
362
  t = TypedTitleString.new(
353
363
  content: si[:name], language: language(reference), script: "Latn",
@@ -25,7 +25,7 @@ module RelatonBib
25
25
  # @param state [String]
26
26
  # @param country [String]
27
27
  # @param postcode [String]
28
- def initialize(street:, city:, state: nil, country:, postcode: nil)
28
+ def initialize(street:, city:, country:, state: nil, postcode: nil)
29
29
  @street = street
30
30
  @city = city
31
31
  @state = state
@@ -45,7 +45,7 @@ module RelatonBib
45
45
  end
46
46
 
47
47
  # @return [Hash]
48
- def to_hash
48
+ def to_hash # rubocop:disable Metrics/AbcSize
49
49
  hash = {}
50
50
  hash["street"] = street if street&.any?
51
51
  hash["city"] = city
@@ -59,7 +59,7 @@ module RelatonBib
59
59
  # @param count [Integer] number of addresses
60
60
  # @return [String]
61
61
  def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
62
- pref = prefix.empty? ? "address" : prefix + ".address"
62
+ pref = prefix.empty? ? "address" : "#{prefix}.address"
63
63
  out = count > 1 ? "#{pref}::\n" : ""
64
64
  street.each { |st| out += "#{pref}.street:: #{st}\n" }
65
65
  out += "#{pref}.city:: #{city}\n"
@@ -99,7 +99,7 @@ module RelatonBib
99
99
  # @param count [Integer] number of contacts
100
100
  # @return [string]
101
101
  def to_asciibib(prefix = "", count = 1)
102
- pref = prefix.empty? ? prefix : prefix + "."
102
+ pref = prefix.empty? ? prefix : "#{prefix}."
103
103
  out = count > 1 ? "#{pref}contact::\n" : ""
104
104
  out += "#{pref}contact.type:: #{type}\n"
105
105
  out += "#{pref}contact.value:: #{value}\n"
@@ -156,7 +156,7 @@ module RelatonBib
156
156
  # @param count [Integer]
157
157
  # @return [String]
158
158
  def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
159
- pref = prefix.empty? ? prefix : prefix + "."
159
+ pref = prefix.empty? ? prefix : "#{prefix}."
160
160
  out = count > 1 ? "#{pref}affiliation::\n" : ""
161
161
  out += name.to_asciibib "#{pref}affiliation.name" if name
162
162
  description.each do |d|
@@ -206,7 +206,7 @@ module RelatonBib
206
206
  # @param prefix [String]
207
207
  # @return [String]
208
208
  def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
209
- pref = prefix.empty? ? prefix : prefix + "."
209
+ pref = prefix.empty? ? prefix : "#{prefix}."
210
210
  out = ""
211
211
  out += "#{pref}url:: #{uri}\n" if uri
212
212
  addr = contact.select { |c| c.is_a? RelatonBib::Address }
@@ -39,7 +39,7 @@ module RelatonBib
39
39
  # @param count [Integer]
40
40
  # @return [String]
41
41
  def to_asciibib(prefix = "", count = 1)
42
- pref = prefix.empty? ? prefix : prefix + "."
42
+ pref = prefix.empty? ? prefix : "#{prefix}."
43
43
  out = count > 1 ? "#{pref}identifier::\n" : ""
44
44
  out += "#{pref}identifier.type:: #{type}\n"
45
45
  out += "#{pref}identifier.value:: #{value}\n"
@@ -118,7 +118,7 @@ module RelatonBib
118
118
  # @param count [Integer]
119
119
  # @return [String]
120
120
  def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
121
- pref = prefix.sub /\*$/, "organization"
121
+ pref = prefix.sub(/\*$/, "organization")
122
122
  out = count > 1 ? "#{pref}::\n" : ""
123
123
  name.each { |n| out += n.to_asciibib "#{pref}.name", name.size }
124
124
  out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
@@ -136,10 +136,11 @@ module RelatonBib
136
136
  # @param arg [String, Hash, RelatoBib::LocalizedString]
137
137
  # @return [RelatoBib::LocalizedString]
138
138
  def localized_string(arg)
139
- if arg.is_a?(String) then LocalizedString.new(arg)
140
- elsif arg.is_a?(Hash)
139
+ case arg
140
+ when String then LocalizedString.new(arg)
141
+ when Hash
141
142
  LocalizedString.new(arg[:content], arg[:language], arg[:script])
142
- elsif arg.is_a? LocalizedString then arg
143
+ when LocalizedString then arg
143
144
  end
144
145
  end
145
146
  end
@@ -13,7 +13,7 @@ module RelatonBib
13
13
  # @return [RelatonBib::FormattedRef, NilClass]
14
14
  attr_reader :formattedref
15
15
 
16
- # @return [RelatonBib::FormattedString, NilClass] title
16
+ # @return [RelatonBib::TypedTitleString, NilClass] title
17
17
  attr_reader :title
18
18
 
19
19
  # @return [String, NilClass]
@@ -39,10 +39,10 @@ module RelatonBib
39
39
 
40
40
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
41
 
42
- # @param type [String, NilClass] title or formattedref argument should be
43
- # passed
42
+ # @param type [String, NilClass]
44
43
  # @param formattedref [RelatonBib::FormattedRef, NilClass]
45
- # @param title [RelatonBib::TypedTitleString, NilClass]
44
+ # @param title [RelatonBib::TypedTitleString, NilClass] title or
45
+ # formattedref argument should be passed
46
46
  # @param place [String, NilClass]
47
47
  # @param orgaization [String, NilClass]
48
48
  # @param abbreviation [RelatonBib::LocalizedString, NilClass]
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.9.18".freeze
2
+ VERSION = "1.9.22".freeze
3
3
  end
@@ -238,11 +238,12 @@ module RelatonBib
238
238
  OrgIdentifier.new(i[:type], i.text)
239
239
  end
240
240
  subdiv = org.xpath("subdivision").map &:text
241
- Organization.new(name: names,
242
- abbreviation: org.at("abbreviation")&.text,
243
- subdivision: subdiv,
244
- url: org.at("uri")&.text,
245
- identifier: identifier)
241
+ contact = parse_contact org
242
+ Organization.new(
243
+ name: names, abbreviation: org.at("abbreviation")&.text,
244
+ subdivision: subdiv, # url: org.at("uri")&.text,
245
+ identifier: identifier, contact: contact
246
+ )
246
247
  end
247
248
 
248
249
  def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
@@ -255,21 +256,7 @@ module RelatonBib
255
256
  Affiliation.new organization: get_org(org), description: desc
256
257
  end
257
258
 
258
- contact = person.xpath("./address|./phone|./email|./uri").map do |c|
259
- if c.name == "address"
260
- streets = c.xpath("./street").map(&:text)
261
- Address.new(
262
- street: streets,
263
- city: c.at("./city")&.text,
264
- state: c.at("./state")&.text,
265
- country: c.at("./country")&.text,
266
- postcode: c.at("./postcode")&.text,
267
- )
268
- else
269
- Contact.new(type: c.name, value: c.text)
270
- end
271
- end
272
-
259
+ contact = parse_contact person
273
260
  identifier = person.xpath("./identifier").map do |pi|
274
261
  PersonIdentifier.new pi[:type], pi.text
275
262
  end
@@ -295,6 +282,23 @@ module RelatonBib
295
282
  )
296
283
  end
297
284
 
285
+ def parse_contact(contrib) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/AbcSize
286
+ contrib.xpath("./address|./phone|./email|./uri").map do |c|
287
+ if c.name == "address"
288
+ streets = c.xpath("./street").map(&:text)
289
+ Address.new(
290
+ street: streets,
291
+ city: c.at("./city")&.text,
292
+ state: c.at("./state")&.text,
293
+ country: c.at("./country")&.text,
294
+ postcode: c.at("./postcode")&.text,
295
+ )
296
+ else
297
+ Contact.new(type: c.name, value: c.text)
298
+ end
299
+ end
300
+ end
301
+
298
302
  def name_part(person, part)
299
303
  person.xpath("./name/#{part}").map do |np|
300
304
  LocalizedString.new np.text, np[:language], np[:script]
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.9.18
4
+ version: 1.9.22
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-01-09 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug