relaton-nist 1.9.0 → 1.9.1

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: 51d5205328c024259b5fea0e2632c72eb51045ff119a789e6760a678af3e6961
4
- data.tar.gz: dc3da903e2308fa2ebc3cf894a4972e69a4bdd0ce8dfe39ca770295856bab0ad
3
+ metadata.gz: d440504b749834c27875dc8a1ee84346451578db5dd1588b75eafdb31087b64c
4
+ data.tar.gz: ecfb305d172a8afa171fa4493b1ffec2dd458fd413143a7f197034a392ddf451
5
5
  SHA512:
6
- metadata.gz: 7794caf0f138e6028da3b44345bf6206c4770c21d019205aa84bff604bafe88f1eb888c1126ec99bf6f501494c25eed956080f1c5cc72f7cb46427f2c4933ca8
7
- data.tar.gz: d03f8aec87890fc4bac521318306b87d9c92a174389c9a0109b54cfd360cca387d0c806333a7ffa50a8ae2905c41f2dd8ac14c9903666720ad15615f42e9e757
6
+ metadata.gz: 7af96feb236bddbabd7e90982637b608813d5c2163c7453f217c658035cf34b0ef80adc6441d6be213b77e62b5625d95fb10a30914fc94a1b6cf966b1c921bf6
7
+ data.tar.gz: 9b9daa02fc2ec7df33ad5c8cdf768c711b1bac0122191e7cfc79ee7c8ed2b7de00fbe6509b3347f387cf4868b24448f91f1a687e45b80fe65ce31d3f7a46cad5
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -3,6 +3,8 @@
3
3
  module RelatonNist
4
4
  # Hit.
5
5
  class Hit < RelatonBib::Hit
6
+ attr_writer :fetch
7
+
6
8
  # Parse page.
7
9
  # @return [RelatonNist::NistBliographicItem]
8
10
  def fetch
@@ -10,7 +12,7 @@ module RelatonNist
10
12
  end
11
13
 
12
14
  # @return [Iteger]
13
- def sort_value
15
+ def sort_value # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
14
16
  @sort_value ||= begin
15
17
  sort_phrase = [hit[:serie], hit[:code], hit[:title]].join " "
16
18
  corr = hit_collection&.text&.split&.map do |w|
@@ -13,6 +13,7 @@ module RelatonNist
13
13
  PUBS_EXPORT = URI.join(DOMAIN, "/CSRC/media/feeds/metanorma/pubs-export")
14
14
  DATAFILEDIR = File.expand_path ".relaton/nist", Dir.home
15
15
  DATAFILE = File.expand_path "pubs-export.zip", DATAFILEDIR
16
+ GHNISTDATA = "https://raw.githubusercontent.com/relaton/relaton-data-nist/main/data/"
16
17
 
17
18
  # @param ref_nbr [String]
18
19
  # @param year [String]
