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

#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
33
34
35
36
# File 'lib/relaton/plateau/bibliography.rb', line 26

def search(code)
  all_editions = code.match?(/ #\d+$/)
  rows = index.search do |r|
    id = all_editions ? r[:id].sub(/ \d+\.\d+$/, "") : r[:id]
    id ==  code
  end
  return unless rows.any?

  hits = rows.map { |r| Hit.new(**r) }
  all_editions ? hits[0].bibitem.to_all_editions(hits) : hits[0].bibitem
end