Sha256: c595d4f7846dd90249da69ce6122d28c30b812247e9afc92b54a8591c18cd81a

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

Contents

module RelatonCcsds
  class HitCollection < RelatonBib::HitCollection
    GHURL = "https://raw.githubusercontent.com/relaton/relaton-data-ccsds/main/".freeze
    INDEX_FILE = "index-v2.yaml".freeze

    #
    # Search his in index.
    #
    # @return [<Type>] <description>
    #
    def fetch
      pubid = Pubid::Ccsds::Identifier.parse(text)
      rows = if pubid.edition
               index.search(pubid)
               # index.search { |r| Pubid::Ccsds::Identifier.create(**r[:id]) == pubid }
             else
               index.search { |r| r[:id].exclude(:edition) == pubid }
             end
      @array = rows.map { |row| Hit.new code: row[:id], url: "#{GHURL}#{row[:file]}" }
      self
    rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError, Errno::ECONNRESET => e
      raise RelatonBib::RequestError, e.message
    end

    def index
      @index ||= Relaton::Index.find_or_create :ccsds, url: "#{GHURL}index-v2.zip", file: INDEX_FILE, pubid_class: Pubid::Ccsds::Identifier
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
relaton-ccsds-1.20.1 lib/relaton_ccsds/hit_collection.rb