nistbib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef1ae9dcd37608cd47b565f151b291adcf85cca5
4
+ data.tar.gz: 953dce58fd24be8d0e39a3ec9622a3a5508bbb2c
5
+ SHA512:
6
+ metadata.gz: 25007561f152223a16046b5b05811312d4bda2feb5cb2663a351a61da64fe3cd2edee5ce104aeb21918203a1f44529ae4f5ace9f8c8c1f3299eed91966b3b4c7
7
+ data.tar.gz: 1e98dca81f2a883899b4f0ae7f3a8fc057293b208adce21b4e36186db813667e669e534bf8071685ee872d70ccca039918c1f145476c1e6890abe9eb9fe34faa
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.0
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nistbib.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nistbib (0.1.0)
5
+ iso-bib-item (~> 0.4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.6.0)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ byebug (10.0.2)
13
+ coderay (1.1.2)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ docile (1.3.1)
18
+ equivalent-xml (0.6.0)
19
+ nokogiri (>= 1.4.3)
20
+ hashdiff (0.3.8)
21
+ iso-bib-item (0.4.4)
22
+ isoics (~> 0.1.6)
23
+ nokogiri (~> 1.8.4)
24
+ ruby_deep_clone (~> 0.8.0)
25
+ isoics (0.1.7)
26
+ json (2.1.0)
27
+ method_source (0.9.2)
28
+ mini_portile2 (2.3.0)
29
+ nokogiri (1.8.5)
30
+ mini_portile2 (~> 2.3.0)
31
+ pry (0.12.2)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.9.0)
34
+ pry-byebug (3.6.0)
35
+ byebug (~> 10.0)
36
+ pry (~> 0.10)
37
+ public_suffix (3.0.3)
38
+ rake (10.5.0)
39
+ rspec (3.8.0)
40
+ rspec-core (~> 3.8.0)
41
+ rspec-expectations (~> 3.8.0)
42
+ rspec-mocks (~> 3.8.0)
43
+ rspec-core (3.8.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-expectations (3.8.2)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.8.0)
48
+ rspec-mocks (3.8.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.8.0)
51
+ rspec-support (3.8.0)
52
+ ruby_deep_clone (0.8.0)
53
+ safe_yaml (1.0.4)
54
+ simplecov (0.16.1)
55
+ docile (~> 1.1)
56
+ json (>= 1.8, < 3)
57
+ simplecov-html (~> 0.10.0)
58
+ simplecov-html (0.10.2)
59
+ vcr (4.0.0)
60
+ webmock (3.5.1)
61
+ addressable (>= 2.3.6)
62
+ crack (>= 0.3.2)
63
+ hashdiff
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 2.0)
70
+ byebug
71
+ equivalent-xml (~> 0.6)
72
+ nistbib!
73
+ pry-byebug
74
+ rake (~> 10.0)
75
+ rspec (~> 3.0)
76
+ simplecov
77
+ vcr
78
+ webmock
79
+
80
+ BUNDLED WITH
81
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Andrei Kislichenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Nistbib
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nistbib`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nistbib'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nistbib
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nistbib.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nistbib"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NistBib
4
+ # Hit.
5
+ class Hit
6
+ # @return [Isobib::HitCollection]
7
+ attr_reader :hit_collection
8
+
9
+ # @return [Array<Hash>]
10
+ attr_reader :hit
11
+
12
+ # @param hit [Hash]
13
+ # @param hit_collection [Isobib:HitCollection]
14
+ def initialize(hit, hit_collection = nil)
15
+ @hit = hit
16
+ @hit_collection = hit_collection
17
+ end
18
+
19
+ # Parse page.
20
+ # @return [Isobib::IsoBibliographicItem]
21
+ def fetch
22
+ @fetch ||= Scrapper.parse_page @hit
23
+ end
24
+
25
+ # @return [String]
26
+ def to_s
27
+ inspect
28
+ end
29
+
30
+ # @return [String]
31
+ def inspect
32
+ "<#{self.class}:#{format('%#.14x', object_id << 1)} "\
33
+ "@text=\"#{@hit_collection&.text}\" "\
34
+ "@fetched=\"#{!@fetch.nil?}\" "\
35
+ "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
36
+ "@title=\"#{@hit[:code]}\">"
37
+ end
38
+
39
+ # @return [String]
40
+ def to_xml(opts = {})
41
+ #if builder
42
+ #fetch.to_xml builder, opts
43
+ #else
44
+ builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
45
+ fetch.to_xml xml, opts
46
+ end
47
+ builder.doc.root.to_xml
48
+ #end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nistbib/hit'
4
+ require 'nistbib/workers_pool'
5
+ require "addressable/uri"
6
+ require 'open-uri'
7
+
8
+ module NistBib
9
+ # Page of hit collection.
10
+ class HitCollection < Array
11
+
12
+ DOMAIN = 'https://csrc.nist.gov'
13
+
14
+ # @return [TrueClass, FalseClass]
15
+ attr_reader :fetched
16
+
17
+ # @return [String]
18
+ attr_reader :text
19
+
20
+ # @return [String]
21
+ attr_reader :year
22
+
23
+ # @param ref_nbr [String]
24
+ # @param year [String]
25
+ def initialize(ref_nbr, year = nil) #(text, hit_pages = nil)
26
+ @text = ref_nbr
27
+ @year = year
28
+ from, to = nil
29
+ if year
30
+ d = Date.strptime year, '%Y'
31
+ from = d.strftime '%m/%d/%Y'
32
+ to = d.next_year.prev_day.strftime '%m/%d/%Y'
33
+ end
34
+ url = "#{DOMAIN}/publications/search?keywords-lg=#{ref_nbr}&dateFrom-lg=#{from}&dateTo-lg=#{to}"
35
+ doc = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize)
36
+ hits = doc.css('table.publications-table > tbody > tr').map do |h|
37
+ link = h.at('td/div/strong/a')
38
+ code = h.at('td[2]').text.strip
39
+ title = link.text
40
+ url = DOMAIN + link[:href]
41
+ Hit.new({ code: code, title: title, url: url }, self)
42
+ end
43
+ concat hits
44
+ # concat(hits.map { |h| Hit.new(h, self) })
45
+ @fetched = false
46
+ # @hit_pages = hit_pages
47
+ end
48
+
49
+ # @return [Iecbib::HitCollection]
50
+ def fetch
51
+ workers = WorkersPool.new 4
52
+ workers.worker(&:fetch)
53
+ each do |hit|
54
+ workers << hit
55
+ end
56
+ workers.end
57
+ workers.result
58
+ @fetched = true
59
+ self
60
+ end
61
+
62
+ def to_s
63
+ inspect
64
+ end
65
+
66
+ def inspect
67
+ "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>"
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,97 @@
1
+ require 'nistbib/scrapper'
2
+ require 'nistbib/hit_collection'
3
+
4
+ module NistBib
5
+ class NistBibliography
6
+ class << self
7
+ # @param text [String]
8
+ # @return [NistBib::HitCollection]
9
+ def search(text, year = nil)
10
+ HitCollection.new text, year
11
+ rescue
12
+ warn "Could not access https://www.nist.gov"
13
+ []
14
+ end
15
+
16
+ # @param code [String] the NIST standard Code to look up (e..g "8200")
17
+ # @param year [String] the year the standard was published (optional)
18
+ # @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
19
+ # @return [String] Relaton XML serialisation of reference
20
+ def get(code, year, opts)
21
+ code += '-1' if opts[:all_parts]
22
+ ret = nistbib_get1(code, year, opts)
23
+ return nil if ret.nil?
24
+ ret.to_most_recent_reference unless year || opts[:keep_year]
25
+ ret.to_all_parts if opts[:all_parts]
26
+ ret
27
+ end
28
+
29
+ private
30
+
31
+ def nistbib_get1(code, year, opts)
32
+ result = nistbib_search_filter(code, year) or return nil
33
+ ret = nistbib_results_filter(result, year)
34
+ return ret[:ret] if ret[:ret]
35
+ fetch_ref_err(code, year, ret[:years])
36
+ end
37
+
38
+ # Sort through the results from Isobib, fetching them three at a time,
39
+ # and return the first result that matches the code,
40
+ # matches the year (if provided), and which # has a title (amendments do not).
41
+ # Only expects the first page of results to be populated.
42
+ # Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
43
+ # If no match, returns any years which caused mismatch, for error reporting
44
+ def nistbib_results_filter(result, year)
45
+ missed_years = []
46
+ result.each_slice(3) do |s| # ISO website only allows 3 connections
47
+ fetch_pages(s, 3).each_with_index do |r, i|
48
+ return { ret: r } if !year
49
+ r.dates.select { |d| d.type == "published" }.each do |d|
50
+ return { ret: r } if year.to_i == d.on.year
51
+ missed_years << d.on.year
52
+ end
53
+ end
54
+ end
55
+ { years: missed_years }
56
+ end
57
+
58
+ def fetch_pages(s, n)
59
+ workers = WorkersPool.new n
60
+ workers.worker { |w| { i: w[:i], hit: w[:hit].fetch } }
61
+ s.each_with_index { |hit, i| workers << { i: i, hit: hit } }
62
+ workers.end
63
+ workers.result.sort { |x, y| x[:i] <=> y[:i] }.map { |x| x[:hit] }
64
+ end
65
+
66
+ def nistbib_search_filter(code, year)
67
+ # docidrx = %r{^(ISO|IEC)[^0-9]*\s[0-9-]+}
68
+ # corrigrx = %r{^(ISO|IEC)[^0-9]*\s[0-9-]+:[0-9]+/}
69
+ warn "fetching #{code}..."
70
+ result = search(code, year)
71
+ result.select do |i|
72
+ !i.hit[:code].empty?
73
+ # i.hit[:code] &&
74
+ # i.hit[:code].match(docidrx).to_s == code &&
75
+ # corrigrx !~ i.hit[:code]
76
+ end
77
+ end
78
+
79
+ def fetch_ref_err(code, year, missed_years)
80
+ id = year ? "#{code}:#{year}" : code
81
+ warn "WARNING: no match found online for #{id}. "\
82
+ "The code must be exactly like it is on the standards website."
83
+ warn "(There was no match for #{year}, though there were matches "\
84
+ "found for #{missed_years.join(', ')}.)" unless missed_years.empty?
85
+ if /\d-\d/ =~ code
86
+ warn "The provided document part may not exist, or the document "\
87
+ "may no longer be published in parts."
88
+ else
89
+ warn "If you wanted to cite all document parts for the reference, "\
90
+ "use \"#{code} (all parts)\".\nIf the document is not a standard, "\
91
+ "use its document type abbreviation (TS, TR, PAS, Guide)."
92
+ end
93
+ nil
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,184 @@
1
+ require 'iso_bib_item'
2
+
3
+ module NistBib
4
+ module Scrapper
5
+ class << self
6
+ DOMAIN = 'https://csrc.nist.gov'
7
+
8
+ # Parse page.
9
+ # @param hit_data [Hash]
10
+ # @return [Hash]
11
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
12
+ def parse_page(hit_data)
13
+ doc = get_page hit_data[:url]
14
+
15
+ IsoBibItem::IsoBibliographicItem.new(
16
+ docid: fetch_docid(doc),
17
+ edition: nil,
18
+ language: ['en'],
19
+ script: ['Latn'],
20
+ titles: fetch_titles(hit_data),
21
+ type: nil,
22
+ docstatus: fetch_status(doc),
23
+ ics: [],
24
+ dates: fetch_dates(doc),
25
+ contributors: fetch_contributors,
26
+ workgroup: nil,
27
+ abstract: fetch_abstract(doc),
28
+ copyright: fetch_copyright(doc),
29
+ link: fetch_link(doc, hit_data[:url]),
30
+ relations: fetch_relations(doc)
31
+ )
32
+ end
33
+
34
+ private
35
+
36
+ # Get page.
37
+ # @param path [String] page's path
38
+ # @return [Array<Nokogiri::HTML::Document, String>]
39
+ def get_page(url)
40
+ uri = URI url
41
+ resp = Net::HTTP.get_response(uri)#.encode("UTF-8")
42
+ Nokogiri::HTML(resp.body)
43
+ end
44
+
45
+ # Fetch docid.
46
+ # @param doc [Nokogiri::HTML::Document]
47
+ # @return [Hash]
48
+ def fetch_docid(doc)
49
+ item_ref = doc.at("//div[contains(@class, 'publications-detail')]/h3").text.strip
50
+ unless item_ref
51
+ return { project_number: '?', part_number: '', prefix: nil, type: 'NIST', id: '?' }
52
+ end
53
+ m = item_ref.match(/(?<=\s)(?<project>[\d-]+)(?<vol>\sVol\.\s)?(?<part>(?(<vol>)\d+|))/)
54
+ {
55
+ project_number: m[:project],
56
+ part_number: m[:part],
57
+ subpart_number: nil,
58
+ prefix: nil,
59
+ type: 'NIST',
60
+ id: item_ref
61
+ }
62
+ end
63
+
64
+ # Fetch status.
65
+ # @param doc [Nokogiri::HTML::Document]
66
+ # @param status [String]
67
+ # @return [Hash]
68
+ def fetch_status(doc)
69
+ withdrawn = doc.at "//p/strong[text()='Withdrawn:']"
70
+ return { status: 'withdrawn', stage: '95', substage: '99' } if withdrawn
71
+
72
+ item_ref = doc.at("//div[contains(@class, 'publications-detail')]/h3").text.strip
73
+ wip = item_ref.match(/(?<=\()\w+/).to_s
74
+ case wip
75
+ when 'DRAFT'
76
+ { status: 'working-draft', stage: '20', substage: '20' }
77
+ # when 'RETIRED DRAFT'
78
+ # { status: 'committee-draft', stage: '30', substage: '00' }
79
+ else
80
+ { status: 'published', stage: '60', substage: '60' }
81
+ end
82
+ end
83
+
84
+ # Fetch titles.
85
+ # @param hit_data [Hash]
86
+ # @return [Array<Hash>]
87
+ def fetch_titles(hit_data)
88
+ titles = hit_data[:title].split ' - '
89
+ # case titles.size
90
+ # when 0
91
+ # intro, main, part = nil, "", nil
92
+ # when 1
93
+ intro, main, part = nil, titles[0], nil
94
+ # when 2
95
+ # if /^(Part|Partie) \d+:/ =~ titles[1]
96
+ # intro, main, part = nil, titles[0], titles[1]
97
+ # else
98
+ # intro, main, part = titles[0], titles[1], nil
99
+ # end
100
+ # when 3
101
+ # intro, main, part = titles[0], titles[1], titles[2]
102
+ # else
103
+ # intro, main, part = titles[0], titles[1], titles[2..-1]&.join(" -- ")
104
+ # end
105
+ [{
106
+ title_intro: intro,
107
+ title_main: main,
108
+ title_part: part,
109
+ language: 'en',
110
+ script: 'Latn'
111
+ }]
112
+ end
113
+
114
+ # Fetch dates
115
+ # @param doc [Nokogiri::HTML::Document]
116
+ # @return [Array<Hash>]
117
+ def fetch_dates(doc)
118
+ dates = []
119
+ d = doc.at("//strong[text()='Date Published:']/../text()[2]").text.strip
120
+ publish_date = Date.strptime(d, '%B %Y').to_s
121
+ unless publish_date.empty?
122
+ dates << { type: 'published', on: publish_date }
123
+ end
124
+ dates
125
+ end
126
+
127
+ def fetch_contributors
128
+ name = 'National Institute of Standards and Technology'
129
+ url = 'www.nist.gov'
130
+ [{ entity: { name: name, url: url, abbreviation: 'NIST' }, roles: ['publisher'] }]
131
+ end
132
+
133
+ # Fetch abstracts.
134
+ # @param doc [Nokigiri::HTML::Document]
135
+ # @return [Array<Array>]
136
+ def fetch_abstract(doc)
137
+ abstract_content = doc.xpath('//div[contains(@class, "pub-abstract-callout")]/div[1]/p').text
138
+ [{
139
+ content: abstract_content,
140
+ language: 'en',
141
+ script: 'Latn'
142
+ }]
143
+ end
144
+
145
+ # Fetch copyright.
146
+ # @param title [String]
147
+ # @return [Hash]
148
+ def fetch_copyright(doc)
149
+ name = 'National Institute of Standards and Technology'
150
+ url = 'www.nist.gov'
151
+ d = doc.at("//strong[text()='Date Published:']/../text()[2]").text.strip
152
+ from = d.match(/\d{4}$/).to_s
153
+ { owner: { name: name, abbreviation: 'NIST', url: url }, from: from }
154
+ end
155
+
156
+ # Fetch links.
157
+ # @param doc [Nokogiri::HTML::Document]
158
+ # @param url [String]
159
+ # @return [Array<Hash>]
160
+ def fetch_link(doc, url)
161
+ links = [{ type: 'src', content: url }]
162
+ obp_elms = doc.at_css('a[data-identity="first-link-display"]')
163
+ links << { type: 'obp', content: obp_elms[:href] } if obp_elms
164
+ links
165
+ end
166
+
167
+ # Fetch relations.
168
+ # @param doc [Nokogiri::HTML::Document]
169
+ # @return [Array<Hash>]
170
+ # rubocop:disable Metrics/MethodLength
171
+ def fetch_relations(doc)
172
+ relations = doc.xpath('//strong[text()="Other Parts of this Publication:"]/following-sibling::a').map do |r|
173
+ { type: 'partOf', identifier: r.text, url: DOMAIN + r[:href] }
174
+ end
175
+
176
+ doc.xpath('//strong[text()="Related NIST Publications:"]/following-sibling::a').map do |r|
177
+ relations << { type: 'updates', identifier: r.text, url: DOMAIN + r[:href] }
178
+ end
179
+
180
+ relations
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,3 @@
1
+ module NistBib
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Workers poll.
4
+ class WorkersPool
5
+ attr_accessor :nb_hits
6
+
7
+ def initialize(num_workers = 2)
8
+ @num_workers = num_workers < 2 ? 2 : num_workers
9
+ @queue = SizedQueue.new(num_workers * 2)
10
+ @result = []
11
+ @nb_hits = 0
12
+ end
13
+
14
+ def worker(&block)
15
+ @threads = Array.new @num_workers do
16
+ Thread.new do
17
+ until (item = @queue.pop) == :END
18
+ @result << yield(item) if block
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def result
25
+ @threads.each(&:join)
26
+ @result
27
+ end
28
+
29
+ def <<(item)
30
+ @queue << item
31
+ self
32
+ end
33
+
34
+ def end
35
+ @num_workers.times { @queue << :END }
36
+ end
37
+
38
+ # def size
39
+ # @result.size
40
+ # end
41
+ end
data/lib/nistbib.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "nistbib/version"
2
+ require 'nistbib/nist_bibliography'
3
+
4
+ module NistBib
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,23 @@
1
+ require "relaton/processor"
2
+
3
+ module Relaton
4
+ module Isobib
5
+ class Processor < Relaton::Processor
6
+
7
+ def initialize
8
+ @short = :nistbib
9
+ @prefix = "NIST"
10
+ @defaultprefix = %r{^(NIST)[ /]}
11
+ @idtype = "NIST"
12
+ end
13
+
14
+ def get(code, date, opts)
15
+ ::Nistbib::NistBibliography.get(code, date, opts)
16
+ end
17
+
18
+ def from_xml(xml)
19
+ IsoBibItem::XMLParser.from_xml xml
20
+ end
21
+ end
22
+ end
23
+ end
data/nistbib.gemspec ADDED
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nistbib/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nistbib"
8
+ spec.version = NistBib::VERSION
9
+ spec.authors = ["Ribose Inc."]
10
+ spec.email = ["open.source@ribose.com"]
11
+
12
+ spec.summary = %q{NistBib: retrive NIST standards.}
13
+ spec.description = %q{NistBib: retrive NIST standards.}
14
+ spec.homepage = "https://github.com/riboseinc/nistbib"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency 'equivalent-xml', '~> 0.6'
28
+ spec.add_development_dependency "pry-byebug"
29
+ spec.add_development_dependency "byebug"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency 'simplecov'
33
+ spec.add_development_dependency 'vcr'
34
+ spec.add_development_dependency 'webmock'
35
+
36
+ spec.add_dependency 'iso-bib-item', '~> 0.4.2'
37
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nistbib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: equivalent-xml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: iso-bib-item
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.4.2
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.4.2
153
+ description: 'NistBib: retrive NIST standards.'
154
+ email:
155
+ - open.source@ribose.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - Gemfile.lock
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - bin/console
169
+ - bin/setup
170
+ - lib/nistbib.rb
171
+ - lib/nistbib/hit.rb
172
+ - lib/nistbib/hit_collection.rb
173
+ - lib/nistbib/nist_bibliography.rb
174
+ - lib/nistbib/scrapper.rb
175
+ - lib/nistbib/version.rb
176
+ - lib/nistbib/workers_pool.rb
177
+ - lib/relaton/processor.rb
178
+ - nistbib.gemspec
179
+ homepage: https://github.com/riboseinc/nistbib
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.6.12
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: 'NistBib: retrive NIST standards.'
203
+ test_files: []