Module: Relaton::Plateau::Bibliography

Extended by:
Bibliography
Included in:
Bibliography
Defined in:
lib/relaton/plateau/bibliography.rb

Constant Summary collapse

INDEXFILE =
"index-v1"
GHURL =
"https://raw.githubusercontent.com/relaton/relaton-data-plateau/main/"

Instance Method Summary collapse

Instance Method Details

#fetch_doc(code, id:, file:) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/relaton/plateau/bibliography.rb', line 34

def fetch_doc(code, id:, file:)
  resp = Net::HTTP.get_response URI("#{GHURL}#{file}")
  return unless resp.is_a? Net::HTTPSuccess

  hash = YAML.load(resp.body)
  args = HashConverter.hash_to_bib hash
  BibItem.new(**args)
end

#get(code, year = nil, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/relaton/plateau/bibliography.rb', line 13

def get(code, year = nil, opts = {})
  Util.info "Fetching ...", key: code
  bib = search(code)
  if bib
    Util.info "Found `#{bib.docidentifier.first.id}`", key: code
    bib
  else
    Util.warn "Not found.", key: code
  end
rescue StandardError => e
  raise RelatonBib::RequestError, e.message
end

#indexObject



9
10
11
# File 'lib/relaton/plateau/bibliography.rb', line 9

def index
  Relaton::Index.find_or_create :plateau, url: "#{GHURL}#{INDEXFILE}.zip", file: "#{INDEXFILE}.yaml"
end

#search(code) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/relaton/plateau/bibliography.rb', line 26

def search(code)
  rows = index.search(code)
  return unless rows.any?

  row = rows.sort_by { |r| r[:id] }.last
  fetch_doc code, **row
end