relaton-bib 1.9.8 → 1.9.12

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: cea4f63e62a2c6abff013361c4851294799cee45bcbe44a52ee8158501505f5f
4
- data.tar.gz: 1d973d98047232ff7167257beafc0ed339177b27eb878918d9bcf0cc8f7d7301
3
+ metadata.gz: 791772f93f6ec77db4778d4b983bd5b8238342ce83e3b1ebc7ab57f249a13d20
4
+ data.tar.gz: fffd96ca42623382338182a6cb6532fde99c18ebddfd516808f49eb493d31cd6
5
5
  SHA512:
6
- metadata.gz: e21ef90933920055d91d952e2b5513279d4dd61559ead7aebef9db0d7df4b15283bdd5d2cf77decb16d4e4f8d573f38c4c872582dfcdfbd0899703e4b8a9b152
7
- data.tar.gz: 471d57586461900b6805df5c8d536591a2d0377e3da455af5708dbfa37aa13a4960bdee00f7c54de052763332de81b31f862dc9b4acc21a9992c3c52eba08d7a
6
+ metadata.gz: b5440de1b9a0555946b6be63f5c557d9f91b54c247d5876e5f8aaf4e74bfefa1f91d526a1453c99a401e2d82e03ed07af66e2f950a4e0f51d844e9ba0738c427
7
+ data.tar.gz: 8addf5e0b704189efdb1a6f871553c79ef23d1c38c324e728d9e72151a9c7317029340f3b0f4ad25b394a6acfcee679532c3f323a37aab0b0946bb33ce88461a
@@ -331,7 +331,7 @@ module RelatonBib
331
331
  #
332
332
  # @param [Nokogiri::XML::Builder, nil] builder
333
333
  #
334
- # @return [String] <description>
334
+ # @return [String, Nokogiri::XML::Builder::NodeBuilder] XML
335
335
  #
336
336
  def to_bibxml(builder = nil)
337
337
  if builder
@@ -339,8 +339,8 @@ module RelatonBib
339
339
  else
340
340
  Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
341
341
  render_bibxml xml
342
- end
343
- end.doc.root.to_xml
342
+ end.doc.root.to_xml
343
+ end
344
344
  end
345
345
 
346
346
  # @return [Hash]
@@ -761,13 +761,41 @@ module RelatonBib
761
761
  # rubocop:enable Style/NestedParenthesizedCalls, Metrics/BlockLength
762
762
 
763
763
  #
764
- # Render BibXML (RFC)
764
+ # Render BibXML (RFC, BCP)
765
765
  #
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" }
770
- bxml = builder.reference(anchor: anchor) do |xml|
769
+ target = link.detect { |l| l.type == "src" } ||
770
+ link.detect { |l| l.type == "doi" }
771
+ bxml = if docnumber&.match(/^BCP/) || docidentifier[0].id.include?("BCP")
772
+ render_bibxml_refgroup(builder)
773
+ else
774
+ render_bibxml_ref(builder)
775
+ end
776
+ bxml[:target] = target.content.to_s if target
777
+ end
778
+
779
+ #
780
+ # Render BibXML (BCP)
781
+ #
782
+ # @param [Nokogiri::XML::Builder] builder
783
+ #
784
+ def render_bibxml_refgroup(builder)
785
+ builder.referencegroup(**ref_attrs) do |b|
786
+ relation.each do |r|
787
+ r.bibitem.to_bibxml(b) if r.type == "includes"
788
+ end
789
+ end
790
+ end
791
+
792
+ #
793
+ # Render BibXML (RFC)
794
+ #
795
+ # @param [Nokogiri::XML::Builder] builder
796
+ #
797
+ def render_bibxml_ref(builder)
798
+ builder.reference(**ref_attrs) do |xml|
771
799
  xml.front do
772
800
  xml.title title[0].title.content if title.any?
773
801
  render_seriesinfo xml
@@ -778,21 +806,29 @@ module RelatonBib
778
806
  render_abstract xml
779
807
  end
780
808
  end
781
- bxml[:target] = target.content.to_s if target
782
809
  end
783
810
 
784
- def anchor
785
- did = docidentifier.detect { |di| di.type == "rfc-anchor" }
786
- 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)
815
+
816
+ h[di.scope.to_sym] = di.id
817
+ end
818
+ # did = docidentifier.detect { |di| di.type == "rfc-anchor" }
819
+ return attrs if attrs.any?
787
820
 
