Sha256: 456ec125db440c6fed5416e068effaba98589a614ca37e59d91dbc123866605e

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require "net/http"

module RelatonW3c
  # Class methods for search W3C standards.
  class W3cBibliography
    class << self
      # @param text [String]
      # @return [RelatonW3c::HitCollection]
      def search(text)
        HitCollection.new text
      rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
             EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
             Net::ProtocolError, Errno::ETIMEDOUT
        raise RelatonBib::RequestError,
              "Could not access #{HitCollection::DOMAIN}"
      end

      # @param ref [String] the W3C standard Code to look up
      # @param year [String, NilClass] not used
      # @param opts [Hash] options
      # @return [RelatonW3c::W3cBibliographicItem]
      def get(ref, _year = nil, _opts = {})
        warn "[relaton-w3c] (\"#{ref}\") fetching..."
        result = search(ref)
        return unless result.any?

        ret = result.first.fetch
        warn "[relaton-w3c] (\"#{ref}\") found #{ret.title.first.title.content}"
        ret
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
relaton-w3c-1.9.2 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.9.1 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.9.0 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.8.0 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.7.2 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.7.1 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.7.0 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.6.0 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.6.pre1 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.5.0 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.5.pre lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.4.0 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.3.3 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.3.2 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.3.1 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.3.0 lib/relaton_w3c/w3c_bibliography.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/relaton-w3c-1.2.0/lib/relaton_w3c/w3c_bibliography.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/relaton-w3c-1.2.0/lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.2.0 lib/relaton_w3c/w3c_bibliography.rb
relaton-w3c-1.1.0 lib/relaton_w3c/w3c_bibliography.rb