Sha256: 431c2dd395e20827a6d412323c4d56fe40993009e9f13b1e668ff56861aedf9c

Contents?: true

Size: 854 Bytes

Versions: 5

Compression:

Stored size: 854 Bytes

Contents

module RelatonBib
  class Extent
    attr_accessor :locality

    #
    # @param [Array<RelatonBib::Locality, RelatonBib::LocalityStack>] locality
    #
    def initialize(locality)
      @locality = locality
    end

    def to_xml(builder)
      builder.extent do |b|
        locality.each { |l| l.to_xml(b) }
      end
    end

    def to_hash
      hash = Hash.new { |h, k| h[k] = [] }
      locality.each_with_object(hash) do |l, obj|
        k, v = l.to_hash.first
        obj[k] << v
      end
    end

    def to_asciibib(prefix = "", count = 1)
      pref = prefix.empty? ? "extent" : "#{prefix}.extent"
      out = count > 1 ? "#{pref}::\n" : ""
      locality.each do |l|
        out += l.to_asciibib(pref, locality.size)
      end
      out
    end

    def to_bibtex(item)
      locality.map { |l| l.to_bibtex(item) }.join
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
relaton-bib-1.20.4 lib/relaton_bib/extent.rb
relaton-bib-1.20.3 lib/relaton_bib/extent.rb
relaton-bib-1.20.2 lib/relaton_bib/extent.rb
relaton-bib-1.20.1 lib/relaton_bib/extent.rb
relaton-bib-1.20.0 lib/relaton_bib/extent.rb