nist-pubid 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/nist-pubid +46 -17
- data/lib/nist_pubid/document.rb +50 -19
- data/lib/nist_pubid/nist_tech_pubs.rb +21 -9
- data/lib/nist_pubid/publisher.rb +1 -1
- data/lib/nist_pubid/serie.rb +1 -1
- data/lib/nist_pubid/version.rb +1 -1
- data/nist_pubid.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6cbdcaa4e1cfa7c75b6709f34cfd19670e8a3b2d3bd31473cbc5a5d439843b7
|
4
|
+
data.tar.gz: 4dcb0a4b147990872fe4f72c8eecac96ba3a865bcaa477a5158404ab04fc8e42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6331d9887c149a7dbcf49c46a0ce7c121bf973cd239e3467658065820daf8c18f752e68b977d52e08155dfa2d947d9be5fa80bb431f462453ed337e02fc1616
|
7
|
+
data.tar.gz: 35660adeef1ec90862ada64b2150162008d0b25cf01a8e9a7b15f909b6ac64265a04cc2bdf1da7ea9a7d08e99754eb8d49910de9d19119b4548b40f3870876db
|
data/exe/nist-pubid
CHANGED
@@ -1,25 +1,54 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require_relative
|
6
|
-
require
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
5
|
+
require_relative "../lib/nist_pubid"
|
6
|
+
require "thor"
|
7
|
+
require "csv"
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
class NistPubidCLI < Thor
|
10
|
+
desc "report", "Create report for NIST Tech Pubs database (fetches from GitHub)"
|
11
|
+
option :csv, type: :boolean, desc: "Export to CSV format"
|
12
|
+
def report
|
13
|
+
if options[:csv]
|
14
|
+
NistPubid::NistTechPubs.status.each do |doc|
|
15
|
+
puts [doc[:finalPubId] == doc[:id] && doc[:mr] == doc[:doi] ? "-" : "+",
|
16
|
+
doc[:finalPubId], doc[:id], doc[:doi], doc[:mr], doc[:title]]
|
17
|
+
.to_csv
|
18
|
+
end
|
19
|
+
else
|
20
|
+
puts "Changed | New PubID | Document ID | DOI | New MR | Title + subtitle"
|
21
|
+
NistPubid::NistTechPubs.status.each do |doc|
|
22
|
+
puts "#{doc[:finalPubId] == doc[:id] && doc[:mr] == doc[:doi] ? ' -' : '✅'}"\
|
23
|
+
" | #{doc[:finalPubId]} | #{doc[:id]} | #{doc[:doi]} | #{doc[:mr]} | #{doc[:title]}"
|
24
|
+
end
|
14
25
|
end
|
15
26
|
end
|
16
27
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
28
|
+
desc "convert", "Convert legacy NIST Tech Pubs ID to NIST PubID"
|
29
|
+
option :style, aliases: "-s", type: :string,
|
30
|
+
desc: "Convert to PubID style (short|long|mr|abbrev)",
|
31
|
+
default: "short"
|
32
|
+
option :format, aliases: "-f", type: :string,
|
33
|
+
desc: "Render in format (JSON, string)",
|
34
|
+
default: "string"
|
35
|
+
def convert(code)
|
36
|
+
unless %w[mr long short abbrev].include?(options[:style])
|
37
|
+
raise "Invalid PubID style"
|
38
|
+
end
|
39
|
+
|
40
|
+
raise "wrong conversion format" unless %w[string json].include? options[:format]
|
21
41
|
|
22
|
-
|
42
|
+
unless code.empty?
|
43
|
+
if options[:format] == "string"
|
44
|
+
puts NistPubid::Document.parse(code).to_s(options[:style].to_sym)
|
45
|
+
else
|
46
|
+
puts NistPubid::Document.parse(code).to_json
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue NistPubid::Errors::ParseError
|
50
|
+
puts "[Error] This does not seem to be a valid NIST Tech Pubs legacy identifier"
|
51
|
+
end
|
52
|
+
end
|
23
53
|
|
24
|
-
|
25
|
-
puts NistPubid::Document.parse(code).to_s(:short) unless code.empty?
|
54
|
+
NistPubidCLI.start(ARGV)
|
data/lib/nist_pubid/document.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
REVISION_DESC = {
|
4
5
|
long: ", Revision ",
|
@@ -59,8 +60,22 @@ APPENDIX_DESC = {
|
|
59
60
|
ERRATA_DESC = {
|
60
61
|
long: " Errata ",
|
61
62
|
abbrev: " Err. ",
|
62
|
-
short: "
|
63
|
-
mr: "
|
63
|
+
short: "err",
|
64
|
+
mr: "err",
|
65
|
+
}.freeze
|
66
|
+
|
67
|
+
INDEX_DESC = {
|
68
|
+
long: " Index ",
|
69
|
+
abbrev: " Index. ",
|
70
|
+
short: "indx",
|
71
|
+
mr: "indx",
|
72
|
+
}.freeze
|
73
|
+
|
74
|
+
INSERT_DESC = {
|
75
|
+
long: " Insert ",
|
76
|
+
abbrev: " Ins. ",
|
77
|
+
short: "ins",
|
78
|
+
mr: "ins",
|
64
79
|
}.freeze
|
65
80
|
|
66
81
|
module NistPubid
|
@@ -68,7 +83,7 @@ module NistPubid
|
|
68
83
|
attr_accessor :serie, :code, :revision, :publisher, :version, :volume,
|
69
84
|
:part, :addendum, :stage, :translation, :update_number,
|
70
85
|
:edition, :supplement, :update_year, :section, :appendix,
|
71
|
-
:errata
|
86
|
+
:errata, :index, :insert
|
72
87
|
|
73
88
|
def initialize(publisher:, serie:, docnumber:, **opts)
|
74
89
|
@publisher = Publisher.new(publisher: publisher)
|
@@ -101,6 +116,8 @@ module NistPubid
|
|
101
116
|
.gsub("NIST SP 260-162 2006ed.", "NIST SP 260-162e2006")
|
102
117
|
.gsub("NBS CIRC 154suprev", "NBS CIRC 154r1sup")
|
103
118
|
.gsub("NIST SP 260-126 rev 2013", "NIST SP 260-126r2013")
|
119
|
+
.gsub("NIST CSWP", "NIST CSRC White Paper")
|
120
|
+
.gsub("NIST.CSWP.01162020pt", "NIST.CSWP.01162020(por)")
|
104
121
|
.gsub(/(?<=NBS MP )(\d+)\((\d+)\)/, '\1e\2')
|
105
122
|
.gsub(/(?<=\d)es/, "(spa)")
|
106
123
|
.gsub(/(?<=\d)chi/, "(zho)")
|
@@ -123,11 +140,14 @@ module NistPubid
|
|
123
140
|
revision: /[\da](?:r|Rev\.\s|([0-9]+[A-Za-z]*-[0-9]+[A-Za-z]*-))([\da]+)/
|
124
141
|
.match(code)&.[](2),
|
125
142
|
addendum: match(/(?<=(\.))?(add(?:-\d+)?|Addendum)/, code),
|
126
|
-
edition: /(?<=[^a-z])(
|
127
|
-
|
143
|
+
edition: /(?<=[^a-z])(?<=\.)?(?:e(?(1)-)|Ed\.\s)(\d+)|
|
144
|
+
NBS\sFIPS\sPUB\s[0-9]+[A-Za-z]*-[0-9]+[A-Za-z]*-([A-Za-z\d]+)
|
145
|
+
/x.match(code)&.captures&.join,
|
128
146
|
section: /(?<=sec)\d+/.match(code)&.to_s,
|
129
147
|
appendix: /\d+app/.match(code)&.to_s,
|
130
|
-
errata: /-errata
|
148
|
+
errata: /-errata|\d+err(?:ata)?/.match(code)&.to_s,
|
149
|
+
index: /\d+index|\d+indx/.match(code)&.to_s,
|
150
|
+
insert: /\d+ins(?:ert)?/.match(code)&.to_s
|
131
151
|
}
|
132
152
|
supplement = /(?:(?:supp?)-?(\d*)|Supplement|Suppl.)/
|
133
153
|
.match(code)
|
@@ -163,7 +183,7 @@ module NistPubid
|
|
163
183
|
end
|
164
184
|
|
165
185
|
def self.parse_docnumber(serie, code)
|
166
|
-
localities = "[Pp]t\\d+|r(?:\\d+|[A-Za-z]?)|e\\d+|p|v|sec\\d
|
186
|
+
localities = "[Pp]t\\d+|r(?:\\d+|[A-Za-z]?)|e\\d+|p|v|sec\\d+|inde?x|err(?:ata)?|ins(?:ert)?"
|
167
187
|
excluded_parts = "(?!#{localities}|supp?)"
|
168
188
|
|
169
189
|
if ["NBS CSM", "NBS CS"].include?(serie)
|
@@ -179,7 +199,7 @@ module NistPubid
|
|
179
199
|
([0-9]+ # first part of report number
|
180
200
|
(?:#{excluded_parts}[A-Za-z]+)? # with letter but without localities
|
181
201
|
(?:-m)? # for NBS CRPL 4-m-5
|
182
|
-
(?:-[A-
|
202
|
+
(?:-[A-Za]+)? # for NIST SP 1075-NCNR, NIST SP 1113-BFRL, NIST IR 6529-a
|
183
203
|
(?:-[0-9.]+)? # second part
|
184
204
|
(?:
|
185
205
|
(?: # only big letter
|
@@ -203,7 +223,7 @@ module NistPubid
|
|
203
223
|
regex.match(code)&.to_s
|
204
224
|
end
|
205
225
|
|
206
|
-
def to_s(format)
|
226
|
+
def to_s(format = :short)
|
207
227
|
result = render_serie(format)
|
208
228
|
result += " " unless format == :short || stage.nil?
|
209
229
|
result += "#{stage&.to_s(format)}"\
|
@@ -217,6 +237,23 @@ module NistPubid
|
|
217
237
|
result
|
218
238
|
end
|
219
239
|
|
240
|
+
def to_json(*args)
|
241
|
+
result = {
|
242
|
+
styles: {
|
243
|
+
short: to_s(:short),
|
244
|
+
abbrev: to_s(:abbrev),
|
245
|
+
long: to_s(:long),
|
246
|
+
mr: to_s(:mr),
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
instance_variables.each do |var|
|
251
|
+
val = instance_variable_get(var)
|
252
|
+
result[var.to_s.gsub('@', '')] = val unless val.nil?
|
253
|
+
end
|
254
|
+
result.to_json(*args)
|
255
|
+
end
|
256
|
+
|
220
257
|
def render_serie(format)
|
221
258
|
if serie.to_s(format).include?(publisher.to_s(format))
|
222
259
|
return serie.to_s(format)
|
@@ -234,27 +271,21 @@ module NistPubid
|
|
234
271
|
|
235
272
|
def render_edition(format)
|
236
273
|
result = ""
|
237
|
-
|
238
|
-
|
239
|
-
[volume, part, supplement, version, edition].any?
|
240
|
-
"#{REVISION_DESC[format]}#{revision}"
|
241
|
-
else
|
242
|
-
"-#{revision}"
|
243
|
-
end
|
244
|
-
end
|
274
|
+
|
275
|
+
result += "#{REVISION_DESC[format]}#{revision.to_s.upcase}" if revision
|
245
276
|
result += "#{VERSION_DESC[format]}#{version}" unless version.nil?
|
246
277
|
result += "#{EDITION_DESC[format]}#{edition}" unless edition.nil?
|
247
278
|
result
|
248
279
|
end
|
249
280
|
|
250
281
|
def render_localities(format)
|
251
|
-
# TODO: Index, Insert
|
252
|
-
|
253
282
|
result = ""
|
254
283
|
result += "#{SUPPLEMENT_DESC[format]}#{supplement}" unless supplement.nil?
|
255
284
|
result += "#{SECTION_DESC[format]}#{section}" unless section.nil?
|
256
285
|
result += "#{APPENDIX_DESC[format]}" unless appendix.nil?
|
257
286
|
result += "#{ERRATA_DESC[format]}" unless errata.nil?
|
287
|
+
result += INDEX_DESC[format] unless index.nil?
|
288
|
+
result += INSERT_DESC[format] unless insert.nil?
|
258
289
|
|
259
290
|
result
|
260
291
|
end
|
@@ -23,19 +23,18 @@ module NistPubid
|
|
23
23
|
|
24
24
|
def convert(doc)
|
25
25
|
id = @converted_id[doc[:id]] ||= NistPubid::Document.parse(doc[:id])
|
26
|
-
return id
|
26
|
+
return id unless doc.key?(:doi)
|
27
27
|
|
28
28
|
begin
|
29
29
|
doi = @converted_doi[doc[:doi]] ||=
|
30
30
|
NistPubid::Document.parse(doc[:doi])
|
31
31
|
rescue Errors::ParseError
|
32
|
-
return id
|
32
|
+
return id
|
33
33
|
end
|
34
34
|
# return more complete pubid
|
35
|
-
id.merge(doi)
|
35
|
+
id.merge(doi)
|
36
36
|
rescue Errors::ParseError
|
37
37
|
@converted_doi[doc[:doi]] ||= NistPubid::Document.parse(doc[:doi])
|
38
|
-
.to_s(:short)
|
39
38
|
end
|
40
39
|
|
41
40
|
def parse_docid(doc)
|
@@ -57,7 +56,7 @@ module NistPubid
|
|
57
56
|
|
58
57
|
def comply_with_pubid
|
59
58
|
fetch.select do |doc|
|
60
|
-
convert(doc) == doc[:id]
|
59
|
+
convert(doc).to_s == doc[:id]
|
61
60
|
rescue Errors::ParseError
|
62
61
|
false
|
63
62
|
end
|
@@ -65,7 +64,7 @@ module NistPubid
|
|
65
64
|
|
66
65
|
def different_with_pubid
|
67
66
|
fetch.reject do |doc|
|
68
|
-
convert(doc) == doc[:id]
|
67
|
+
convert(doc).to_s == doc[:id]
|
69
68
|
rescue Errors::ParseError
|
70
69
|
true
|
71
70
|
end
|
@@ -73,7 +72,7 @@ module NistPubid
|
|
73
72
|
|
74
73
|
def parse_fail_with_pubid
|
75
74
|
fetch.select do |doc|
|
76
|
-
convert(doc) && false
|
75
|
+
convert(doc).to_s && false
|
77
76
|
rescue Errors::ParseError
|
78
77
|
true
|
79
78
|
end
|
@@ -82,9 +81,22 @@ module NistPubid
|
|
82
81
|
# returning current document id, doi, title and final PubID
|
83
82
|
def status
|
84
83
|
fetch.map do |doc|
|
85
|
-
|
84
|
+
final_doc = convert(doc)
|
85
|
+
{
|
86
|
+
id: doc[:id],
|
87
|
+
doi: doc[:doi],
|
88
|
+
title: doc[:title],
|
89
|
+
finalPubId: final_doc.to_s,
|
90
|
+
mr: final_doc.to_s(:mr),
|
91
|
+
}
|
86
92
|
rescue Errors::ParseError
|
87
|
-
|
93
|
+
{
|
94
|
+
id: doc[:id],
|
95
|
+
doi: doc[:doi],
|
96
|
+
title: doc[:title],
|
97
|
+
finalPubId: "parse error",
|
98
|
+
mr: "parse_error"
|
99
|
+
}
|
88
100
|
end
|
89
101
|
end
|
90
102
|
end
|
data/lib/nist_pubid/publisher.rb
CHANGED
data/lib/nist_pubid/serie.rb
CHANGED
data/lib/nist_pubid/version.rb
CHANGED
data/nist_pubid.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nist-pubid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
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-
|
11
|
+
date: 2022-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: thor
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Library to generate, parse and manipulate NIST PubID.
|
98
112
|
email:
|
99
113
|
- open.source@ribose.com
|