Class: NistBib::HitCollection
- Inherits:
-
Array
- Object
- Array
- NistBib::HitCollection
- Defined in:
- lib/nistbib/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.
27 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 |
# File 'lib/nistbib/hit_collection.rb', line 27 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 += "&status-lg=Draft,Withdrawn" if /PD/ =~ opts[:stage] 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 # concat(hits.map { |h| Hit.new(h, self) }) @fetched = false # @hit_pages = hit_pages end |
Instance Attribute Details
#fetched ⇒ TrueClass, FalseClass (readonly)
15 16 17 |
# File 'lib/nistbib/hit_collection.rb', line 15 def fetched @fetched end |
#text ⇒ String (readonly)
18 19 20 |
# File 'lib/nistbib/hit_collection.rb', line 18 def text @text end |
#year ⇒ String (readonly)
21 22 23 |
# File 'lib/nistbib/hit_collection.rb', line 21 def year @year end |
Instance Method Details
#fetch ⇒ Iecbib::HitCollection
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nistbib/hit_collection.rb', line 63 def fetch workers = WorkersPool.new 4 workers.worker(&:fetch) each do |hit| workers << hit end workers.end workers.result @fetched = true self end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/nistbib/hit_collection.rb', line 79 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>" end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/nistbib/hit_collection.rb', line 75 def to_s inspect end |