Class: RelatonBib::DocumentRelation
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/document_relation.rb
Overview
Documett relation
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #bib_locality ⇒ Array<RelatonBib::BibItemLocality> readonly
- #bibitem ⇒ RelatonBib::BibliographicItem readonly
- #type ⇒ String readonly
Instance Method Summary collapse
-
#initialize(type:, bibitem:, bib_locality: []) ⇒ DocumentRelation
constructor
A new instance of DocumentRelation.
- #to_hash ⇒ Hash
- #to_xml(builder, **opts) ⇒ Object
Methods included from RelatonBib
Constructor Details
#initialize(type:, bibitem:, bib_locality: []) ⇒ DocumentRelation
Returns a new instance of DocumentRelation.
34 35 36 37 38 39 |
# File 'lib/relaton_bib/document_relation.rb', line 34 def initialize(type:, bibitem:, bib_locality: []) type = "obsoletes" if type == "Now withdrawn" @type = type @bib_locality = bib_locality @bibitem = bibitem end |
Instance Attribute Details
#bib_locality ⇒ Array<RelatonBib::BibItemLocality> (readonly)
29 30 31 |
# File 'lib/relaton_bib/document_relation.rb', line 29 def bib_locality @bib_locality end |
#bibitem ⇒ RelatonBib::BibliographicItem (readonly)
26 27 28 |
# File 'lib/relaton_bib/document_relation.rb', line 26 def bibitem @bibitem end |
#type ⇒ String (readonly)
20 21 22 |
# File 'lib/relaton_bib/document_relation.rb', line 20 def type @type end |
Instance Method Details
#to_hash ⇒ Hash
54 55 56 57 58 |
# File 'lib/relaton_bib/document_relation.rb', line 54 def to_hash hash = { "type" => type, "bibitem" => bibitem.to_hash } hash["bib_locality"] = single_element_array(bib_locality) if bib_locality&.any? hash end |
#to_xml(builder, **opts) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/relaton_bib/document_relation.rb', line 42 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| builder.locality { l.to_xml builder } end end end |