relaton-nist 1.7.1 → 1.7.2

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: 86fbfc1190f5174be69a4e51bb6b791328c1d432143e8eb6d2aab6f644ae5100
4
- data.tar.gz: 2aa468017a4bcf5ab9369e2f4fca85543fd641ac5ba2b35399e60e96769c996d
3
+ metadata.gz: c81efdc2d8f38426e3eba552cc116e51fac614c10901098bdc1e8eb71b09c1f1
4
+ data.tar.gz: d629498cf1943a4d0d735e55fa6d4d61727cfcfc7bd24ca1e0e4b1e102c04364
5
5
  SHA512:
6
- metadata.gz: 9bb703e914559d9e8359ef6442f089d76fb3dc84fedb273e046893989b7e035825d7990235e1b9c95f14f1c916e0ffff24d9cc1e6b177ae027bcc403480ac2be
7
- data.tar.gz: b1b0857eff72431fb9ae953af25dfedd49a1fa459b05fdd85c2285e642182ceb3a58d407bdcd8986153fad5f9f162e6115bd0c9d804d2956ed65de700d830158
6
+ metadata.gz: 1089faa79d7cc68a375fa77f6abd1ddbc9d10a636ef00cdd56fd99112d2b3356fa95703630685a4d668badca853fb5696b7503b4b680e8117a9b1a064a785003
7
+ data.tar.gz: 105c563803b84854488ed7e02c9bfe74a3853a78f55c90f5f67ba5c36fa3f3d83df9f889a925fef89da1114fc1efff0cb0d6fbddc2e49193d8d72ae7595c4ffa
@@ -91,11 +91,14 @@ RelatonNist::NistBibliography.get("8200", "2018", {})
91
91
  === Get short citation
92
92
  Short citation is a convetion about a citation's format. The format for NIST publications is:
93
93
  ----
94
- NIST {abbrev(series)} {docnumber} {(edition), optional} {(stage), optioal}
94
+ NIST {abbrev(series)} {docnumber} {(edition), optional} {(stage), optional}
95
95
  # or
96
- {abbrev(series)} {docnumber} {(edition), optional} {(stage), optioal}
96
+ {abbrev(series)} {docnumber} {(edition), optional} {(stage), optional}
97
97
  ----
98
- - `(stage)` is empty if the state is "final" (published)
98
+ - `(stage)` is empty if the state is "final" (published). In case state is "draft" it shoud be:
99
+ * PD for public draft
100
+ * IPD for initial iteration public draft or 2PD, 3PD and so one for following iterations
101
+ * FPD for final public draft
99
102
  - `(edition)` is the date of publication or update
100
103
  - `docnumber` is the full NIST number, including revision, e.g., 800-52
101
104
 
@@ -114,6 +117,36 @@ RelatonNist::NistBibliography.get("SP 800-205 (February 2019) (PD)")
114
117
  ...
115
118
  ----
116
119
 
120
+ === Get specific part, volume, version, revision, and addendum
121
+
122
+ Referehces can contain optional parameters `{ptN}{vN}{verN}{rN}{/Add}`:
123
+ - Part is specified as `ptN` (SP 800-57pt1)
124
+ - Volume is specified as `vN` (SP 800-60v1)
125
+ - Version is specified as `verN` (SP 800-45ver2)
126
+ - Revision is specified as `rN` (SP 800-40r3)
127
+ - Addendum is specified as `/Add` (SP 800-38A/Add)
128
+
129
+ [source,ruby]
130
+ ----
131
+ item = RelatonNist::NistBibliography.get 'SP 800-67r3'
132
+ [relaton-nist] ("SP 800-67r3") fetching...
133
+ [relaton-nist] ("SP 800-67r3") found SP 800-67 Rev. 3
134
+ => #<RelatonNist::NistBibliographicItem:0x007fd87bbe9460
135
+ ...
136
+
137
+ item.docidentifier.first.id
138
+ => "SP 800-67 Rev. 3"
139
+
140
+ RelatonNist::NistBibliography.get 'SP 800-38A/Add'
141
+ [relaton-nist] ("SP 800-38A/Add") fetching...
142
+ [relaton-nist] ("SP 800-38A/Add") found SP 800-38A-Add
143
+ => #<RelatonNist::NistBibliographicItem:0x007fd88c21d880
144
+ ...
145
+
146
+ item.docidentifier.first.id
147
+ => "SP 800-38A-Add"
148
+ ----
149
+
117
150
  === Create bibliographic item from YAML
118
151
  [source,ruby]
119
152
  ----
