relaton-bib 1.9.11 → 1.9.15

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: a3f1dc44ef7d2716e9dab35fdb81005962960fb608d388b2d556073758f3cf25
4
- data.tar.gz: e31e80c8a248a626bf83bc85e0f3d781544e5461c65e805d1a8ff45025808caa
3
+ metadata.gz: df627fef24296d28c6a6802972a545ce575e89065efc41d07a1783c05fa9d1ad
4
+ data.tar.gz: aff5fe6709c54247e238523cbb49b04137723dc2264e79c054415b1ed29bd706
5
5
  SHA512:
6
- metadata.gz: 90256a1674ec5311fd7fedb5d0822a5cb10bb9ecaf6c7f5865d74b9a28e6b4feaa969fae327610726720524010db1f1d290dbad48902a3b6e4a86e468542179f
7
- data.tar.gz: 29cfeccc2388db9096b094274653800499a4a40a52b7102e9283e64030e921edd37a93ea8c70f92cd2056ac654a2e8b9a4184ca08a05863365f12fa6c15e6305
6
+ metadata.gz: e787baf783f229454cbf25423e6ed998476df6d3a4a70654f43c6385be9e74f92913f5526f6d589b5e5c3a23de2123e578109bac9cef79d76734c9c67a6100b1
7
+ data.tar.gz: e1977eb5ab24edd762217c6799319adfb4da51decf4cd9d1cf0660d1e2102eeb568a47a734a9bff40e45748c6fa08efd17f1e094d76fc8285bfb59e100b42637
@@ -766,7 +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" } || link.detect { |l| l.type == "doi" }
769
+ target = link.detect { |l| l.type == "src" } ||
770
+ link.detect { |l| l.type == "doi" }
770
771
  bxml = if docnumber&.match(/^BCP/) || docidentifier[0].id.include?("BCP")
771
772
  render_bibxml_refgroup(builder)
772
773
  else
@@ -781,7 +782,7 @@ module RelatonBib
781
782
  # @param [Nokogiri::XML::Builder] builder
782
783
  #
783
784
  def render_bibxml_refgroup(builder)
784
- builder.referencegroup(anchor: anchor) do |b|
785
+ builder.referencegroup(**ref_attrs) do |b|
785
786
  relation.each do |r|
786
787
  r.bibitem.to_bibxml(b) if r.type == "includes"
787
788
  end
@@ -794,7 +795,7 @@ module RelatonBib
794
795
  # @param [Nokogiri::XML::Builder] builder
795
796
  #
796
797
  def render_bibxml_ref(builder)
797
- builder.reference(anchor: anchor) do |xml|
798
+ builder.reference(**ref_attrs) do |xml|
798
799
  xml.front do
799
800
  xml.title title[0].title.content if title.any?
800
801
  render_seriesinfo xml
@@ -807,18 +808,22 @@ module RelatonBib
807
808
  end
808
809
  end
809
810
 
810
- def anchor
811
- did = docidentifier.detect { |di| di.type == "rfc-anchor" }
812
- return did.id if did
811
+ def ref_attrs
812
+ discopes = %w[anchor docName number]
813
+ attrs = docidentifier.each_with_object({}) do |di, h|
814
+ next unless discopes.include?(di.scope)
813
815
 
814
- type = docidentifier[0].type
815
- "#{type}.#{docnumber}"
816
+ h[di.scope.to_sym] = di.id
817
+ end
818
+ return attrs if attrs.any?
819
+
820
+ docidentifier.first&.tap do |di|
821
+ return { anchor: di.id }
822
+ end
816
823
  end
817
824
 
818
825
  def render_keyword(builder)
819
- keyword.each do |kw|
820
- builder.keyword kw.content
821
- end
826
+ keyword.each { |kw| builder.keyword kw.content }
822
827
  end
823
828
 
824
829
  def render_workgroup(builder)
@@ -45,7 +45,7 @@ module RelatonBib
45
45
  end
46
46
 
47
47
  # @param attrs [Hash]
48
- # @return [RelatonBib::IetfBibliographicItem]
48
+ # @return [RelatonBib::BibliographicItem]
49
49
  def bib_item(**attrs)
50
50
  # attrs[:place] = ["Fremont, CA"]
51
51
  BibliographicItem.new(**attrs)
@@ -67,16 +67,39 @@ module RelatonBib
67
67
  #
68
68
  def docids(reference, ver) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize
69
69
  ret = []
