Class: Relaton::Ieee::Bibliography
- Inherits:
-
Object
- Object
- Relaton::Ieee::Bibliography
- Defined in:
- lib/relaton/ieee/bibliography.rb
Constant Summary collapse
- GH_URL =
"https://raw.githubusercontent.com/relaton/relaton-data-ieee/refs/heads/data-v2/".freeze
Class Method Summary collapse
-
.get(code, _year = nil, _opts = {}) ⇒ Relaton::Ieee::ItemData?
Get IEEE bibliography item by reference.
-
.search(code) ⇒ Relaton::Ieee::ItemData?
Search IEEE bibliography item by reference.
Class Method Details
.get(code, _year = nil, _opts = {}) ⇒ Relaton::Ieee::ItemData?
Get IEEE bibliography item by reference.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/relaton/ieee/bibliography.rb', line 37 def get(code, _year = nil, _opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength Util.info "Fetching from Relaton repository ...", key: code item = search(code) if item Util.info "Found: `#{item.docidentifier.first.content}`", key: code item else Util.info "Not found.", key: code nil end end |
.search(code) ⇒ Relaton::Ieee::ItemData?
Search IEEE bibliography item by reference.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/relaton/ieee/bibliography.rb', line 14 def search(code) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength # ref = code.sub(/Std\s/i, "") # .gsub(/[\s,:\/]/, "_").squeeze("_").upcase index = Relaton::Index.find_or_create :ieee, url: "#{GH_URL}#{INDEXFILE}.zip", file: "#{INDEXFILE}.yaml" row = index.search(code).min_by { |r| r[:id] } return unless row resp = Faraday.get "#{GH_URL}#{row[:file]}" return unless resp.status == 200 Item.from_yaml(resp.body).tap { |item| item.fetched = Date.today.to_s } rescue Faraday::ConnectionFailed raise Relaton::RequestError, "Could not access #{GH_URL}" end |