Class: Relaton::Ogc::HitCollection

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

Constant Summary collapse

ENDPOINT =
"https://raw.githubusercontent.com/relaton/relaton-data-ogc/data-v2/".freeze

Instance Method Summary collapse

Instance Method Details

#findself

Returns:

  • (self)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/relaton/ogc/hit_collection.rb', line 10

def find
  return self if ref.nil? || ref.empty?

  row = index.search(ref).min_by { |r| r[:id] }
  return self unless row

  url = "#{ENDPOINT}#{row[:file]}"
  resp = Faraday.get(url) { |req| req.options.timeout = 10 }
  return self unless resp.status == 200

  item = Item.from_yaml resp.body
  item.fetched = Date.today.to_s
  hit = Hit.new({ code: item.docidentifier[0]&.content, file: row[:file] }, self)
  hit.instance_variable_set(:@item, item)
  @array = [hit]
  self
end

#indexRelaton::Index

Returns:

  • (Relaton::Index)


29
30
31
32
33
# File 'lib/relaton/ogc/hit_collection.rb', line 29

def index
  @index ||= Relaton::Index.find_or_create(
    :ogc, url: "#{ENDPOINT}index-v1.zip", file: "#{INDEXFILE}.yaml",
  )
end