@@ -21,8 +21,9 @@ module RelatonNist
21
21
  def initialize(ref_nbr, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize
22
22
  super ref_nbr, year
23
23
 
24
- /(?<docid>(SP|FIPS)\s[0-9-]+\w?)/ =~ text
24
+ /(?<docid>(SP|FIPS)\s[0-9-]+)/ =~ text
25
25
  @array = docid ? from_json(docid, **opts) : from_csrc(**opts)
26
+ @array = from_csrc(**opts) unless @array.any?
26
27
 
27
28
  @array.sort! do |a, b|
28
29
  if a.sort_value != b.sort_value
@@ -94,8 +95,9 @@ module RelatonNist
94
95
  # @param stage [String]
95
96
  # @return [Array<Hach>]
96
97
  def select_data(docid, **opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
98
+ # ref = docid.sub(/(?<=\d{3}-\d{2})r(\d+)/, ' Rev. \1')
97
99
  d = Date.strptime year, "%Y" if year
98
- didrx = Regexp.new(docid)
100
+ # didrx = Regexp.new(docid)
99
101
  data.select do |doc|
100
102
  next unless match_year?(doc, d)
101
103
 
@@ -104,7 +106,7 @@ module RelatonNist
104
106
  else
105
107
  next unless doc["status"] == "final"
106
108
  end
107
- doc["docidentifier"] =~ didrx
109
+ doc["docidentifier"].include? docid
108
110
  end
109
111
  end
110
112
 
@@ -32,6 +32,7 @@ module RelatonNist
32
32
  return fetch_ref_err(code, year, []) if code.match? /\sEP$/
33
33
 
34
34
  /^(?<code2>[^\(]+)(\((?<date2>\w+\s(\d{2},\s)?\d{4})\))?\s?\(?((?<=\()(?<stage>[^\)]+))?/ =~ code
35
+ stage ||= /(?<=\.)PD-\w+(?=\.)/.match(code)&.to_s
35
36
  if code2
36
37
  code = code2.strip
37
38
  if date2
@@ -81,10 +82,10 @@ module RelatonNist
81
82
  # @option opts [Time] :issued_date
82
83
  # @option opts [String] :stage
83
84
  #
84
- # @retur [Hash]
85
+ # @return [Hash]
85
86
  def nistbib_results_filter(result, year, opts)
86
87
  missed_years = []
87
- iter = opts[:stage]&.slice(-3, 1)
88
+ iter = /\w+(?=PD)|(?<=PD-)\w+/.match(opts[:stage])&.to_s
88
89
  iteration = case iter
89
90
  when "I" then "1"
90
91
  when "F" then "final"
@@ -116,6 +117,9 @@ module RelatonNist
116
117
  { years: missed_years }
117
118
  end
118
119
 
120
+ # @param hits [RelatonNist::HitCollection]
121
+ # @param threads [Integer]
122
+ # @return [Array<RelatonNist::NistBibliographicItem>]
119
123
  def fetch_pages(hits, threads)
120
124
  workers = RelatonBib::WorkersPool.new threads
121
125
  workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
@@ -124,24 +128,94 @@ module RelatonNist
124
128
  workers.result.sort_by { |a| a[:i] }.map { |x| x[:hit] }
125
129
  end
126
130
 
127
- def nistbib_search_filter(code, year, opts)
131
+ # @param code [String]
132
+ # @param year [String, nil]
133
+ # @param opts [Hash]
134
+ # @return [RelatonNist::HitCollection]
135
+ def nistbib_search_filter(code, year, opts) # rubocop:disable Metrics/MethodLength
136
+ warn "[relaton-nist] (\"#{code}\") fetching..."
137
+ # match = %r{
138
+ # ^((?:NIST)\s)?
139
+ # (?<serie>(SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s
140
+ # (?<code>[0-9-]{3,}[A-Z]?)
141
+ # (?<prt1>pt\d+)?
142
+ # (?<vol1>v\d+)?
143
+ # (?<ver1>ver[\d\.]+)?
144
+ # (?<rev1>r\d+)?
145
+ # (\s(?<prt2>Part\s\d+))?
146
+ # (\s(?<vol2>Vol\.\s\d+))?
147
+ # (\s(?<ver2>(Ver\.|Version)\s[\d\.]+))?
148
+ # (\s(?<rev2>Rev\.\s\d+))?
149
+ # (\/(?<upd>Add))?
150
+ # }x.match(code)
151
+ # match ||= %r{
152
+ # ^NIST\.
153
+ # (?<serie>(SP|FIPS|IR|ITL\sBulletin|White\sPaper))\.
154
+ # ((PD-\d+|PUB)\.)?
155
+ # (?<code>[0-9-]{3,}[A-Z]?)
156
+ # (\.(?<prt1>pt-\d+))?
157
+ # (\.(?<vol1>v-\d+))?
158
+ # (\.(?<ver1>ver-[\d\.]+))?
159
+ # (\.(?<rev1>r-\d+))?
160
+ # }x.match(code)
161
+ matches = {
162
+ serie: match(/(SP|FIPS|(NIST)?IR|ITL\sBulletin|White\sPaper)(?=\.|\s)/, code),
163
+ code: match(/(?<=\.|\s)[0-9-]{3,}[A-Z]?/, code),
164
+ prt1: match(/(?<=(\.))?pt(?(1)-)[A-Z\d]+/, code),
165
+ vol1: match(/(?<=(\.))?v(?(1)-)\d+/, code),
166
+ ver1: match(/(?<=(\.))?ver(?(1)[-\d]|[\.\d])+/, code)&.gsub(/-/, "."),
167
+ rev1: match(/(?<=[^a-z])(?<=(\.))?r(?(1)-)\d+/, code),
168
+ add1: match(/(?<=(\.))?add(?(1)-)\d+/, code),
169
+ prt2: match(/(?<=\s)Part\s[A-Z\d]+/, code),
170
+ vol2: match(/(?<=\s)Vol\.\s\d+/, code),
171
+ ver2: match(/(?<=\s)Ver\.\s\d+/, code),
172
+ rev2: match(/(?<=\s)Rev\.\s\d+/, code),
173
+ add2: match(/(?<=\/)Add/, code),
174
+ }
175
+ ref = matches[:code] ? "#{matches[:serie]} #{matches[:code]}" : code
176
+ result = search(ref, year, opts)
177
+ result.select { |i| search_filter i, matches, code }
178
+ end
179
+
180
+ def match(regex, code)
181
+ regex.match(code)&.to_s
182
+ end
183
+
184
+ # @param item [RelatonNist::Hit]
185
+ # @param matches [Hash]
186
+ # @param text [String]
187
+ # @return [Boolean]
188
+ def search_filter(item, matches, text) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
128
189
  %r{
129
190
  ^((?:NIST)\s)?
130
- (?<serie1>(SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s
131
- (?<code1>[0-9-]{3,}\w?)
132
- (\/(?<upd1>Add))?
133
- }x =~ code
134
- warn "[relaton-nist] (\"#{code}\") fetching..."
135
- result = search(code, year, opts)
136
- result.select do |i|
137
- %r{
138
- ^((?:NIST)\s)?
139
- ((?<serie2>(SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s)?
140
- (?<code2>[0-9-]{3,}\w?)
141
- (\s(?<upd2>Add)endum)?
142
- }x =~ i.hit[:code]
143
- [serie2, i.hit[:serie]].include?(serie1) && code1 == code2 && upd1 == upd2
144
- end
191
+ ((?<serie>(SP|FIPS|NISTIR|ITL\sBulletin|White\sPaper))\s)?
192
+ (?<code>[0-9-]{3,}[A-Z]?)
193
+ (?<prt1>pt\d+)?
194
+ (?<vol1>v\d+)?
195
+ (?<ver1>ver[\d\.]+)?
196
+ (?<rev1>r\d+)?
197
+ (\s(?<prt2>Part\s\d+))?
198
+ (\s(?<vol2>Vol\.\s\d+))?
199
+ (\s(?<ver2>(Ver\.|Version)\s[\d\.]+))?
200
+ (\s(?<rev2>Rev\.\s\d+))?
201
+ (\s(?<add>Add)endum)?
202
+ }x =~ item.hit[:code]
203
+ matches[:code] && [serie, item.hit[:serie]].include?(matches[:serie]) && matches[:code] == code &&
204
+ long_to_short(matches[:prt1], matches[:prt2]) == long_to_short(prt1, prt2) &&
205
+ long_to_short(matches[:vol1], matches[:vol2]) == long_to_short(vol1, vol2) &&
206
+ long_to_short(matches[:ver1], matches[:ver2]) == long_to_short(ver1, ver2) &&
207
+ long_to_short(matches[:rev1], matches[:rev2]) == long_to_short(rev1, rev2) &&
208
+ long_to_short(matches[:add1], matches[:add2]) == add || item.hit[:title].include?(text.sub(/^NIST\s/, ""))
209
+ end
210
+
211
+ # @param short [String]
212
+ # @param long [String]
213
+ # @return [String, nil]
214
+ def long_to_short(short, long)
215
+ return short.sub(/-/, "") if short
216
+ return unless long
217
+
218
+ long.sub(/Part\s/, "pt").sub(/Vol\.\s/, "v").sub(/Rev\.\s/, "r").sub(/(Ver\.|Version)\s/, "ver")
145
219
  end
146
220
 
147
221
  def fetch_ref_err(code, year, missed_years)
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.7.1".freeze
2
+ VERSION = "1.7.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-08 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase