Sha256: d1fb5d9914fb192ff7ee6f1981f936ae2a6950f3ec845ea219ac95654a9e6cda

Contents?: true

Size: 961 Bytes

Versions: 3

Compression:

Stored size: 961 Bytes

Contents

require_relative "databases/bibtex"
require_relative "errors"

module AsciidoctorBibliography
  # This is an array of citeproc entries.
  class Database < Array
    def initialize(*filepaths)
      filepaths.each do |filepath|
        append filepath
      end
    end

    def append(filepath)
      concat Database.load(filepath)
    end

    def find_entry_by_id(id)
      result = detect { |entry| entry["id"] == id }
      if result.nil?
        message = "No entry with id '#{id}' was found in the bibliographic database."
        raise Errors::Database::IdNotFound, message
      end
      result
    end

    def self.load(filepath)
      raise Errors::Database::FileNotFound, filepath unless File.exist?(filepath)

      fileext = File.extname filepath
      case fileext
      when *Databases::BibTeX::EXTENSIONS
        Databases::BibTeX.load filepath
      else
        raise Errors::Database::UnsupportedFormat, fileext
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
asciidoctor-bibliography-0.5.0 lib/asciidoctor-bibliography/database.rb
asciidoctor-bibliography-0.5.1 lib/asciidoctor-bibliography/database.rb
asciidoctor-bibliography-0.4.4 lib/asciidoctor-bibliography/database.rb