Sha256: f141202c2df5f2752811dbe06cdadb535193f1649b1d4384405e59a19a7be030

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 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/data/"

    # @param text [String]
    # @return [RelatonBib::BibliographicItem]
    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

    # @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 = {})
      warn "[relaton-iana] (\"#{ref}\") fetching..."
      result = search(ref)
      return unless result

      warn "[relaton-iana] (\"#{ref}\") found #{result.docidentifier[0].id}"
      result
    end

    extend IanaBibliography
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
relaton-iana-1.12.0 lib/relaton_iana/iana_bibliography.rb
relaton-iana-1.11.0 lib/relaton_iana/iana_bibliography.rb
relaton-iana-1.10.3 lib/relaton_iana/iana_bibliography.rb
relaton-iana-1.10.2 lib/relaton_iana/iana_bibliography.rb
relaton-iana-1.10.1 lib/relaton_iana/iana_bibliography.rb
relaton-iana-1.10.0 lib/relaton_iana/iana_bibliography.rb
relaton-iana-1.9.2 lib/relaton_iana/iana_bibliography.rb