Class: RelatonNist::NistBibliography

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

Class Method Summary collapse

Class Method Details

.get(code, year = nil, opts = {}) ⇒ String

Returns Relaton XML serialisation of reference.

Options Hash (opts):

  • :all_parts (TrueClass, FalseClass)

    restricted to all parts if all-parts reference is required

  • :bibdata (TrueClass, FalseClass)


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
# File 'lib/relaton_nist/nist_bibliography.rb', line 31

def get(code, year = nil, opts = {})
  /^(?<code2>[^\(]+)(\((?<date2>\w+\s(\d{2},\s)?\d{4})\))?\s?\(?((?<=\()(?<stage>[^\)]+))?/ =~ code
  if code2
    code = code2.strip
    if date2
      if /\w+\s\d{4}/ =~ date2
        opts[:issued_date] = Date.strptime date2, "%B %Y"
      elsif /\w+\s\d{2},\s\d{4}/ =~ date2
        opts[:updated_date] = Date.strptime date2, "%B %d, %Y"
      end
    end
    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]
  ret = nistbib_get1(code, year, opts)
  # return nil if ret.nil?
  # ret.to_most_recent_reference unless year || opts[:keep_year]
  # ret.to_all_parts if opts[:all_parts]
  ret
end

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



16
17
18
19
20
# File 'lib/relaton_nist/nist_bibliography.rb', line 16

def search(text, year = nil, opts = {})
  HitCollection.new text, year, opts
rescue OpenURI::HTTPError, SocketError, OpenSSL::SSL::SSLError
  raise RelatonBib::RequestError, "Could not access https://www.nist.gov"
end