Sha256: ca8ecaa71c9e3e3d0a1b6c7974812bdef4050b156c8013d76ff10874424bca94

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

module RelatonIeee
  class IeeeBibliography
    class << self
      GH_URL = "https://raw.githubusercontent.com/relaton/relaton-data-ieee/main/data/".freeze

      #
      # Search IEEE bibliography item by reference.
      #
      # @param code [String]
      #
      # @return [RelatonIeee::HitCollection]
      #
      def search(code)
        ref = code.sub(/Std\s/i, "").gsub(/[\s,:\/]/, "_").squeeze("_").upcase
        url = "#{GH_URL}#{ref}.yaml"
        resp = Faraday.get url
        return unless resp.status == 200

        IeeeBibliographicItem.from_hash YAML.safe_load resp.body
      rescue Faraday::ConnectionFailed
        raise RelatonBib::RequestError, "Could not access #{GH_URL}"
      end

      #
      # Get IEEE bibliography item by reference.
      #
      # @param code [String] the IEEE standard Code to look up (e..g "528-2019")
      # @param year [String] the year the standard was published (optional)
      # @param opts [Hash] options
      #
      # @return [Hash, NilClass] returns { ret: RelatonBib::BibliographicItem }
      #   if document is found else returns NilClass
      #
      def get(code, _year = nil, _opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
        warn "[relaton-ieee] (\"#{code}\") fetching..."
        item = search(code)
        if item
          warn "[relaton-ieee] (\"#{code}\") found #{item.docidentifier.first.id}"
          item
        else
          warn "[relaton-ieee] (\"#{code}\") not found"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relaton-ieee-1.13.1 lib/relaton_ieee/ieee_bibliography.rb
relaton-ieee-1.13.0 lib/relaton_ieee/ieee_bibliography.rb
relaton-ieee-1.12.8 lib/relaton_ieee/ieee_bibliography.rb