788
- type = docidentifier[0].type
789
- "#{type}.#{docnumber}"
821
+ docidentifier.first&.tap do |di|
822
+ return { anchor: di.id }
823
+ end
790
824
  end
791
825
 
826
+ # def id_to_ref_attr(id)
827
+ # id.sub(/^(RFC|BCP)\s/, '\1').sub(/^(\d?[A-Z]+)\s/, '\1.')
828
+ # end
829
+
792
830
  def render_keyword(builder)
793
- keyword.each do |kw|
794
- builder.keyword kw.content
795
- end
831
+ keyword.each { |kw| builder.keyword kw.content }
796
832
  end
797
833
 
798
834
  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)
@@ -70,13 +70,21 @@ module RelatonBib
70
70
  sfid = reference.at("./seriesInfo[@name='#{self::FLAVOR}']",
71
71
  "./front/seriesInfo[@name='#{self::FLAVOR}']")
72
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 "))
76
- end
77
- if (id = reference[:anchor])
78
- ret << DocumentIdentifier.new(type: "rfc-anchor", id: id)
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&.match(/^(3GPP|W3C|[A-Z]{2,})(?:\.(?=[A-Z])|(?=\d))/)
82
+ type = self::FLAVOR || ($~ && $~[1])
79
83
  end
84
+ ret << DocumentIdentifier.new(type: type, id: id, scope: scope) if id
85
+ # if (id = reference[:anchor])
86
+ # ret << DocumentIdentifier.new(type: "rfc-anchor", id: id)
87
+ # end
80
88
  ret + reference.xpath("./seriesInfo", "./front/seriesInfo").map do |si|
81
89
  next unless SERIESINFONAMES.include? si[:name]
82
90
 
@@ -139,10 +147,10 @@ module RelatonBib
139
147
  # @return [Array<RelatonBib::FormattedString>]
140
148
  def abstracts(ref)
141
149
  ref.xpath("./front/abstract").map do |a|
142
- FormattedString.new(
143
- content: a.children.to_s.gsub(/(<\/?)t(>)/, '\1p\2'),
144
- language: language(ref), script: "Latn", format: "text/html"
145
- )
150
+ c = a.children.to_s.gsub(/\s*(<\/?)t(>)\s*/, '\1p\2')
151
+ .gsub(/[\t\n]/, " ").squeeze " "
152
+ FormattedString.new(content: c, language: language(ref), script: "Latn",
153
+ format: "text/html")
146
154
  end
147
155
  end
148
156
 
@@ -245,7 +253,7 @@ module RelatonBib
245
253
  # @rerurn [RelatonBib::Address]
246
254
  def address(postal) # rubocop:disable Metrics/CyclomaticComplexity
247
255
  street = [
248
- (postal.at("./postalLine") || postal.at("./street"))&.text
256
+ (postal.at("./postalLine") || postal.at("./street"))&.text,
249
257
  ].compact
250
258
  Address.new(
251
259
  street: street,
@@ -189,8 +189,8 @@ module RelatonBib
189
189
  # @option opts [String, Symbol] :lang language
190
190
  def to_xml(**opts)
191
191
  opts[:builder].person do |builder|
192
- name.to_xml **opts
193
- affiliation.each { |a| a.to_xml **opts }
192
+ name.to_xml(**opts)
193
+ affiliation.each { |a| a.to_xml(**opts) }
194
194
  identifier.each { |id| id.to_xml builder }
195
195
  contact.each { |contact| contact.to_xml builder }
196
196
  end
@@ -210,7 +210,7 @@ module RelatonBib
210
210
  # @count [Integer] number of persons
211
211
  # @return [String]
212
212
  def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
213
- pref = prefix.sub /\*$/, "person"
213
+ pref = prefix.sub(/\*$/, "person")
214
214
  out = count > 1 ? "#{pref}::\n" : ""
215
215
  out += name.to_asciibib pref
216
216
  affiliation.each { |af| out += af.to_asciibib pref, affiliation.size }
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.9.8".freeze
2
+ VERSION = "1.9.12".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.8
4
+ version: 1.9.12
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-19 00:00:00.000000000 Z
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug