Module: Relaton::Iana::Bibliography
Overview
Methods for search IANA standards.
Constant Summary collapse
- SOURCE =
"https://raw.githubusercontent.com/relaton/relaton-data-iana/refs/heads/data-v2/"
Instance Method Summary collapse
- #get(ref, _year = nil, _opts = {}) ⇒ Relaton::Iana::ItemData?
- #search(text) ⇒ Relaton::Iana::ItemData?
Instance Method Details
#get(ref, _year = nil, _opts = {}) ⇒ Relaton::Iana::ItemData?
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/relaton/iana/bibliography.rb', line 32 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].content}`", key: ref result end |
#search(text) ⇒ Relaton::Iana::ItemData?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/relaton/iana/bibliography.rb', line 11 def search(text) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize index = Relaton::Index.find_or_create :iana, url: "#{SOURCE}#{INDEXFILE}.zip", file: "#{INDEXFILE}.yaml" 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" Item.from_yaml(resp.body).tap { |item| item.fetched = Date.today.to_s } rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ETIMEDOUT => e raise Relaton::RequestError, e. end |