Sha256: 478e4a2e057600f9e146b4170905f74bceb37294c172428aeebc6a28a544d146
Contents?: true
Size: 1.7 KB
Versions: 5
Compression:
Stored size: 1.7 KB
Contents
require "net/http" module RelatonBipm class BipmBibliography ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-bipm/master/data/" .freeze class << self # @param text [String] # @return [RelatonBipm::BipmBibliographicItem] def search(text, _year = nil, _opts = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize warn "[relaton-bipm] (\"#{text}\") fetching..." ref = text.sub(/^BIPM\s/, "").downcase # .sub /^([[:alpha:]]+)(\d+)/, '\1-\2' uri = URI("#{ENDPOINT}#{ref}.yaml") resp = Net::HTTP.get_response uri return unless resp.code == "200" hash = HashConverter.hash_to_bib YAML.safe_load(resp.body, [Date]) item = BipmBibliographicItem.new hash warn "[relaton-bipm] (\"#{text}\") found #{item.docidentifier.first.id}" item rescue SocketError, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Net::ReadTimeout, # OpenSSL::SSL::SSLError, Errno::ETIMEDOUT => e raise RelatonBib::RequestError, "Could not access #{uri}: #{e.message}" end # @param ref [String] the BIPM standard Code to look up (e..g "BIPM B-11") # @param year [String] the year the standard was published (optional) # # @param opts [Hash] options # @option opts [TrueClass, FalseClass] :all_parts restricted to all parts # if all-parts reference is required # @option opts [TrueClass, FalseClass] :bibdata # # @return [RelatonBipm::BipmBibliographicItem] def get(ref, year = nil, opts = {}) search(ref, year, opts) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems