Sha256: 9fd5afd2de23bd058354aacbd036cdb91a46bb7c36c207a9bc4d4174cbcc0317
Contents?: true
Size: 1.69 KB
Versions: 2
Compression:
Stored size: 1.69 KB
Contents
# frozen_string_literal: true module RelatonIana # Methods for search IANA standards. module IanaBibliography SOURCE = "https://raw.githubusercontent.com/relaton/relaton-data-iana/main/" INDEX_FILE = "index-v1.yaml" # @param text [String] # @return [RelatonIana::IanaBibliographicItem] def search(text) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize # file = text.sub(/^IANA\s/, "").gsub(/[\s,:\/]/, "_").downcase # url = "#{SOURCE}#{file}.yaml" index = Relaton::Index.find_or_create :IANA, url: "#{SOURCE}index-v1.zip", file: INDEX_FILE id = text.sub(/^IANA\s/, "") row = index.search(id).min_by { |i| i[:id] } return unless row url = "#{SOURCE}#{row[:file]}" resp = Net::HTTP.get_response URI(url) return unless resp.code == "200" hash = YAML.safe_load resp.body hash["fetched"] = Date.today.to_s IanaBibliographicItem.from_hash hash rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ETIMEDOUT => e raise RelatonBib::RequestError, e.message end # @param ref [String] the W3C standard Code to look up # @param year [String, NilClass] not used # @param opts [Hash] options # @return [RelatonIana::IanaBibliographicItem] def get(ref, _year = nil, _opts = {}) Util.warn "(#{ref}) Fetching from Relaton repository ..." result = search(ref) unless result Util.warn "(#{ref}) Not found." return end Util.warn "(#{ref}) Found: `#{result.docidentifier[0].id}`" result end extend IanaBibliography end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
relaton-iana-1.18.0 | lib/relaton_iana/iana_bibliography.rb |
relaton-iana-1.17.0 | lib/relaton_iana/iana_bibliography.rb |