@@ -21,9 +22,9 @@ module RelatonNist
21
22
  def initialize(ref_nbr, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
22
23
  super ref_nbr, year
23
24
 
24
- /(?<docid>(?:SP|FIPS)\s[0-9-]+)/ =~ text
25
- @array = docid ? from_json(docid, **opts) : from_csrc(**opts)
26
- @array = from_csrc(**opts) unless @array.any?
25
+ # /(?<docid>(?:SP|FIPS)\s[0-9-]+)/ =~ text
26
+ @array = from_json(**opts)
27
+ @array = from_ga unless @array.any?
27
28
 
28
29
  @array.sort! do |a, b|
29
30
  if a.sort_value == b.sort_value
@@ -36,52 +37,65 @@ module RelatonNist
36
37
 
37
38
  private
38
39
 
40
+ def from_ga # rubocop:disable Metrics/AbcSize
41
+ fn = text.gsub(%r{[/\s:.]}, "_").upcase
42
+ yaml = OpenURI.open_uri "#{GHNISTDATA}#{fn}.yaml"
43
+ hash = YAML.safe_load yaml
44
+ bib = RelatonNist::NistBibliographicItem.from_hash hash
45
+ hit = Hit.new({ code: text }, self)
46
+ hit.fetch = bib
47
+ [hit]
48
+ rescue OpenURI::HTTPError => e
49
+ return [] if e.io.status[0] == "404"
50
+
51
+ raise e
52
+ end
53
+
39
54
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
40
55
 
41
56
  # @param stage [String]
42
57
  # @return [Array<RelatonNist::Hit>]
43
- def from_csrc(**opts)
44
- from, to = nil
45
- if year
46
- d = Date.strptime year, "%Y"
47
- from = d.strftime "%m/%d/%Y"
48
- to = d.next_year.prev_day.strftime "%m/%d/%Y"
49
- end
50
- url = "#{DOMAIN}/publications/search?keywords-lg=#{text}"\
51
- "&sortBy-lg=relevence"
52
- url += "&dateFrom-lg=#{from}" if from
53
- url += "&dateTo-lg=#{to}" if to
54
- url += if /PD/.match? opts[:stage]
55
- "&status-lg=Draft,Retired Draft,Withdrawn"
56
- else
57
- "&status-lg=Final,Withdrawn"
58
- end
59
-
60
- doc = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize)
61
- doc.css("table.publications-table > tbody > tr").map do |h|
62
- link = h.at("td/div/strong/a")
63
- serie = h.at("td[1]").text.strip
64
- code = h.at("td[2]").text.strip
65
- title = link.text
66
- doc_url = DOMAIN + link[:href]
67
- status = h.at("td[4]").text.strip.downcase
68
- release_date = Date.strptime h.at("td[5]").text.strip, "%m/%d/%Y"
69
- Hit.new(
70
- {
71
- code: code, serie: serie, title: title, url: doc_url,
72
- status: status, release_date: release_date
73
- }, self
74
- )
75
- end
76
- end
58
+ # def from_csrc(**opts)
59
+ # from, to = nil
60
+ # if year
61
+ # d = Date.strptime year, "%Y"
62
+ # from = d.strftime "%m/%d/%Y"
63
+ # to = d.next_year.prev_day.strftime "%m/%d/%Y"
64
+ # end
65
+ # url = "#{DOMAIN}/publications/search?keywords-lg=#{text}"\
66
+ # "&sortBy-lg=relevence"
67
+ # url += "&dateFrom-lg=#{from}" if from
68
+ # url += "&dateTo-lg=#{to}" if to
69
+ # url += if /PD/.match? opts[:stage]
70
+ # "&status-lg=Draft,Retired Draft,Withdrawn"
71
+ # else
72
+ # "&status-lg=Final,Withdrawn"
73
+ # end
74
+
75
+ # doc = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize)
76
+ # doc.css("table.publications-table > tbody > tr").map do |h|
77
+ # link = h.at("td/div/strong/a")
78
+ # serie = h.at("td[1]").text.strip
79
+ # code = h.at("td[2]").text.strip
80
+ # title = link.text
81
+ # doc_url = DOMAIN + link[:href]
82
+ # status = h.at("td[4]").text.strip.downcase
83
+ # release_date = Date.strptime h.at("td[5]").text.strip, "%m/%d/%Y"
84
+ # Hit.new(
85
+ # {
86
+ # code: code, serie: serie, title: title, url: doc_url,
87
+ # status: status, release_date: release_date
88
+ # }, self
89
+ # )
90
+ # end
91
+ # end
77
92
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
78
93
 
79
94
  # Fetches data form json
80
- # @param docid [String]
81
95
  # @param stage [String]
82
96
  # @return [Array<RelatonNist::Hit>]
83
- def from_json(docid, **opts)
84
- select_data(docid, **opts).map do |h|
97
+ def from_json(**opts)
98
+ select_data(**opts).map do |h|
85
99
  /(?<serie>(?<=-)\w+$)/ =~ h["series"]
86
100
  title = [h["title-main"], h["title-sub"]].compact.join " - "
87
101
  release_date = RelatonBib.parse_date h["published-date"], false
@@ -91,10 +105,9 @@ module RelatonNist
91
105
  end
92
106
  end
93
107
 
94
- # @param docid [String]
95
108
  # @param stage [String]
96
109
  # @return [Array<Hach>]
97
- def select_data(docid, **opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
110
+ def select_data(**opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
98
111
  d = Date.strptime year, "%Y" if year
99
112
  statuses = %w[draft-public draft-prelim]
100
113
  data.select do |doc|
@@ -105,7 +118,7 @@ module RelatonNist
105
118
  else
106
119
  next unless doc["status"] == "final"
107
120
  end
108
- doc["docidentifier"].include? docid
121
+ doc["docidentifier"].include? text
109
122
  end
110
123
  end
111
124
 
@@ -67,7 +67,7 @@ module RelatonNist
67
67
  # @return [RelatonNist::GbBibliographicItem]
68
68
  def self.from_hash(hash)
69
69
  item_hash = RelatonNist::HashConverter.hash_to_bib(hash)
70
- new **item_hash
70
+ new(**item_hash)
71
71
  end
72
72
 
73
73
  # @param opts [Hash]
@@ -15,8 +15,8 @@ module RelatonNist
15
15
  # @return [RelatonNist::HitCollection]
16
16
  def search(text, year = nil, opts = {})
17
17
  HitCollection.new text, year, opts
18
- rescue OpenURI::HTTPError, SocketError, OpenSSL::SSL::SSLError
19
- raise RelatonBib::RequestError, "Could not access https://www.nist.gov"
18
+ rescue OpenURI::HTTPError, SocketError, OpenSSL::SSL::SSLError => e
19
+ raise RelatonBib::RequestError, e.message
20
20
  end
21
21
 
22
22
  # @param code [String] the NIST standard Code to look up (e..g "8200")
@@ -174,7 +174,17 @@ module RelatonNist
174
174
  }
175
175
  ref = matches[:code] ? "#{matches[:serie]} #{matches[:code]}" : code
176
176
  result = search(ref, year, opts)
177
- result.select { |i| search_filter i, matches, code }
177
+ selected_result = result.select { |i| search_filter i, matches, code }
178
+ return selected_result if selected_result.any? || !matches[:code]
179
+
180
+ search full_ref(matches)
181
+ end
182
+
183
+ def full_ref(matches)
184
+ ref = "#{matches[:serie]} #{matches[:code]}"
185
+ ref += long_to_short(matches[:prt1], matches[:prt2]).to_s
186
+ ref += long_to_short(matches[:vol1], matches[:vol2]).to_s
187
+ ref
178
188
  end
179
189
 
180
190
  def match(regex, code)
@@ -192,11 +202,11 @@ module RelatonNist
192
202
  (?<code>[0-9-]{3,}[A-Z]?)
193
203
  (?<prt1>pt\d+)?
194
204
  (?<vol1>v\d+)?
195
- (?<ver1>ver[\d\.]+)?
205
+ (?<ver1>ver[\d.]+)?
196
206
  (?<rev1>r\d+)?
197
207
  (\s(?<prt2>Part\s\d+))?
198
208
  (\s(?<vol2>Vol\.\s\d+))?
199
- (\s(?<ver2>(Ver\.|Version)\s[\d\.]+))?
209
+ (\s(?<ver2>(Ver\.|Version)\s[\d.]+))?
200
210
  (\s(?<rev2>Rev\.\s\d+))?
201
211
  (\s(?<add>Add)endum)?
202
212
  }x =~ item.hit[:code]
@@ -11,23 +11,17 @@ module RelatonNist
11
11
  # @param hit_data [Hash]
12
12
  # @return [Hash]
13
13
  def parse_page(hit_data)
14
- item_data = if hit_data[:json]
15
- from_json hit_data
16
- else
17
- from_csrs hit_data
18
- end
19
- # doctype = "standard"
14
+ item_data = from_json hit_data
20
15
  titles = fetch_titles(hit_data)
21
16
  unless /^(SP|NISTIR|FIPS) /.match? item_data[:docid][0].id
22
- # doctype = id_cleanup(item_data[:docid][0].id)
23
17
  item_data[:docid][0] = RelatonBib::DocumentIdentifier.new(
24
- id: titles[0][:content].upcase, type: "NIST"
18
+ id: titles[0][:content].upcase, type: "NIST",
25
19
  )
26
20
  end
27
21
  item_data[:fetched] = Date.today.to_s
28
22
  item_data[:type] = "standard"
29
23
  item_data[:title] = titles
30
- item_data[:doctype] = "standard" # doctype
24
+ item_data[:doctype] = "standard"
31
25
 
32
26
  NistBibliographicItem.new(**item_data)
33
27
  end
@@ -44,7 +38,7 @@ module RelatonNist
44
38
  edition: fetch_edition(json),
45
39
  language: [json["language"]],
46
40
  script: [json["script"]],
47
- docstatus: fetch_status(json, hit_data[:status]),
41
+ docstatus: fetch_status(json), # hit_data[:status]),
48
42
  copyright: fetch_copyright(json["published-date"]),
49
43
  relation: fetch_relations_json(json),
50
44
  place: ["Gaithersburg, MD"],
@@ -53,119 +47,58 @@ module RelatonNist
53
47
  }
54
48
  end
55
49
 
56
- def from_csrs(hit_data)
57
- doc = get_page hit_data[:url]
58
- {
59
- # id: fetch_id(doc),
60
- link: fetch_link(doc),
61
- docid: fetch_docid(doc),
62
- date: fetch_dates(doc, hit_data[:release_date]),
63
- contributor: fetch_contributors(doc),
64
- edition: fetch_edition(hit_data[:code]),
65
- language: ["en"],
66
- script: ["Latn"],
67
- abstract: fetch_abstract(doc),
68
- docstatus: fetch_status(doc, hit_data[:status]),
69
- copyright: fetch_copyright(doc),
70
- relation: fetch_relations(doc),
71
- series: fetch_series(doc),
72
- keyword: fetch_keywords(doc),
73
- commentperiod: fetch_commentperiod(doc),
74
- }
75
- end
76
50
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
77
51
 
