Sha256: 6af21146b9f7a72c330f6fb1552a3c8c017ccb075ba0b96878a9e4a4256c4b4f
Contents?: true
Size: 1008 Bytes
Versions: 11
Compression:
Stored size: 1008 Bytes
Contents
require "faraday" require "relaton_ogc/hit" require "fileutils" module RelatonOgc class HitCollection < RelatonBib::HitCollection ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-ogc/main/".freeze INDEX_FILE = "index-v1.yaml".freeze # @param code [Strig] # @param year [String] # @param opts [Hash] def initialize(code, year = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength super @array = [] return if code.nil? || code.empty? index = Relaton::Index.find_or_create :ogc, url: "#{ENDPOINT}index-v1.zip", file: INDEX_FILE row = index.search(code).min_by { |r| r[:id] } return unless row url = "#{ENDPOINT}#{row[:file]}" resp = Faraday.get(url) { |req| req.options.timeout = 10 } return unless resp.status == 200 hash = YAML.safe_load(resp.body) hash["fetched"] = Date.today.to_s bib = OgcBibliographicItem.from_hash hash @array = [Hit.new(bib, self)] end end end
Version data entries
11 entries across 11 versions & 1 rubygems