70
- sfid = reference.at("./seriesInfo[@name='#{self::FLAVOR}']",
71
- "./front/seriesInfo[@name='#{self::FLAVOR}']")
72
- if sfid
73
- ret << DocumentIdentifier.new(type: sfid[:name], id: sfid[:value])
74
- elsif self::FLAVOR && (id = (reference[:anchor] || reference[:docName] || reference[:number]))
75
- ret << DocumentIdentifier.new(type: self::FLAVOR, id: id.sub(/^(RFC)/, "\\1 "))
70
+ # sfid = reference.at("./seriesInfo[@name='#{self::FLAVOR}']",
71
+ # "./front/seriesInfo[@name='#{self::FLAVOR}']")
72
+ # if sfid
73
+ # type = sfid[:name]
74
+ # id = sfid[:value]
75
+ # # scope = "series"
76
+ # else # if self::FLAVOR
77
+ # id, scope = if reference[:anchor] then [reference[:anchor], "anchor"]
78
+ # elsif reference[:docName] then [reference[:docName], "docName"]
79
+ # elsif reference[:number] then [reference[:number], "number"]
80
+ # end
81
+ id = reference["anchor"] || reference["docName"] || reference["number"]
82
+ type_match = id&.match(/^(3GPP|W3C|[A-Z]{2,})(?:\.(?=[A-Z])|(?=\d))/)
83
+ type = self::FLAVOR || (type_match && type_match[1])
84
+ if id
85
+ /^(?<pref>I-D|3GPP|W3C|[A-Z]{2,})\.?(?<num>.+)/ =~ id
86
+ num.sub!(/^-?0+/, "") if %w[RFC BCP FYI STD].include?(pref)
87
+ pid = pref ? "#{pref} #{num}" : id
88
+ ret << DocumentIdentifier.new(type: type, id: pid)
76
89
  end
77
- if (id = reference[:anchor])
78
- ret << DocumentIdentifier.new(type: "rfc-anchor", id: id)
90
+ %w[anchor docName number].each do |atr|
91
+ if reference[atr]
92
+ ret << DocumentIdentifier.new(id: reference[atr], type: type, scope: atr)
93
+ end
79
94
  end
95
+ # end
96
+ # if id
97
+ # ret << DocumentIdentifier.new(type: type, id: id)
98
+ # ret << DocumentIdentifier.new(type: type, id: id, scope: scope) if scope
99
+ # end
100
+ # if (id = reference[:anchor])
101
+ # ret << DocumentIdentifier.new(type: "rfc-anchor", id: id)
102
+ # end
80
103
  ret + reference.xpath("./seriesInfo", "./front/seriesInfo").map do |si|
81
104
  next unless SERIESINFONAMES.include? si[:name]
82
105
 
@@ -139,7 +162,8 @@ module RelatonBib
139
162
  # @return [Array<RelatonBib::FormattedString>]
140
163
  def abstracts(ref)
141
164
  ref.xpath("./front/abstract").map do |a|
142
- c = a.children.to_s.gsub(/\s*(<\/?)t(>)\s*/, '\1p\2').gsub(/\n/, "").squeeze " "
165
+ c = a.children.to_s.gsub(/\s*(<\/?)t(>)\s*/, '\1p\2')
166
+ .gsub(/[\t\n]/, " ").squeeze " "
143
167
  FormattedString.new(content: c, language: language(ref), script: "Latn",
144
168
  format: "text/html")
145
169
  end
@@ -244,7 +268,7 @@ module RelatonBib
244
268
  # @rerurn [RelatonBib::Address]
245
269
  def address(postal) # rubocop:disable Metrics/CyclomaticComplexity
246
270
  street = [
247
- (postal.at("./postalLine") || postal.at("./street"))&.text
271
+ (postal.at("./postalLine") || postal.at("./street"))&.text,
248
272
  ].compact
249
273
  Address.new(
250
274
  street: street,
@@ -20,7 +20,7 @@ module RelatonBib
20
20
  def remove_part
21
21
  case @type
22
22
  when "Chinese Standard" then @id.sub!(/\.\d+/, "")
23
- when "ISO", "IEC" then @id.sub!(/-[^:]+/, "")
23
+ when "ISO", "IEC", "BSI" then @id.sub!(/-[^:]+/, "")
24
24
  when "URN" then remove_urn_part
25
25
  end
26
26
  end
@@ -28,7 +28,7 @@ module RelatonBib
28
28
  def remove_date
29
29
  case @type
30
30
  when "Chinese Standard" then @id.sub!(/-[12]\d\d\d/, "")
31
- when "ISO", "IEC" then @id.sub!(/:[12]\d\d\d/, "")
31
+ when "ISO", "IEC", "BSI" then @id.sub!(/:[12]\d\d\d/, "")
32
32
  when "URN"
33
33
  @id.sub!(/^(urn:iec:std:[^:]+:[^:]+:)[^:]*/, '\1')
34
34
  end
@@ -69,8 +69,8 @@ module RelatonBib
69
69
  # @param prefix [String]
70
70
  # @param count [Integer] number of docids
71
71
  # @return [String]
72
- def to_asciibib(prefix = "", count = 1)
73
- pref = prefix.empty? ? prefix : prefix + "."
72
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity
73
+ pref = prefix.empty? ? prefix : "#{prefix}."
74
74
  return "#{pref}docid:: #{id}\n" unless type || scope
75
75
 
76
76
  out = count > 1 ? "#{pref}docid::\n" : ""
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.9.11".freeze
2
+ VERSION = "1.9.15".freeze
3
3
  end
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.11
4
+ version: 1.9.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug