Sha256: 528617f0b39af3ec73c15d9a3652b893d608671e12781f80dcc10446ea5b406f

Contents?: true

Size: 927 Bytes

Versions: 5

Compression:

Stored size: 927 Bytes

Contents

require "asciidoctor/attribute_list"

module AsciidoctorBibliography
  class CitationItem
    LOCATORS = CiteProc::CitationItem.labels.map(&:to_s).push("locator").freeze

    attr_accessor :key, :target, :positional_attributes, :named_attributes, :locators

    def initialize
      yield self if block_given?
    end

    def prefix
      named_attributes["prefix"]
    end

    def suffix
      named_attributes["suffix"]
    end

    def locators
      named_attributes.select { |key, _| LOCATORS.include? key }
    end

    def locator
      locators.first
    end

    def parse_attribute_list(string)
      parsed_attributes = ::Asciidoctor::AttributeList.new(string).parse
      self.named_attributes = parsed_attributes.reject { |key, _| key.is_a? Integer }
      self.positional_attributes = parsed_attributes.select { |key, _| key.is_a? Integer }.values
      self.key = positional_attributes.shift
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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