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[
  includes includedIn hasPart partOf merges mergedInto splits splitInto
  instanceOf hasInstance exemplarOf hasExemplar manifestationOf
  hasManifestation reproductionOf hasReproduction reprintOf hasReprint
  expressionOf hasExpression translatedFrom hasTranslation arrangementOf
  hasArrangement abridgementOf hasAbridgement annotationOf hasAnnotation
  draftOf hasDraft editionOf hasEdition updates updatedBy derivedFrom
  derives describes describedBy catalogues cataloguedBy hasSuccessor
  successorOf adaptedFrom hasAdaptation adoptedFrom adoptedAs reviewOf
  hasReview commentaryOf hasCommentary related hasComplement complementOf
  obsoletes obsoletedBy cites isCitedIn
].freeze

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

array, format_date, grammar_hash, parse_date, parse_yaml

Methods included from Config

#configuration, #configure

Constructor Details

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

Returns a new instance of DocumentRelation.

Parameters:



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/relaton_bib/document_relation.rb', line 45

def initialize(type:, bibitem:, description: nil, locality: [],
               source_locality: [])
  type = "obsoletes" if type == "Now withdrawn"
  unless self.class::TYPES.include? type
    Util.warn "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)



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

def bibitem
  @bibitem
end

#descriptionRelatonBib::FormattedString? (readonly)

Returns:



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

def description
  @description
end

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



32
33
34
# File 'lib/relaton_bib/document_relation.rb', line 32

def locality
  @locality
end

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



36
37
38
# File 'lib/relaton_bib/document_relation.rb', line 36

def source_locality
  @source_locality
end

#typeString

Returns:

  • (String)


20
21
22
# File 'lib/relaton_bib/document_relation.rb', line 20

def type
  @type
end

Instance Method Details

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


86
87
88
89
90
91
92
# File 'lib/relaton_bib/document_relation.rb', line 86

def to_asciibib(prefix = "")
  pref = prefix.empty? ? prefix : prefix + "."
  out = "#{prefix}.type:: #{type}\n"
  out += description.to_asciibib "#{pref}desctiption" if description
  out += bibitem.to_asciibib "#{pref}bibitem" if bibitem
  out
end

#to_hashHash

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
82
# File 'lib/relaton_bib/document_relation.rb', line 74

def to_hash # rubocop:disable Metrics/AbcSize
  hash = { "type" => type, "bibitem" => bibitem.to_hash(embedded: true) }
  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)


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

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(**opts.merge(builder: builder, embedded: true))
    locality.each { |l| l.to_xml builder }
    source_locality.each { |l| l.to_xml builder }
  end
end