Class: RelatonNist::Scrapper

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

Constant Summary collapse

DOMAIN =
"https://csrc.nist.gov".freeze

Class Method Summary collapse

Class Method Details

.fetch_gh(hit_data) ⇒ Object



17
18
19
20
21
22
# File 'lib/relaton_nist/scrapper.rb', line 17

def fetch_gh(hit_data)
  yaml = OpenURI.open_uri "#{HitCollection::GHNISTDATA}#{hit_data[:path]}"
  hash = YAML.safe_load yaml
  hash["fetched"] = Date.today.to_s
  NistBibliographicItem.from_hash hash
end

.parse_json(hit_data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/relaton_nist/scrapper.rb', line 24

def parse_json(hit_data)
  item_data = from_json hit_data
  titles = fetch_titles(hit_data)
  # unless /^(SP|NISTIR|FIPS) /.match? item_data[:docid][0].id
  #   item_data[:docid][0] = RelatonBib::DocumentIdentifier.new(
  #     id: titles[0][:content].upcase, type: "NIST", primary: true,
  #   )
  # end
  item_data[:fetched] = Date.today.to_s
  item_data[:type] = "standard"
  item_data[:title] = titles
  item_data[:doctype] = RelatonBib::DocumentType.new(type: "standard")

  NistBibliographicItem.new(**item_data)
end

.parse_page(hit_data) ⇒ Hash

Parse page.

Parameters:

  • hit_data (Hash)

Returns:

  • (Hash)


13
14
15
# File 'lib/relaton_nist/scrapper.rb', line 13

def parse_page(hit_data)
  hit_data[:path] ? fetch_gh(hit_data) : parse_json(hit_data)
end