Class: RelatonBib::DocumentRelation
Overview
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:, **args) ⇒ DocumentRelation
Returns a new instance of DocumentRelation.
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/relaton_bib/document_relation.rb', line 46
def initialize(type:, bibitem:, **args)
type = "obsoletes" if type == "Now withdrawn"
unless self.class::TYPES.include? type
Util.warn "Invalid relation type: `#{type}`"
end
@type = type
@description = args[:description]
@locality = args[:locality] || args[:locality_stack] || []
@source_locality = args[:source_locality] || args[:source_locality_stack] || []
@bibitem = bibitem
end
|
Instance Attribute Details
29
30
31
|
# File 'lib/relaton_bib/document_relation.rb', line 29
def bibitem
@bibitem
end
|
23
24
25
|
# File 'lib/relaton_bib/document_relation.rb', line 23
def description
@description
end
|
32
33
34
|
# File 'lib/relaton_bib/document_relation.rb', line 32
def locality
@locality
end
|
36
37
38
|
# File 'lib/relaton_bib/document_relation.rb', line 36
def source_locality
@source_locality
end
|
#type ⇒ String
20
21
22
|
# File 'lib/relaton_bib/document_relation.rb', line 20
def type
@type
end
|
Instance Method Details
#to_asciibib(prefix = "") ⇒ String
87
88
89
90
91
92
93
|
# File 'lib/relaton_bib/document_relation.rb', line 87
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
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/relaton_bib/document_relation.rb', line 71
def to_hash hash = { "type" => type, "bibitem" => bibitem.to_hash(embedded: true) }
hash["description"] = description.to_hash if description
locality.each_with_object(hash) do |l, obj|
k, v = l.to_hash.first
hash[k] ||= []
hash[k] << v
end
if source_locality&.any?
hash["source_locality"] = single_element_array(source_locality)
end
hash
end
|
#to_xml(builder, **opts) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/relaton_bib/document_relation.rb', line 59
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
|