Module: Relaton3gpp::Bibliography
Overview
Methods for search IANA standards.
Constant Summary collapse
- SOURCE =
"https://raw.githubusercontent.com/relaton/relaton-data-3gpp/main/"
- INDEX_FILE =
"index-v1.yaml"
Instance Method Summary collapse
- #get(ref, _year = nil, _opts = {}) ⇒ RelatonBib::BibliographicItem
- #search(text) ⇒ RelatonBib::BibliographicItem
Instance Method Details
#get(ref, _year = nil, _opts = {}) ⇒ RelatonBib::BibliographicItem
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/relaton_3gpp/bibliography.rb', line 36 def get(ref, _year = nil, _opts = {}) Util.info "Fetching from Relaton repository ...", key: ref result = search(ref) unless result Util.info "Not found.", key: ref return end Util.info "Found: `#{result.docidentifier[0].id}`", key: ref result end |
#search(text) ⇒ RelatonBib::BibliographicItem
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/relaton_3gpp/bibliography.rb', line 12 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. end |