Module: Relaton::Plateau::Bibliography
Constant Summary collapse
- INDEXFILE =
"index-v1"- GHURL =
"https://raw.githubusercontent.com/relaton/relaton-data-plateau/main/"
Instance Method Summary collapse
- #fetch_doc(code, id:, file:) ⇒ Object
- #get(code, year = nil, opts = {}) ⇒ Object
- #index ⇒ Object
- #search(code) ⇒ Object
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. end |
#index ⇒ Object
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 { |r| r[:id] == code } return unless rows.any? row = rows.sort_by { |r| r[:id] }.last fetch_doc code, **row end |