relaton-bib 1.10.3 → 1.10.4

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: f5d4afe9383395a6aedab41481f8cd61e54705b875a070a6a0c96e60bf34eb35
4
- data.tar.gz: ef3ad715dbe15c38ed939b7860ddc8fcda697c2937d3b92bc698432d5a682fb6
3
+ metadata.gz: 826acb78507045bc31dd931b706331e248a682507b1454df64d957f97a856fce
4
+ data.tar.gz: 2a8bd874712691f4586d0a0d75f4c102731d592abf484ddd70a97cc7a2d72c24
5
5
  SHA512:
6
- metadata.gz: 345f8b3198bef26aa58297acafff8386e906075220aa73bfdfc68ca07b0435049a5ee89c77b85ef46af57b26cf073622a50d6be7e519372446de13453366c859
7
- data.tar.gz: fa4ec221835cb39a95c4f39ada023a603a59e493d0170ca78785869bc8bcd13477a50484dd29470bd5d7030ecf70b4f18cce7c11edc6546f0129c36fd599e156
6
+ metadata.gz: ff8a95d1afc8c44ce738e6c48cefa65d87fe2f5f2d431e5d5933d8ded66ba577797e55933b8f8082f6dc21841ec68dc3de16c8579d7b5a5af539229f183700c2
7
+ data.tar.gz: a2a7c1b255cffefcc84c93542062ff42a34b4b6e3c6b1077cb3f6a49c4c2002724ab6cb2f20d54a53fd6a06c423a7a0b43b762ebc0417be30bb85055116cc4a5
@@ -1,7 +1,7 @@
1
1
  module RelatonBib
2
2
  module BibXMLParser
3
3
  # SeriesInfo what should be saved as docidentifiers in the Relaton model.
4
- SERIESINFONAMES = ["DOI", "Internet-Draft"].freeze
4
+ SERIESINFONAMES = ["DOI"].freeze
5
5
 
6
6
  FLAVOR = nil
7
7
 
@@ -75,27 +75,55 @@ module RelatonBib
75
75
  #
76
76
  def docids(reference, ver) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/AbcSize
77
77
  ret = []
78
- id = reference["anchor"] || reference["docName"] || reference["number"]
79
- if id
80
- /^(?<pref>I-D|3GPP|W3C|[A-Z]{2,})[._]?(?<num>.+)/ =~ id
81
- num.sub!(/^-?0+/, "") if %w[RFC BCP FYI STD].include?(pref)
82
- pid = pref ? "#{pref} #{num}" : id
83
- ret << DocumentIdentifier.new(type: pubid_type(id), id: pid, primary: true)
78
+ si = reference.at("./seriesInfo[@name='Internet-Draft']",
79
+ "./front/seriesInfo[@name='Internet-Draft']")
80
+ if si
81
+ id = si[:value]
82
+ id.sub!(/(?<=-)\d{2}$/, ver) if ver
83
+ ret << DocumentIdentifier.new(type: "Internet-Draft", id: id, primary: true)
84
+ else
85
+ id = reference["anchor"] || reference["docName"] || reference["number"]
86
+ ret << create_docid(id, ver) if id
84
87
  end
88
+
85
89
  %w[anchor docName number].each do |atr|
86
90
  if reference[atr]
87
- ret << DocumentIdentifier.new(id: reference[atr], type: pubid_type(id), scope: atr)
91
+ type = pubid_type id
92
+ ret << DocumentIdentifier.new(id: reference[atr], type: type, scope: atr)
88
93
  end
89
94
  end
95
+
90
96
  ret + reference.xpath("./seriesInfo", "./front/seriesInfo").map do |si|
91
97
  next unless SERIESINFONAMES.include? si[:name]
92
98
 
93
99
  id = si[:value]
94
- id.sub!(/(?<=-)\d{2}$/, ver) if ver && si[:name] == "Internet-Draft"
100
+ # id.sub!(/(?<=-)\d{2}$/, ver) if ver && si[:name] == "Internet-Draft"
95
101
  DocumentIdentifier.new(id: id, type: si[:name])
96
102
  end.compact
97
103
  end
98
104
 
105
+ def create_docid(id, ver) # rubocop:disable Metrics/MethodLength
106
+ pref, num = id_to_pref_num(id)
107
+ if %w[RFC BCP FYI STD].include?(pref)
108
+ num.sub!(/^-?0+/, "")
109
+ pid = "#{pref} #{num}"
110
+ type = pubid_type id
111
+ elsif %w[I-D draft].include?(pref)
112
+ pid = "draft-#{num}"
113
+ pid.sub!(/(?<=-)\d{2}$/, ver) if ver
114
+ type = "Internet-Draft"
115
+ else
116
+ pid = pref ? "#{pref} #{num}" : num
117
+ type = pubid_type id
118
+ end
119
+ DocumentIdentifier.new(type: type, id: pid, primary: true)
120
+ end
121
+
122
+ def id_to_pref_num(id)
123
+ tn = /^(?<pref>I-D|draft|3GPP|W3C|[A-Z]{2,})[._-]?(?<num>.+)/.match id
124
+ tn && tn.to_a[1..2]
125
+ end
126
+
99
127
  #
100
128
  # Extract document identifier type from identifier
101
129
  #
@@ -104,8 +132,7 @@ module RelatonBib
104
132
  # @return [String]
105
133
  #
106
134
  def pubid_type(id)
107
- type_match = id&.match(/^(3GPP|W3C|[A-Z]{2,})(?:\.(?=[A-Z])|(?=\d))/)
108
- type_match && type_match[1]
135
+ id_to_pref_num(id)&.first
109
136
  end
110
137
 
111
138
  #
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.10.3".freeze
2
+ VERSION = "1.10.4".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.10.3
4
+ version: 1.10.4
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-02-22 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug