Sha256: a65307b46eba288809b250d383e2337b66affc3181829b9ec509c3c758e9692e

Contents?: true

Size: 1.52 KB

Versions: 15

Compression:

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

    # @param text [String]
    # @return [RelatonBib::BibliographicItem]
    def search(text) # rubocop:disable Metrics/MethodLength
      file = text.sub(/^3GPP\s/, "").gsub(/[\s,:\/]/, "_").squeeze("_").upcase
      url = "#{SOURCE}#{file}.yaml"
      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)
      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 = {})
      warn "[relaton-3gpp] (\"#{ref}\") fetching..."
      result = search(ref)
      unless result
        warn "[relaton-3gpp] (\"#{ref}\") not found"
        return
      end

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

    extend Bibliography
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
relaton-3gpp-1.13.0 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.12.0 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.11.1 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.11.0 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.10.5 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.10.4 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.10.3 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.10.2 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.10.1 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.10.0 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.9.4 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.9.3 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.9.2 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.9.1 lib/relaton_3gpp/bibliography.rb
relaton-3gpp-1.9.0 lib/relaton_3gpp/bibliography.rb