Class: RelatonNist::HitCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/relaton_nist/hit_collection.rb

Overview

Page of hit collection.

Constant Summary collapse

DOMAIN =
"https://csrc.nist.gov"
DATAFILE =
File.expand_path "data/pubs-export.zip", __dir__

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref_nbr, year = nil, opts = {}) ⇒ HitCollection

Returns a new instance of HitCollection.

Parameters:

  • ref_nbr (String)
  • year (String) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :stage (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/relaton_nist/hit_collection.rb', line 30

def initialize(ref_nbr, year = nil, opts = {})
  @text = ref_nbr
  @year = year

  /(?<docid>(SP|FIPS)\s[0-9-]+)/ =~ text
  hits = docid ? from_json(docid, **opts) : from_csrc(**opts)

  hits.sort! do |a, b|
    if a.sort_value != b.sort_value
      b.sort_value - a.sort_value
    else
      (b.hit[:release_date] - a.hit[:release_date]).to_i
    end
  end
  concat hits
  @fetched = false
end

Instance Attribute Details

#fetchedTrueClass, FalseClass (readonly)

Returns:

  • (TrueClass, FalseClass)


16
17
18
# File 'lib/relaton_nist/hit_collection.rb', line 16

def fetched
  @fetched
end

#textString (readonly)

Returns:

  • (String)


19
20
21
# File 'lib/relaton_nist/hit_collection.rb', line 19

def text
  @text
end

#yearString (readonly)

Returns:

  • (String)


22
23
24
# File 'lib/relaton_nist/hit_collection.rb', line 22

def year
  @year
end

Instance Method Details

#fetchIecbib::HitCollection

Returns:

  • (Iecbib::HitCollection)


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/relaton_nist/hit_collection.rb', line 50

def fetch
  workers = RelatonBib::WorkersPool.new 4
  workers.worker(&:fetch)
  each do |hit|
    workers << hit
  end
  workers.end
  workers.result
  @fetched = true
  self
end

#inspectString

Returns:

  • (String)


67
68
69
# File 'lib/relaton_nist/hit_collection.rb', line 67

def inspect
  "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>"
end

#to_sObject



62
63
64
# File 'lib/relaton_nist/hit_collection.rb', line 62

def to_s
  inspect
end