Class: RelatonNist::HitCollection
- Inherits:
-
Array
- Object
- Array
- RelatonNist::HitCollection
- Defined in:
- lib/relaton_nist/hit_collection.rb
Overview
Page of hit collection.
Constant Summary collapse
- DOMAIN =
"https://csrc.nist.gov"
Instance Attribute Summary collapse
- #fetched ⇒ TrueClass, FalseClass readonly
- #text ⇒ String readonly
- #year ⇒ String readonly
Instance Method Summary collapse
- #fetch ⇒ Iecbib::HitCollection
-
#initialize(ref_nbr, year = nil, opts = {}) ⇒ HitCollection
constructor
A new instance of HitCollection.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ref_nbr, year = nil, opts = {}) ⇒ HitCollection
Returns a new instance of HitCollection.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/relaton_nist/hit_collection.rb', line 28 def initialize(ref_nbr, year = nil, opts = {}) @text = ref_nbr @year = year from, to = nil if year d = Date.strptime year, "%Y" from = d.strftime "%m/%d/%Y" to = d.next_year.prev_day.strftime "%m/%d/%Y" end url = "#{DOMAIN}/publications/search?keywords-lg=#{ref_nbr}" url += "&dateFrom-lg=#{from}" if from url += "&dateTo-lg=#{to}" if to url += if /PD/ =~ opts[:stage] "&status-lg=Draft,Retired Draft,Withdrawn" else "&status-lg=Final,Withdrawn" end doc = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize) hits = doc.css("table.publications-table > tbody > tr").map do |h| link = h.at("td/div/strong/a") serie = h.at("td[1]").text.strip code = h.at("td[2]").text.strip title = link.text url = DOMAIN + link[:href] status = h.at("td[4]").text.strip.downcase release_date = Date.strptime h.at("td[5]").text.strip, "%m/%d/%Y" Hit.new( { code: code, serie: serie, title: title, url: url, status: status, release_date: release_date }, self ) end concat(hits.sort { |a, b| a.sort_value - b.sort_value }) # concat(hits.map { |h| Hit.new(h, self) }) @fetched = false # @hit_pages = hit_pages end |
Instance Attribute Details
#fetched ⇒ TrueClass, FalseClass (readonly)
14 15 16 |
# File 'lib/relaton_nist/hit_collection.rb', line 14 def fetched @fetched end |
#text ⇒ String (readonly)
17 18 19 |
# File 'lib/relaton_nist/hit_collection.rb', line 17 def text @text end |
#year ⇒ String (readonly)
20 21 22 |
# File 'lib/relaton_nist/hit_collection.rb', line 20 def year @year end |
Instance Method Details
#fetch ⇒ Iecbib::HitCollection
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/relaton_nist/hit_collection.rb', line 70 def fetch workers = RelatonBib::WorkersPool.new 4 workers.worker(&:fetch) each do |hit| workers << hit end workers.end workers.result @fetched = true self end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/relaton_nist/hit_collection.rb', line 86 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>" end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/relaton_nist/hit_collection.rb', line 82 def to_s inspect end |