Sha256: cdf97f7ea1a18d65e023c13b95136fb19d105e7a5d24d68f9f150a7a6687918c

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module Relaton
  module Plateau
    module Bibliography
      extend self

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

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

      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

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
relaton-plateau-1.20.0 lib/relaton/plateau/bibliography.rb
relaton-plateau-1.19.5 lib/relaton/plateau/bibliography.rb