Class: Relaton::Ieee::Bibliography

Inherits:
Object
  • Object
show all
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

Class Method Details

.get(code, _year = nil, _opts = {}) ⇒ Relaton::Ieee::ItemData?

Get IEEE bibliography item by reference.

Parameters:

  • code (String)

    the IEEE standard Code to look up (e..g “528-2019”)

  • year (String)

    the year the standard was published (optional)

  • opts (Hash)

    options

Returns:



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.

Parameters:

  • code (String)

Returns:



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