Class: RelatonBib::DocumentRelation
- 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
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_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.
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
#bibitem ⇒ RelatonBib::BibliographicItem (readonly)
24 25 26 |
# File 'lib/relaton_bib/document_relation.rb', line 24 def bibitem @bibitem end |
#description ⇒ RelatonBib::FormattedString, NilClass (readonly)
18 19 20 |
# File 'lib/relaton_bib/document_relation.rb', line 18 def description @description end |
#locality ⇒ Array<RelatonBib::Locality, RelatonBib::LocalityStack> (readonly)
27 28 29 |
# File 'lib/relaton_bib/document_relation.rb', line 27 def locality @locality end |
#source_locality ⇒ Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack> (readonly)
30 31 32 |
# File 'lib/relaton_bib/document_relation.rb', line 30 def source_locality @source_locality end |
#type ⇒ String (readonly)
15 16 17 |
# File 'lib/relaton_bib/document_relation.rb', line 15 def type @type end |
Instance Method Details
#to_hash ⇒ 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
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 |