Class: RelatonBib::DocumentRelation

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_bib/document_relation.rb

Overview

Documett relation

Constant Summary collapse

TYPES =
%w[
  obsoletes obsoletedBy supersedes supersededBy updates updatedBy
  complements derivedFrom translatedFrom hasTranslation adoptedFrom
  equivalent identical nonequivalent includedIn includes instance
  instanceOf partOf hasPart hasDraft draftOf merges splits amends amendedBy
  corrects correctedBy revises revisedBy describes describedBy
].freeze

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(type:, description: nil, bibitem:, locality: [], source_locality: []) ⇒ DocumentRelation

Returns a new instance of DocumentRelation.

Parameters:



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/relaton_bib/document_relation.rb', line 37

def initialize(type:, description: nil, bibitem:, locality: [], source_locality: [])
  type             = "obsoletes" if type == "Now withdrawn"
  unless TYPES.include? type
    warn "[relaton-bib] WARNING: invalid relation type: #{type}"
  end
  @type            = type
  @description     = description
  @locality        = locality
  @source_locality = source_locality
  @bibitem         = bibitem
end

Instance Attribute Details

#bibitemRelatonBib::BibliographicItem (readonly)



24
25
26
# File 'lib/relaton_bib/document_relation.rb', line 24

def bibitem
  @bibitem
end

#descriptionRelatonBib::FormattedString, NilClass (readonly)

Returns:



18
19
20
# File 'lib/relaton_bib/document_relation.rb', line 18

def description
  @description
end

#localityArray<RelatonBib::Locality, RelatonBib::LocalityStack> (readonly)



27
28
29
# File 'lib/relaton_bib/document_relation.rb', line 27

def locality
  @locality
end

#source_localityArray<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack> (readonly)



30
31
32
# File 'lib/relaton_bib/document_relation.rb', line 30

def source_locality
  @source_locality
end

#typeString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/relaton_bib/document_relation.rb', line 15

def type
  @type
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


62
63
64
65
66
67
68
69
70
# File 'lib/relaton_bib/document_relation.rb', line 62

def to_hash
  hash = { "type" => type, "bibitem" => bibitem.to_hash }
  hash["description"] = description.to_hash if description
  hash["locality"] = single_element_array(locality) if locality&.any?
  if source_locality&.any?
    hash["source_locality"] = single_element_array(source_locality)
  end
  hash
end

#to_xml(builder, **opts) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


50
51
52
53
54
55
56
57
58
59
# File 'lib/relaton_bib/document_relation.rb', line 50

def to_xml(builder, **opts)
  opts.delete :bibdata
  opts.delete :note
  builder.relation(type: type) do
    builder.description { description.to_xml builder } if description
    bibitem.to_xml(builder, **opts.merge(embedded: true))
    locality.each { |l| l.to_xml builder }
    source_locality.each { |l| l.to_xml builder }
  end
end