78
- # Strip status from doc id
79
- # @param id String
80
- # @return String
81
- # def id_cleanup(id)
82
- # id.sub(/ \(WITHDRAWN\)/, "").sub(/ \(([^) ]+ )?DRAFT\)/i, "")
83
- # end
84
-
85
- # Get page.
86
- # @param path [String] page's path
87
- # @return [Array<Nokogiri::HTML::Document, String>]
88
- def get_page(url)
89
- uri = URI url
90
- resp = Net::HTTP.get_response(uri)
91
- %r{(?<=newLocation = 'https://' \+ window.location.hostname \+ ')(?<path>[^']+)} =~ resp.body
92
- if path
93
- uri = URI HitCollection::DOMAIN + path
94
- resp = Net::HTTP.get_response(uri)
95
- end
96
- Nokogiri::HTML(resp.body)
97
- rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
98
- EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
99
- Net::ProtocolError, OpenSSL::SSL::SSLError
100
- raise RelatonBib::RequestError, "Could not access #{url}"
101
- end
102
-
103
52
  # Fetch docid.
104
- # @param doc [Nokogiri::HTML::Document, String]
53
+ # @param docid [String]
105
54
  # @return [Array<RelatonBib::DocumentIdentifier>]
106
- def fetch_docid(doc)
107
- item_ref = if doc.is_a? String then doc
108
- else
109
- doc.at(
110
- "//div[contains(@class, 'publications-detail')]/h3"
111
- )&.text&.strip&.sub(/(?<=\w)\([^\)]+\)$/) do |m|
112
- " " + m.upcase
113
- end&.squeeze(" ")&.gsub(/&#13;|\n|\r/, "")
114
- end
115
- item_ref ||= "?"
116
- item_ref.sub! /\sAddendum$/, "-Add"
55
+ def fetch_docid(docid)
56
+ item_ref = docid
57
+ # item_ref ||= "?"
58
+ item_ref.sub!(/\sAddendum$/, "-Add")
117
59
  [RelatonBib::DocumentIdentifier.new(id: item_ref, type: "NIST")]
118
60
  end
119
61
 
120
- # Fetch id.
121
- # @param doc [Nokogiri::HTML::Document]
122
- # @return [String]
123
- # def fetch_id(doc)
124
- # doc.at("//div[contains(@class, 'publications-detail')]/h3").text.
125
- # strip.gsub(/\s/, "")
126
- # end
127
-
128
62
  # Fetch status.
129
- # @param doc [Nokogiri::HTML::Document, Hash]
130
- # @param status [String]
63
+ # @param doc [Hash]
131
64
  # @return [RelatonNist::DocumentStatus]
132
- def fetch_status(doc, status)
133
- if doc.is_a? Hash
134
- stage = doc["status"]
135
- subst = doc["substage"]
136
- iter = doc["iteration"] == "initial" ? 1 : doc["iteration"]
137
- else
138
- case status
139
- when "draft (obsolete)"
140
- stage = "draft-public"
141
- subst = "withdrawn"
142
- when "retired draft"
143
- stage = "draft-public"
144
- subst = "retired"
145
- when "withdrawn"
146
- stage = "final"
147
- subst = "withdrawn"
148
- when /^draft/
149
- stage = "draft-public"
150
- subst = "active"
151
- else
152
- stage = status
153
- subst = "active"
154
- end
155
-
156
- iter = nil
157
- if stage.include? "draft"
158
- iter = 1
159
- history = doc.xpath("//span[@id='pub-history-container']/a"\
160
- "|//span[@id='pub-history-container']/span")
161
- history.each_with_index do |h, idx|
162
- next if h.name == "a"
163
-
164
- iter = idx + 1 if idx.positive?
165
- break
166
- end
167
- end
168
- end
65
+ def fetch_status(doc) # , status)
66
+ # if doc.is_a? Hash
67
+ stage = doc["status"]
68
+ subst = doc["substage"]
69
+ iter = doc["iteration"] == "initial" ? 1 : doc["iteration"]
70
+ # else
71
+ # case status
72
+ # when "draft (obsolete)"
73
+ # stage = "draft-public"
74
+ # subst = "withdrawn"
75
+ # when "retired draft"
76
+ # stage = "draft-public"
77
+ # subst = "retired"
78
+ # when "withdrawn"
79
+ # stage = "final"
80
+ # subst = "withdrawn"
81
+ # when /^draft/
82
+ # stage = "draft-public"
83
+ # subst = "active"
84
+ # else
85
+ # stage = status
86
+ # subst = "active"
87
+ # end
88
+
89
+ # iter = nil
90
+ # if stage.include? "draft"
91
+ # iter = 1
92
+ # history = doc.xpath("//span[@id='pub-history-container']/a"\
93
+ # "|//span[@id='pub-history-container']/span")
94
+ # history.each_with_index do |h, idx|
95
+ # next if h.name == "a"
96
+
97
+ # iter = idx + 1 if idx.positive?
98
+ # break
99
+ # end
100
+ # end
101
+ # end
169
102
 
170
103
  RelatonNist::DocumentStatus.new stage: stage, substage: subst, iteration: iter.to_s
171
104
  end
@@ -179,49 +112,49 @@ module RelatonNist
179
112
  end
180
113
 
181
114
  # Fetch dates
182
- # @param doc [Nokogiri::HTML::Document]
115
+ # @param doc [Hash]
183
116
  # @param release_date [Date]
184
117
  # @return [Array<Hash>]
185
118
  def fetch_dates(doc, release_date) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
186
119
  dates = [{ type: "published", on: release_date.to_s }]
187
120
 
188
- if doc.is_a? Hash
189
- issued = RelatonBib.parse_date doc["issued-date"]
190
- updated = RelatonBib.parse_date doc["updated-date"]
191
- dates << { type: "updated", on: updated.to_s } if updated
192
- obsoleted = RelatonBib.parse_date doc["obsoleted-date"]
193
- dates << { type: "obsoleted", on: obsoleted.to_s } if obsoleted
194
- else
195
- d = doc.at("//span[@id='pub-release-date']")&.text&.strip
196
- issued = RelatonBib.parse_date d
197
- end
121
+ # if doc.is_a? Hash
122
+ issued = RelatonBib.parse_date doc["issued-date"]
123
+ updated = RelatonBib.parse_date doc["updated-date"]
124
+ dates << { type: "updated", on: updated.to_s } if updated
125
+ obsoleted = RelatonBib.parse_date doc["obsoleted-date"]
126
+ dates << { type: "obsoleted", on: obsoleted.to_s } if obsoleted
127
+ # else
128
+ # d = doc.at("//span[@id='pub-release-date']")&.text&.strip
129
+ # issued = RelatonBib.parse_date d
130
+ # end
198
131
  dates << { type: "issued", on: issued.to_s }
199
132
  dates
200
133
  end
201
134
 
202
135
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
203
- # @param doc [Nokogiri::HTML::Document, Hash]
136
+ # @param doc [Hash]
204
137
  # @return [Array<RelatonBib::ContributionInfo>]
205
138
  def fetch_contributors(doc)
206
139
  contribs = []
207
- if doc.is_a? Hash
208
- contribs += contributors_json(
209
- doc["authors"], "author", doc["language"], doc["script"]
210
- )
211
- contribs + contributors_json(
212
- doc["editors"], "editor", doc["language"], doc["script"]
213
- )
214
- else
215
- name = "National Institute of Standards and Technology"
216
- org = RelatonBib::Organization.new(
217
- name: name, url: "www.nist.gov", abbreviation: "NIST",
218
- )
219
- contribs << RelatonBib::ContributionInfo.new(entity: org, role: [type: "publisher"])
220
- authors = doc.at('//h4[.="Author(s)"]/following-sibling::p')
221
- contribs += contributors(authors, "author")
222
- editors = doc.at('//h4[.="Editor(s)"]/following-sibling::p')
223
- contribs + contributors(editors, "editor")
224
- end
140
+ # if doc.is_a? Hash
141
+ contribs += contributors_json(
142
+ doc["authors"], "author", doc["language"], doc["script"]
143
+ )
144
+ contribs + contributors_json(
145
+ doc["editors"], "editor", doc["language"], doc["script"]
146
+ )
147
+ # else
148
+ # name = "National Institute of Standards and Technology"
149
+ # org = RelatonBib::Organization.new(
150
+ # name: name, url: "www.nist.gov", abbreviation: "NIST",
151
+ # )
152
+ # contribs << RelatonBib::ContributionInfo.new(entity: org, role: [type: "publisher"])
153
+ # authors = doc.at('//h4[.="Author(s)"]/following-sibling::p')
154
+ # contribs += contributors(authors, "author")
155
+ # editors = doc.at('//h4[.="Editor(s)"]/following-sibling::p')
156
+ # contribs + contributors(editors, "editor")
157
+ # end
225
158
  end
226
159
 
227
160
  # @param doc [Array<Hash>]
@@ -256,37 +189,37 @@ module RelatonNist
256
189
  # @param doc [Nokogiri::HTML::Element, Array<Hash>]
257
190
  # @param role [String]
258
191
  # @return [Array<RelatonBib::ContributionInfo>]
259
- def contributors(doc, role, lang = "en", script = "Latn")
260
- return [] if doc.nil?
261
-
262
- doc.text.split(", ").map do |contr|
263
- /(?<an>.+?)(\s+\((?<abbrev>.+?)\))?$/ =~ contr.strip
264
- if abbrev && an.downcase !~ /(task|force|group)/ && an.split.size.between?(2, 3)
265
- fullname = RelatonBib::FullName.new(
266
- completename: RelatonBib::LocalizedString.new(an, lang, script)
267
- )
268
- case abbrev
269
- when "NIST"
270
- org_name = "National Institute of Standards and Technology"
271
- url = "www.nist.gov"
272
- when "MITRE"
273
- org_name = abbrev
274
- url = "www.mitre.org"
275
- else
276
- org_name = abbrev
277
- url = nil
278
- end
279
- org = RelatonBib::Organization.new name: org_name, url: url, abbreviation: abbrev
280
- affiliation = RelatonBib::Affiliation.new organization: org
281
- entity = RelatonBib::Person.new(
282
- name: fullname, affiliation: [affiliation],
283
- )
284
- else
285
- entity = RelatonBib::Organization.new name: an, abbreviation: abbrev
286
- end
287
- RelatonBib::ContributionInfo.new entity: entity, role: [type: role]
288
- end
289
- end
192
+ # def contributors(doc, role, lang = "en", script = "Latn")
193
+ # return [] if doc.nil?
194
+
195
+ # doc.text.split(", ").map do |contr|
196
+ # /(?<an>.+?)(\s+\((?<abbrev>.+?)\))?$/ =~ contr.strip
197
+ # if abbrev && an.downcase !~ /(task|force|group)/ && an.split.size.between?(2, 3)
198
+ # fullname = RelatonBib::FullName.new(
199
+ # completename: RelatonBib::LocalizedString.new(an, lang, script)
200
+ # )
201
+ # case abbrev
202
+ # when "NIST"
203
+ # org_name = "National Institute of Standards and Technology"
204
+ # url = "www.nist.gov"
205
+ # when "MITRE"
206
+ # org_name = abbrev
207
+ # url = "www.mitre.org"
208
+ # else
209
+ # org_name = abbrev
210
+ # url = nil
211
+ # end
212
+ # org = RelatonBib::Organization.new name: org_name, url: url, abbreviation: abbrev
213
+ # affiliation = RelatonBib::Affiliation.new organization: org
214
+ # entity = RelatonBib::Person.new(
215
+ # name: fullname, affiliation: [affiliation],
216
+ # )
217
+ # else
218
+ # entity = RelatonBib::Organization.new name: an, abbreviation: abbrev
219
+ # end
220
+ # RelatonBib::ContributionInfo.new entity: entity, role: [type: role]
221
+ # end
222
+ # end
290
223
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
291
224
 
292
225
  # @param name [Hash]
@@ -313,16 +246,16 @@ module RelatonNist
313
246
  [RelatonBib::LocalizedString.new(part, lang, script)]
314
247
  end
315
248
 
316
- # @param doc [String, Hash]
249
+ # @param doc [Hash]
317
250
  # @return [String, NilClass]
318
251
  def fetch_edition(doc)
319
- if doc.is_a? Hash
320
- return unless doc["edition"]
252
+ # if doc.is_a? Hash
253
+ return unless doc["edition"]
321
254
 
322
- rev = doc["edition"]
323
- else
324
- return unless /(?<=Rev\.\s)(?<rev>\d+)/ =~ doc
325
- end
255
+ rev = doc["edition"]
256
+ # else
257
+ # return unless /(?<=Rev\.\s)(?<rev>\d+)/ =~ doc
258
+ # end
326
259
 
327
260
  "Revision #{rev}"
328
261
  end
@@ -330,17 +263,17 @@ module RelatonNist
330
263
  # Fetch abstracts.
331
264
  # @param doc [Nokigiri::HTML::Document]
332
265
  # @return [Array<Hash>]
333
- def fetch_abstract(doc)
334
- abstract_content = doc.xpath(
335
- '//div[contains(@class, "pub-abstract-callout")]/div[1]/p',
336
- ).text
337
- [{
338
- content: abstract_content,
339
- language: "en",
340
- script: "Latn",
341
- format: "text/plain",
342
- }]
343
- end
266
+ # def fetch_abstract(doc)
267
+ # abstract_content = doc.xpath(
268
+ # '//div[contains(@class, "pub-abstract-callout")]/div[1]/p',
269
+ # ).text
270
+ # [{
271
+ # content: abstract_content,
272
+ # language: "en",
273
+ # script: "Latn",
274
+ # format: "text/plain",
275
+ # }]
276
+ # end
344
277
 
345
278
  # Fetch copyright.
346
279
  # @param doc [Nokogiri::HTL::Document, String]
@@ -348,30 +281,30 @@ module RelatonNist
348
281
  def fetch_copyright(doc)
349
282
  name = "National Institute of Standards and Technology"
350
283
  url = "www.nist.gov"
351
- d = if doc.is_a? String then doc
352
- else
353
- doc.at("//span[@id='pub-release-date']")&.text&.strip
354
- end
355
- from = d&.match(/\d{4}/)&.to_s
284
+ # d = if doc.is_a? String then doc
285
+ # else
286
+ # doc.at("//span[@id='pub-release-date']")&.text&.strip
287
+ # end
288
+ from = doc&.match(/\d{4}/)&.to_s
356
289
  [{ owner: [{ name: name, abbreviation: "NIST", url: url }], from: from }]
357
290
  end
358
291
 
359
292
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
360
293
 
361
294
  # Fetch links.
362
- # @param doc [Nokogiri::HTML::Document, Hash]
295
+ # @param doc [Hash]
363
296
  # @return [Array<Hash>]
364
297
  def fetch_link(doc)
365
298
  links = []
366
- if doc.is_a? Hash
367
- links << { type: "uri", content: doc["uri"] } if doc["uri"]
368
- doi = "https://doi.org/" + doc["doi"] if doc["doi"]
369
- else
370
- pub = doc.at "//p/strong[contains(., 'Publication:')]"
371
- pdf = pub&.at "./following-sibling::a[.=' Local Download']"
372
- doi = pub&.at("./following-sibling::a[contains(.,'(DOI)')]")&.attr :href
373
- links << { type: "pdf", content: pdf[:href] } if pdf
374
- end
299
+ # if doc.is_a? Hash
300
+ links << { type: "uri", content: doc["uri"] } if doc["uri"]
301
+ doi = "https://doi.org/" + doc["doi"] if doc["doi"]
302
+ # else
303
+ # pub = doc.at "//p/strong[contains(., 'Publication:')]"
304
+ # pdf = pub&.at "./following-sibling::a[.=' Local Download']"
305
+ # doi = pub&.at("./following-sibling::a[contains(.,'(DOI)')]")&.attr :href
306
+ # links << { type: "pdf", content: pdf[:href] } if pdf
307
+ # end
375
308
  links << { type: "doi", content: doi } if doi
376
309
  links
377
310
  end
@@ -380,19 +313,19 @@ module RelatonNist
380
313
  # Fetch relations.
381
314
  # @param doc [Nokogiri::HTML::Document]
382
315
  # @return [Array<RelatonNist::DocumentRelation>]
383
- def fetch_relations(doc)
384
- relations = doc.xpath('//span[@id="pub-supersedes-container"]/a').map do |r|
385
- doc_relation "supersedes", r.text, DOMAIN + r[:href]
386
- end
387
-
388
- relations += doc.xpath('//span[@id="pub-part-container"]/a').map do |r|
389
- doc_relation "partOf", r.text, DOMAIN + r[:href]
390
- end
391
-
392
- relations + doc.xpath('//span[@id="pub-related-container"]/a').map do |r|
393
- doc_relation "updates", r.text, DOMAIN + r[:href]
394
- end
395
- end
316
+ # def fetch_relations(doc)
317
+ # relations = doc.xpath('//span[@id="pub-supersedes-container"]/a').map do |r|
318
+ # doc_relation "supersedes", r.text, DOMAIN + r[:href]
319
+ # end
320
+
321
+ # relations += doc.xpath('//span[@id="pub-part-container"]/a').map do |r|
322
+ # doc_relation "partOf", r.text, DOMAIN + r[:href]
323
+ # end
324
+
325
+ # relations + doc.xpath('//span[@id="pub-related-container"]/a').map do |r|
326
+ # doc_relation "updates", r.text, DOMAIN + r[:href]
327
+ # end
328
+ # end
396
329
  # rubocop:enable Metrics/AbcSize
397
330
 
398
331
  def fetch_relations_json(doc)
@@ -425,62 +358,62 @@ module RelatonNist
425
358
 
426
359
  # @param doc [Nokogiri::HTML::Document]
427
360
  # @return [Array<RelatonBib::Series>]
428
- def fetch_series(doc)
429
- series = doc.xpath "//span[@id='pub-history-container']/a"\
430
- "|//span[@id='pub-history-container']/span"
431
- series.map.with_index do |s, idx|
432
- next if s.name == "span"
433
-
434
- iter = if idx.zero? then "I"
435
- else idx + 1
436
- end
437
-
438
- content = s.text.match(/^[^\(]+/).to_s.strip.squeeze " "
439
-
440
- ref = case s.text
441
- when /^Draft/
442
- content.match(/(?<=Draft\s).+/).to_s + " (#{iter}PD)"
443
- when /\(Draft\)/ then content + " (#{iter}PD)"
444
- else content
445
- end
446
-
447
- fref = RelatonBib::FormattedRef.new(
448
- content: ref, language: "en", script: "Latn", format: "text/plain",
449
- )
450
- RelatonBib::Series.new(formattedref: fref)
451
- end.select { |s| s }
452
- end
361
+ # def fetch_series(doc)
362
+ # series = doc.xpath "//span[@id='pub-history-container']/a"\
363
+ # "|//span[@id='pub-history-container']/span"
364
+ # series.map.with_index do |s, idx|
365
+ # next if s.name == "span"
366
+
367
+ # iter = if idx.zero? then "I"
368
+ # else idx + 1
369
+ # end
370
+
371
+ # content = s.text.match(/^[^\(]+/).to_s.strip.squeeze " "
372
+
373
+ # ref = case s.text
374
+ # when /^Draft/
375
+ # content.match(/(?<=Draft\s).+/).to_s + " (#{iter}PD)"
376
+ # when /\(Draft\)/ then content + " (#{iter}PD)"
377
+ # else content
378
+ # end
379
+
380
+ # fref = RelatonBib::FormattedRef.new(
381
+ # content: ref, language: "en", script: "Latn", format: "text/plain",
382
+ # )
383
+ # RelatonBib::Series.new(formattedref: fref)
384
+ # end.select { |s| s }
385
+ # end
453
386
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
454
387
 
455
- # @param doc [Nokogiri::HTML::Document, Hash]
388
+ # @param doc [Hash]
456
389
  # @return [Array<RelatonNist::Keyword>]
457
390
  def fetch_keywords(doc)
458
- kws = if doc.is_a? Hash
459
- doc["keywords"]
460
- else
461
- doc.xpath "//span[@id='pub-keywords-container']/span"
462
- end
463
- kws.map { |kw| kw.is_a?(String) ? kw : kw.text }
391
+ # kws = if doc.is_a? Hash
392
+ # doc["keywords"]
393
+ # else
394
+ # doc.xpath "//span[@id='pub-keywords-container']/span"
395
+ # end
396
+ doc["keywords"].map { |kw| kw.is_a?(String) ? kw : kw.text }
464
397
  end
465
398
 
466
399
  # rubocop:disable Metrics/AbcSize
467
400
  # @param doc [Nokogiri::HTML::Document]
468
401
  # @return [RelatonNist::CommentPeriod, NilClass]
469
- def fetch_commentperiod(doc)
470
- cp = doc.at "//span[@id='pub-comments-due']"
471
- return unless cp
402
+ # def fetch_commentperiod(doc)
403
+ # cp = doc.at "//span[@id='pub-comments-due']"
404
+ # return unless cp
472
405
 
473
- to = Date.strptime cp.text.strip, "%B %d, %Y"
406
+ # to = Date.strptime cp.text.strip, "%B %d, %Y"
474
407
 
475
- d = doc.at("//span[@id='pub-release-date']").text.strip
476
- from = Date.strptime(d, "%B %Y").to_s
408
+ # d = doc.at("//span[@id='pub-release-date']").text.strip
409
+ # from = Date.strptime(d, "%B %Y").to_s
477
410
 
478
- ex = doc.at "//strong[contains(.,'The comment closing date has been "\
479
- "extended to')]"
480
- ext = ex&.text&.match(/\w+\s\d{2},\s\d{4}/).to_s
481
- extended = ext.empty? ? nil : Date.strptime(ext, "%B %d, %Y")
482
- CommentPeriod.new from: from, to: to, extended: extended
483
- end
411
+ # ex = doc.at "//strong[contains(.,'The comment closing date has been "\
412
+ # "extended to')]"
413
+ # ext = ex&.text&.match(/\w+\s\d{2},\s\d{4}/).to_s
414
+ # extended = ext.empty? ? nil : Date.strptime(ext, "%B %d, %Y")
415
+ # CommentPeriod.new from: from, to: to, extended: extended
416
+ # end
484
417
  # rubocop:enable Metrics/AbcSize
485
418
 
486
419
  # @param json [Hash]
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.9.0".freeze
2
+ VERSION = "1.9.1".freeze
3
3
  end
data/relaton_nist.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
27
27
  spec.add_development_dependency "pry-byebug"
28
- spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency "ruby-jing"
31
31
  spec.add_development_dependency "simplecov"
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.9.0
4
+ version: 1.9.1
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-08-26 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +166,7 @@ files:
166
166
  - README.adoc
167
167
  - Rakefile
168
168
  - bin/console
169
+ - bin/rspec
169
170
  - bin/setup
170
171
  - grammars/basicdoc.rng
171
172
  - grammars/biblio.rng