relaton-bib 1.9.19 → 1.9.23

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: fcf7272c206af7f7206cc3886a744db7a1c0084d1f999164f7971829c16e640e
4
- data.tar.gz: c5260c213ab4542c98e5df926bb638451345fded8b7ebaa76897212aab9bb7c5
3
+ metadata.gz: 69ae43ef45d31008eb5fcfb3939335a6ecb7731a198c7fb944ff671a018180c2
4
+ data.tar.gz: 82154362500a3a1476efd7415ccc37e2a9f8a878b889b2562b51024f8d691884
5
5
  SHA512:
6
- metadata.gz: 5a60302d3043fdac1e1ca6b1ebfbd7244b2788a266d5c6392f1279797f4e4c6fc7f3a951cc05b79bf24c7f2bfc7267bf1d1740ddfefe8534a54156233bb1664a
7
- data.tar.gz: c5f46067ab37b963dee5c04fa9294a9e3522906ae011af2397eb18f88b0c48d37b0727eb44ca78dd17ba77e493a4246a8feef4c338ae68564a320e1cd148c0bf
6
+ metadata.gz: d151df39d087c6dfd66d50eeede28c8b14c3d4551197122f955000611f958fe89b7caa36c05730b77f34e5729ed4838d3d1cb52f85f53169babf624c5ac56c38
7
+ data.tar.gz: 2f0a0f3bf334cd1204eaafe55d90ce4825f6eeed884730f44ae4956ecb43a6bca9356bb27af473b421fb4a4a4ab4ad565721c0ced92f0e7b5b40b5b4a0104a49
@@ -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
@@ -330,15 +330,16 @@ module RelatonBib
330
330
  # Render BibXML (RFC)
331
331
  #
332
332
  # @param [Nokogiri::XML::Builder, nil] builder
333
+ # @param [Boolean] include_keywords (false)
333
334
  #
334
335
  # @return [String, Nokogiri::XML::Builder::NodeBuilder] XML
335
336
  #
336
- def to_bibxml(builder = nil)
337
+ def to_bibxml(builder = nil, include_keywords: false)
337
338
  if builder
338
- render_bibxml builder
339
+ render_bibxml builder, include_keywords
339
340
  else
340
341
  Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
341
- render_bibxml xml
342
+ render_bibxml xml, include_keywords
342
343
  end.doc.root.to_xml
343
344
  end
344
345
  end
@@ -764,14 +765,15 @@ module RelatonBib
764
765
  # Render BibXML (RFC, BCP)
765
766
  #
766
767
  # @param [Nokogiri::XML::Builder] builder
768
+ # @param [Boolean] include_bibdata
767
769
  #
768
- def render_bibxml(builder)
769
- target = link.detect { |l| l.type == "src" } ||
770
- link.detect { |l| l.type == "doi" }
770
+ def render_bibxml(builder, include_keywords)
771
+ target = link.detect { |l| l.type.casecmp("src").zero? } ||
772
+ link.detect { |l| l.type.casecmp("doi").zero? }
771
773
  bxml = if docnumber&.match(/^BCP/) || docidentifier[0].id.include?("BCP")
772
- render_bibxml_refgroup(builder)
774
+ render_bibxml_refgroup(builder, include_keywords)
773
775
  else
774
- render_bibxml_ref(builder)
776
+ render_bibxml_ref(builder, include_keywords)
775
777
  end
776
778
  bxml[:target] = target.content.to_s if target
777
779
  end
@@ -780,11 +782,12 @@ module RelatonBib
780
782
  # Render BibXML (BCP)
781
783
  #
782
784
  # @param [Nokogiri::XML::Builder] builder
785
+ # @param [Boolean] include_keywords
783
786
  #
784
- def render_bibxml_refgroup(builder)
787
+ def render_bibxml_refgroup(builder, include_keywords)
785
788
  builder.referencegroup(**ref_attrs) do |b|
786
789
  relation.each do |r|
787
- r.bibitem.to_bibxml(b) if r.type == "includes"
790
+ r.bibitem.to_bibxml(b, include_keywords: include_keywords) if r.type == "includes"
788
791
  end
789
792
  end
790
793
  end
@@ -793,18 +796,19 @@ module RelatonBib
793
796
  # Render BibXML (RFC)
794
797
  #
795
798
  # @param [Nokogiri::XML::Builder] builder
799
+ # @param [Boolean] include_keywords
796
800
  #
797
- def render_bibxml_ref(builder)
801
+ def render_bibxml_ref(builder, include_keywords)
798
802
  builder.reference(**ref_attrs) do |xml|
799
803
  xml.front do
800
804
  xml.title title[0].title.content if title.any?
801
- render_seriesinfo xml
802
805
  render_authors xml
803
806
  render_date xml
804
807
  render_workgroup xml
805
- render_keyword xml
808
+ render_keyword xml if include_keywords
806
809
  render_abstract xml
807
810
  end
811
+ render_seriesinfo xml
808
812
  end
809
813
  end
810
814
 
@@ -849,8 +853,11 @@ module RelatonBib
849
853
  elm[:year] = y if y
850
854
  m = dt.on(:month) || dt.from(:month) || dt.to(:month)
851
855
  elm[:month] = Date::MONTHNAMES[m] if m
856
+ # rfcs = %w[RFC BCP FYI STD]
857
+ # unless rfcs.include?(doctype) && docidentifier.detect { |di| rfcs.include? di.type }
852
858
  d = dt.on(:day) || dt.from(:day) || dt.to(:day)
853
859
  elm[:day] = d if d
860
+ # end
854
861
  end
855
862
 
856
863
  # @param [Nokogiri::XML::Builder] builder
@@ -860,9 +867,9 @@ module RelatonBib
860
867
  builder.seriesInfo(name: di.type, value: di.id)
861
868
  end
862
869
  end
863
- di_types = docidentifier.map(&:type)
870
+ # di_types = docidentifier.map(&:type)
864
871
  series.select do |s|
865
- s.title && !di_types.include?(s.title.title.to_s) &&
872
+ s.title && # !di_types.include?(s.title.title.to_s) &&
866
873
  !BibXMLParser::SERIESINFONAMES.include?(s.title.title.to_s)
867
874
  end.uniq { |s| s.title.title.to_s }.each do |s|
868
875
  si = builder.seriesInfo(name: s.title.title.to_s)
@@ -920,23 +927,32 @@ module RelatonBib
920
927
  def render_person(builder, person)
921
928
  render_organization builder, person.affiliation.first&.organization
922
929
  if person.name.completename
923
- builder.parent[:fullname] = person.name.completename
930
+ builder.parent[:fullname] = person.name.completename.content
931
+ elsif person.name.forename.any?
932
+ builder.parent[:fullname] = person.name.forename.map(&:content).join
924
933
  end
925
934
  if person.name.initial.any?
926
935
  builder.parent[:initials] = person.name.initial.map(&:content).join
936
+ elsif person.name.forename.any?
937
+ builder.parent[:initials] = person.name.forename.map do |f|
938
+ "#{f.content[0]}."
939
+ end.join
927
940
  end
928
941
  if person.name.surname
929
- builder.parent[:surname] = person.name.surname
942
+ if person.name.forename.any?
943
+ builder.parent[:fullname] += " #{person.name.surname}"
944
+ end
945
+ builder.parent[:surname] = person.name.surname.content
930
946
  end
931
947
  end
932
948
 
933
949
  # @param [Nokogiri::XML::Builder] builder
934
950
  # @param [RelatonBib::Organization] org
935
951
  def render_organization(builder, org)
936
- return unless org
952
+ # return unless org
937
953
 
938
- ab = org.abbreviation&.content
939
- on = org.name.first&.content
954
+ ab = org&.abbreviation&.content
955
+ on = org&.name&.first&.content
940
956
  orgname = if BibXMLParser::ORGNAMES.key?(ab) then ab
941
957
  else BibXMLParser::ORGNAMES.key(on) || on || ab
942
958
  end
@@ -1,7 +1,10 @@
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
7
+
5
8
  ORGNAMES = {
6
9
  "IEEE" => "Istitute of Electrical and Electronics Engineers",
7
10
  "W3C" => "World Wide Web Consortium",
@@ -312,13 +315,15 @@ module RelatonBib
312
315
  # @return [Array<RelatonBib::BibliographicDate>] published data.
313
316
  #
314
317
  def dates(reference)
315
- return unless (date = reference.at "./front/date")
316
-
317
- d = [date[:year], month(date[:month]), (date[:day] || 1)].compact.join "-"
318
- date = Time.parse(d).strftime "%Y-%m-%d"
319
- [BibliographicDate.new(type: "published", on: date)]
320
- rescue ArgumentError
321
- []
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
+ # []
322
327
  end
323
328
 
324
329
  # @param reference [Nokogiri::XML::Element]
@@ -338,10 +343,10 @@ module RelatonBib
338
343
  end
339
344
 
340
345
  def month(mon)
341
- return 1 if !mon || mon.empty?
346
+ # return 1 if !mon || mon.empty?
342
347
  return mon if /^\d+$/.match? mon
343
348
 
344
- Date::MONTHNAMES.index(mon)
349
+ Date::MONTHNAMES.index(mon).to_s.rjust 2, "0"
345
350
  end
346
351
 
347
352
  #
@@ -352,7 +357,7 @@ module RelatonBib
352
357
  #
353
358
  def series(reference)
354
359
  reference.xpath("./seriesInfo", "./front/seriesInfo").map do |si|
355
- next if si[:name] == "DOI" || si[:stream] || si[:status]
360
+ next if SERIESINFONAMES.include?(si[:name]) || si[:stream] || si[:status]
356
361
 
357
362
  t = TypedTitleString.new(
358
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.19".freeze
2
+ VERSION = "1.9.23".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.19
4
+ version: 1.9.23
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-10 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug