Class: Relaton::Ogc::HitCollection
- Inherits:
-
Core::HitCollection
- Object
- Core::HitCollection
- Relaton::Ogc::HitCollection
- Defined in:
- lib/relaton/ogc/hit_collection.rb
Constant Summary collapse
- ENDPOINT =
"https://raw.githubusercontent.com/relaton/relaton-data-ogc/v2/".freeze
Instance Attribute Summary
Attributes inherited from Core::HitCollection
Instance Method Summary collapse
Methods inherited from Core::HitCollection
#fetch, #initialize, #inspect, #reduce!, #select, #select!, #to_s, #to_xml
Constructor Details
This class inherits a constructor from Relaton::Core::HitCollection
Instance Method Details
#find ⇒ 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..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 |
#index ⇒ 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 |