Sha256: 546eae0471f73e0452d11667512fe0a49890e5c21af2f70fd6db2b36c1044328
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true module RelatonOasis # Class methods for search Cenelec standards. class OasisBibliography ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-oasis/main/" INDEX_FILE = "index-v1.yaml" class << self # @param text [String] # @return [RelatonOasis::HitCollection] def search(text, _year = nil) /^(?:OASIS\s)?(?<code>.+)/ =~ text index = Relaton::Index.find_or_create :oasis, url: "#{ENDPOINT}index-v1.zip", file: INDEX_FILE row = index.search(code).min_by { |i| i[:id] } return unless row agent = Mechanize.new resp = agent.get "#{ENDPOINT}#{row[:file]}" return unless resp.code == "200" hash = YAML.safe_load resp.body hash["fetched"] = Date.today.to_s OasisBibliographicItem.from_hash hash rescue Mechanize::ResponseCodeError, OpenURI::HTTPError => e return if e.response_code == "404" raise RelatonBib::RequestError, e.message end # @param code [String] the CEN standard Code to look up # @param year [String] the year the standard was published (optional) # @param opts [Hash] options; restricted to :all_parts if all-parts # reference is required # @return [RelatonOasis::OasisBibliographicItem, nil] def get(code, year = nil, _opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity warn "[relaton-oasis] (#{code}) fetching..." bibitem = search code, year if bibitem docid = bibitem.docidentifier.detect(&:primary).id warn "[relaton-oasis] (#{code}) found #{docid}" bibitem else warn "[relaton-oasis] (#{code}) not found" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
relaton-oasis-1.16.0 | lib/relaton_oasis/oasis_bibliography.rb |