Class: Pubid::Nist::NistTechPubs

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/nist/nist_tech_pubs.rb

Constant Summary collapse

URL =
"https://raw.githubusercontent.com/usnistgov/NIST-Tech-Pubs/nist-pages/xml/allrecords.xml".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.converted_doiObject

Returns the value of attribute converted_doi.



15
16
17
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 15

def converted_doi
  @converted_doi
end

.converted_idObject

Returns the value of attribute converted_id.



15
16
17
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 15

def converted_id
  @converted_id
end

.documentsObject

Returns the value of attribute documents.



15
16
17
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 15

def documents
  @documents
end

Class Method Details

.comply_with_pubidObject



68
69
70
71
72
73
74
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 68

def comply_with_pubid
  fetch.select do |doc|
    convert(doc).to_s == doc[:id]
  rescue Pubid::Core::Errors::ParseError
    false
  end
end

.convert(doc) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 29

def convert(doc)
  id = @converted_id[doc[:id]] ||= Pubid::Nist::Identifier.parse(doc[:id])
  return id unless doc.key?(:doi)

  begin
    doi = @converted_doi[doc[:doi]] ||=
      Pubid::Nist::Identifier.parse(doc[:doi])
  rescue Pubid::Core::Errors::ParseError
    return id
  end
  # return more complete pubid
  id.merge(doi)
rescue Pubid::Core::Errors::ParseError
  @converted_doi[doc[:doi]] ||= Pubid::Nist::Identifier.parse(doc[:doi])
end

.different_with_pubidObject



76
77
78
79
80
81
82
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 76

def different_with_pubid
  fetch.reject do |doc|
    convert(doc).to_s == doc[:id]
  rescue Pubid::Core::Errors::ParseError
    true
  end
end

.fetchObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 17

def fetch
  Lightly.prune
  @documents ||= Lightly.get "documents" do
    Nokogiri::XML(URI.open(URL))
      .xpath("/body/query/doi_record/report-paper/report-paper_metadata")
      .map { |doc| parse_docid doc }
  end
rescue StandardError => e
  warn e.message
  []
end

.parse_docid(doc) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 45

def parse_docid(doc)
  id = doc.at("publisher_item/item_number", "publisher_item/identifier")
         &.text&.sub(%r{^/}, "")
  if id == "NBS BH 10"
    # XXX: "doi" attribute is missing for doi_data
    doi = "NBS.BH.10"
  else
    doi = doc.at("doi_data/doi").text.gsub("10.6028/", "")
  end

  title = doc.at("titles/title").text
  title += " #{doc.at('titles/subtitle').text}" if doc.at("titles/subtitle")
  case doi
  when "10.6028/NBS.CIRC.12e2revjune" then id.sub!("13e", "12e")
  when "10.6028/NBS.CIRC.36e2" then id.sub!("46e", "36e")
  when "10.6028/NBS.HB.67suppJune1967" then id.sub!("1965", "1967")
  when "10.6028/NBS.HB.105-1r1990" then id.sub!("105-1-1990", "105-1r1990")
  when "10.6028/NIST.HB.150-10-1995" then id.sub!(/150-10$/, "150-10-1995")
  end

  { id: id || doi, doi: doi, title: title }
end

.parse_fail_with_pubidObject



84
85
86
87
88
89
90
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 84

def parse_fail_with_pubid
  fetch.select do |doc|
    convert(doc).to_s && false
  rescue Pubid::Core::Errors::ParseError
    true
  end
end

.statusObject

returning current document id, doi, title and final PubID



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/pubid/nist/nist_tech_pubs.rb', line 93

def status
  fetch.lazy.map do |doc|
    final_doc = convert(doc)
    {
      id: doc[:id],
      doi: doc[:doi],
      title: doc[:title],
      finalPubId: final_doc.to_s,
      mr: final_doc.to_s(:mr),
    }
  rescue Pubid::Core::Errors::ParseError
    {
      id: doc[:id],
      doi: doc[:doi],
      title: doc[:title],
      finalPubId: "parse error",
      mr: "parse_error",
    }
  end
end