Sha256: 5f033fa49fa602a87ac579aa4b13479306191eb50b9b368fe3e6084c31b08a7c

Contents?: true

Size: 1004 Bytes

Versions: 5

Compression:

Stored size: 1004 Bytes

Contents

require_relative "databases/bibtex"
require_relative "errors"

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

    def append(filename)
      concat Database.load(filename)
    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(filename)
      filepath = File.expand_path filename
      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

5 entries across 5 versions & 1 rubygems

Version Path
asciidoctor-bibliography-0.4.3 lib/asciidoctor-bibliography/database.rb
asciidoctor-bibliography-0.4.2 lib/asciidoctor-bibliography/database.rb
asciidoctor-bibliography-0.4.1 lib/asciidoctor-bibliography/database.rb
asciidoctor-bibliography-0.4.0 lib/asciidoctor-bibliography/database.rb
asciidoctor-bibliography-0.3.0 lib/asciidoctor-bibliography/database.rb