Class: Relaton::Ccsds::HitCollection

Inherits:
Relaton::Core::HitCollection
  • Object
show all
Defined in:
lib/relaton/ccsds/hit_collection.rb

Constant Summary collapse

GHURL =
"https://raw.githubusercontent.com/relaton/relaton-data-ccsds/refs/heads/v2/".freeze

Instance Method Summary collapse

Instance Method Details

#fetch<Type>

Search his in index.

Returns:

  • (<Type>)

    <description>



13
14
15
16
17
18
# File 'lib/relaton/ccsds/hit_collection.rb', line 13

def fetch
  @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 Relaton::RequestError, e.message
end

#indexObject

Pubid index (index-v2): ‘:id` deserializes to a Pubid::Ccsds::Identifier via pubid_class, so search narrows by number with binary search.



22
23
24
25
26
# File 'lib/relaton/ccsds/hit_collection.rb', line 22

def index
  @index ||= Relaton::Index.find_or_create(
    :ccsds, url: "#{GHURL}#{INDEXFILE}.zip", file: "#{INDEXFILE}.yaml", pubid_class: Pubid::Ccsds::Identifier
  )
end

#pubidObject



28
29
30
# File 'lib/relaton/ccsds/hit_collection.rb', line 28

def pubid
  @pubid ||= Pubid::Ccsds::Identifier.parse(ref)
end

#rowsObject



32
33
34
35
36
37
38
39
# File 'lib/relaton/ccsds/hit_collection.rb', line 32

def rows
  if pubid.edition
    index.search(pubid)
  else
    # search(pubid) narrows candidates by number via binary search first.
    index.search(pubid) { |r| r[:id].exclude(:edition) == pubid }
  end
end