Class: Relaton::W3c::Bibliography
- Inherits:
-
Object
- Object
- Relaton::W3c::Bibliography
- Defined in:
- lib/relaton/w3c/bibliography.rb
Overview
Class methods for search W3C standards.
Constant Summary collapse
- SOURCE =
"https://raw.githubusercontent.com/relaton/relaton-data-w3c/data-v2/"
Class Method Summary collapse
Class Method Details
.get(ref, _year = nil, _opts = {}) ⇒ Relaton::W3c::ItemData
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/relaton/w3c/bibliography.rb', line 39 def get(ref, _year = nil, _opts = {}) Util.info "Fetching from Relaton repository ...", key: ref result = search(ref) unless result Util.info "Not found.", key: ref return end found = result.docidentifier.first.content Util.info "Found: `#{found}`", key: ref result end |
.search(text) ⇒ Relaton::W3c::ItemData
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/relaton/w3c/bibliography.rb', line 16 def search(text) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize pubid = PubId.parse text.sub(/^W3C\s/, "") index = Relaton::Index.find_or_create( :W3C, url: "#{SOURCE}#{INDEXFILE}.zip", file: "#{INDEXFILE}.yaml", id_keys: PubId::PARTS, ) row = index.search { |r| pubid == r[:id] }.sort_by { |r| (r[:id][:date] || r[:id][:year]).to_i }.last return unless row url = "#{SOURCE}#{row[:file]}" resp = Net::HTTP.get_response(URI.parse(url)) return unless resp.code == "200" Item.from_yaml(resp.body).tap { |i| i.fetched = Date.today.to_s } rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ETIMEDOUT => e raise Relaton::RequestError, "Could not access #{url}: #{e.}" end |