class NistPubid::NistTechPubs
Constants
- URL
Attributes
converted_doi[RW]
converted_id[RW]
documents[RW]
Public Class Methods
comply_with_pubid()
click to toggle source
# File lib/nist_pubid/nist_tech_pubs.rb, line 57 def comply_with_pubid fetch.select do |doc| convert(doc).to_s == doc[:id] rescue Errors::ParseError false end end
convert(doc)
click to toggle source
# File lib/nist_pubid/nist_tech_pubs.rb, line 24 def convert(doc) id = @converted_id[doc[:id]] ||= NistPubid::Document.parse(doc[:id]) return id unless doc.key?(:doi) begin doi = @converted_doi[doc[:doi]] ||= NistPubid::Document.parse(doc[:doi]) rescue Errors::ParseError return id end # return more complete pubid id.merge(doi) rescue Errors::ParseError @converted_doi[doc[:doi]] ||= NistPubid::Document.parse(doc[:doi]) end
different_with_pubid()
click to toggle source
# File lib/nist_pubid/nist_tech_pubs.rb, line 65 def different_with_pubid fetch.reject do |doc| convert(doc).to_s == doc[:id] rescue Errors::ParseError true end end
fetch()
click to toggle source
# File lib/nist_pubid/nist_tech_pubs.rb, line 15 def fetch @documents ||= Nokogiri::XML(URI.open(URL)) .xpath("/body/query/doi_record/report-paper/report-paper_metadata") .map { |doc| parse_docid doc } rescue StandardError => e warn e.message [] end
parse_docid(doc)
click to toggle source
# File lib/nist_pubid/nist_tech_pubs.rb, line 40 def parse_docid(doc) id = doc.at("publisher_item/item_number", "publisher_item/identifier") .text.sub(%r{^/}, "") doi = doc.at("doi_data/doi").text.gsub("10.6028/", "") 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, title: title } end
parse_fail_with_pubid()
click to toggle source
# File lib/nist_pubid/nist_tech_pubs.rb, line 73 def parse_fail_with_pubid fetch.select do |doc| convert(doc).to_s && false rescue Errors::ParseError true end end
status()
click to toggle source
returning current document id, doi, title and final PubID
# File lib/nist_pubid/nist_tech_pubs.rb, line 82 def status fetch.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 Errors::ParseError { id: doc[:id], doi: doc[:doi], title: doc[:title], finalPubId: "parse error", mr: "parse_error" } end end