Class: RelatonBib::DocumentRelation
- 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 instance 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 complements complementOf obsoletes obsoletedBy cites isCitedIn ].freeze
Constants included from RelatonBib
Instance Attribute Summary collapse
- #bibitem ⇒ RelatonBib::BibliographicItem readonly
- #description ⇒ RelatonBib::FormattedString, NilClass readonly
- #locality ⇒ Array<RelatonBib::Locality, RelatonBib::LocalityStack> readonly
- #source_locality ⇒ Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack> readonly
- #type ⇒ String readonly
Instance Method Summary collapse
-
#initialize(type:, description: nil, bibitem:, locality: [], source_locality: []) ⇒ DocumentRelation
constructor
A new instance of DocumentRelation.
- #to_asciibib(prefix = "") ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder, **opts) ⇒ Object
Methods included from RelatonBib
Constructor Details
#initialize(type:, description: nil, bibitem:, locality: [], source_locality: []) ⇒ DocumentRelation
Returns a new instance of DocumentRelation.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/relaton_bib/document_relation.rb', line 45 def initialize(type:, description: nil, bibitem:, locality: [], source_locality: []) type = "obsoletes" if type == "Now withdrawn" unless self.class::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
#bibitem ⇒ RelatonBib::BibliographicItem (readonly)
29 30 31 |
# File 'lib/relaton_bib/document_relation.rb', line 29 def bibitem @bibitem end |
#description ⇒ RelatonBib::FormattedString, NilClass (readonly)
23 24 25 |
# File 'lib/relaton_bib/document_relation.rb', line 23 def description @description end |
#locality ⇒ Array<RelatonBib::Locality, RelatonBib::LocalityStack> (readonly)
32 33 34 |
# File 'lib/relaton_bib/document_relation.rb', line 32 def locality @locality end |
#source_locality ⇒ Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack> (readonly)
36 37 38 |
# File 'lib/relaton_bib/document_relation.rb', line 36 def source_locality @source_locality end |
#type ⇒ String (readonly)
20 21 22 |
# File 'lib/relaton_bib/document_relation.rb', line 20 def type @type end |
Instance Method Details
#to_asciibib(prefix = "") ⇒ 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_hash ⇒ 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 } 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
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 |