Sha256: 64630b78e69529201ba065277b9dff36651d00d363784a59f7e5e48831ea42e3
Contents?: true
Size: 1013 Bytes
Versions: 2
Compression:
Stored size: 1013 Bytes
Contents
module AsciidoctorBibliography class Bibliographer attr_accessor :citations attr_accessor :indices attr_accessor :database attr_reader :occurring_keys attr_accessor :options def initialize @options = {} @citations = [] @indices = [] @database = nil @occurring_keys = [] end def add_citation(citation) citations << citation @occurring_keys.concat(citation.citation_items.map(&:key)).uniq! end def appearance_index_of(id) @occurring_keys.index(id) + 1 end def sort if options['order'] == 'alphabetical' @occurring_keys = @occurring_keys.sort_by do |target| first_author_family_name(target) end end end private def first_author_family_name(key) authors = database.find { |h| h['id'] == key }['author'] return '' if authors.nil? authors.map { |h| h['family'] }.compact.first # TODO: is the first also alphabetically the first? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
asciidoctor-bibliography-0.2.1 | lib/asciidoctor-bibliography/bibliographer.rb |
asciidoctor-bibliography-0.2.0 | lib/asciidoctor-bibliography/bibliographer.rb |