Class: Relaton::Nist::Bibliography

Inherits:
Object
  • Object
show all
Extended by:
Core::DateParser
Defined in:
lib/relaton/nist/bibliography.rb

Class Method Summary collapse

Class Method Details

.get(code, year = nil, opts = {}) ⇒ Relaton::Nist::ItemData?

Get NIST document by reference

Parameters:

  • code (String)

    the NIST standard Code to look up

  • year (String) (defaults to: nil)

    the year the standard was published (optional)

  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :all_parts (Boolean)

    restricted to all parts

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/relaton/nist/bibliography.rb', line 31

def get(code, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  return fetch_ref_err(code, year, []) if code.match?(/\sEP$/)

  /^(?<code2>[^(]+)(?:\((?<date2>\w+\s(?:\d{2},\s)?\d{4})\))?\s?\(?(?:(?<=\()(?<stage>(?:I|F|\d)PD))?/ =~ code
  stage ||= /(?<=\.)PD-\w+(?=\.)/.match(code)&.to_s
  if code2
    code = code2.strip
    opts[:date] = parse_date(date2, str: false) if date2
    opts[:stage] = stage if stage
  end

  if year.nil?
    /^(?<code1>[^:]+):(?<year1>[^:]+)$/ =~ code
    unless code1.nil?
      code = code1
      year = year1
    end
  end

  code += "-1" if opts[:all_parts]
  nistbib_get(code, year, opts)
end

.search(text, year = nil, opts = {}) ⇒ Relaton::Nist::HitCollection

Search NIST documents by reference

Parameters:

  • text (String)

    reference

Returns:



14
15
16
17
18
19
# File 'lib/relaton/nist/bibliography.rb', line 14

def search(text, year = nil, opts = {})
  ref = text.sub(/^NISTIR/, "NIST IR").sub(/\/Add/, " Add")
  HitCollection.search ref, year, opts
rescue OpenURI::HTTPError, SocketError, OpenSSL::SSL::SSLError => e
  raise Relaton::RequestError, e.message
end