module RelatonIana::IanaBibliography
Methods for search IANA standards.
Constants
- SOURCE
Public Instance Methods
get(ref, _year = nil, _opts = {})
click to toggle source
@param ref [String] the W3C standard Code to look up @param year [String, NilClass] not used @param opts [Hash] options @return [RelatonBib::BibliographicItem]
# File lib/relaton_iana/iana_bibliography.rb, line 26 def get(ref, _year = nil, _opts = {}) warn "[relaton-iana] (\"#{ref}\") fetching..." result = search(ref) return unless result warn "[relaton-iana] (\"#{ref}\") found #{result.docidentifier[0].id}" result end
search(text)
click to toggle source
@param text [String] @return [RelatonBib::BibliographicItem]
# File lib/relaton_iana/iana_bibliography.rb, line 10 def search(text) # rubocop:disable Metrics/MethodLength file = text.sub(/^IANA\s/, "").gsub(/[\s,:\/]/, "_") url = "#{SOURCE}#{file}.yaml" resp = Net::HTTP.get_response URI(url) hash = YAML.safe_load resp.body RelatonBib::BibliographicItem.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