Sha256: e681247add641829f50d7ea9d3b7e8a6d9fe6ced3657be4616700699aad30d49
Contents?: true
Size: 1.78 KB
Versions: 3
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true module Relaton3gpp # Methods for search IANA standards. module Bibliography # SOURCE = "http://xml2rfc.tools.ietf.org/public/rfc/bibxml-3gpp-new/" SOURCE = "https://raw.githubusercontent.com/relaton/relaton-data-3gpp/main/" INDEX_FILE = "index-v1.yaml" # @param text [String] # @return [RelatonBib::BibliographicItem] def search(text) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize index = Relaton::Index.find_or_create "3GPP", url: "#{SOURCE}index-v1.zip", file: INDEX_FILE row = index.search(text.sub(/^3GPP\s/, "")).min_by { |r| r[:id] } return unless row # file = text.sub(/^3GPP\s/, "").gsub(/[\s,:\/]/, "_").squeeze("_").upcase url = "#{SOURCE}#{row[:file]}" resp = Net::HTTP.get_response URI(url) return unless resp.code == "200" hash = YAML.safe_load resp.body bib_hash = Relaton3gpp::HashConverter.hash_to_bib(hash) bib_hash[:fetched] = Date.today.to_s Relaton3gpp::BibliographicItem.new(**bib_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 [RelatonBib::BibliographicItem] 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 Bibliography end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
relaton-3gpp-1.18.0 | lib/relaton_3gpp/bibliography.rb |
relaton-3gpp-1.17.0 | lib/relaton_3gpp/bibliography.rb |
relaton-3gpp-1.16.3 | lib/relaton_3gpp/bibliography.rb |