Sha256: 74acbeebc1f6a652a8098f0cb717e9b0de5ca95c6411b1add421a33df2034b00

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

module RelatonBib
  # module DocumentRelationType
  #   PARENT        = 'parent'
  #   CHILD         = 'child'
  #   OBSOLETES     = 'obsoletes'
  #   UPDATES       = 'updates'
  #   COMPLEMENTS   = 'complements'
  #   DERIVED_FORM  = 'derivedForm'
  #   ADOPTED_FORM  = 'adoptedForm'
  #   EQUIVALENT    = 'equivalent'
  #   IDENTICAL     = 'identical'
  #   NONEQUIVALENT = 'nonequivalent'
  # end

  # Documett relation
  class DocumentRelation
    include RelatonBib

    # @return [String]
    attr_reader :type

    # @return [String]
    # attr_reader :identifier, :url

    # @return [RelatonBib::BibliographicItem]
    attr_reader :bibitem

    # @return [Array<RelatonBib::BibItemLocality>]
    attr_reader :bib_locality

    # @param type [String]
    # @param bibitem [RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem]
    # @param bib_locality [Array<RelatonBib::BibItemLocality>]
    def initialize(type:, bibitem:, bib_locality: [])
      type = "obsoletes" if type == "Now withdrawn"
      @type         = type
      @bib_locality = bib_locality
      @bibitem      = bibitem
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder, **opts)
      opts.delete :bibdata
      opts.delete :note
      builder.relation(type: type) do
        bibitem.to_xml(builder, **opts.merge(embedded: true))
        bib_locality.each do |l|
          l.to_xml builder
        end
      end
    end

    # @return [Hash]
    def to_hash
      hash = { "type" => type, "bibitem" => bibitem.to_hash }
      hash["bib_locality"] = single_element_array(bib_locality) if bib_locality&.any?
      hash
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
relaton-bib-0.3.12 lib/relaton_bib/document_relation.rb
relaton-bib-0.3.11 lib/relaton_bib/document_relation.rb
relaton-bib-0.3.10 lib/relaton_bib/document_relation.rb
relaton-bib-0.3.9 lib/relaton_bib/document_relation.rb
relaton-bib-0.3.8 lib/relaton_bib/document_relation.rb
relaton-bib-0.3.7 lib/relaton_bib/document_relation.rb
relaton-bib-0.3.6 lib/relaton_bib/document_relation.rb
relaton-bib-0.3.5 lib/relaton_bib/document_relation.rb