Class: RelatonBib::CopyrightAssociation
Overview
Constant Summary
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(owner:, from:, to: nil, scope: nil) ⇒ CopyrightAssociation
Returns a new instance of CopyrightAssociation.
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/relaton_bib/copyright_association.rb', line 27
def initialize(owner:, from:, to: nil, scope: nil)
unless owner.any?
raise ArgumentError, "at least one owner should exist."
end
@owner = owner.map do |o|
o.is_a?(Hash) ? ContributionInfo.new(entity: Organization.new(**o)) : o
end
@from = Date.strptime(from.to_s, "%Y") if from.to_s.match?(/\d{4}/)
@to = Date.strptime(to.to_s, "%Y") unless to.to_s.empty?
@scope = scope
end
|
Instance Attribute Details
#from ⇒ Date
7
8
9
|
# File 'lib/relaton_bib/copyright_association.rb', line 7
def from
@from
end
|
16
17
18
|
# File 'lib/relaton_bib/copyright_association.rb', line 16
def owner
@owner
end
|
#scope ⇒ String?
13
14
15
|
# File 'lib/relaton_bib/copyright_association.rb', line 13
def scope
@scope
end
|
#to ⇒ Date?
10
11
12
|
# File 'lib/relaton_bib/copyright_association.rb', line 10
def to
@to
end
|
Instance Method Details
#to_asciibib(prefix = "", count = 1) ⇒ String
69
70
71
72
73
74
75
76
77
|
# File 'lib/relaton_bib/copyright_association.rb', line 69
def to_asciibib(prefix = "", count = 1) pref = prefix.empty? ? "copyright" : "#{prefix}.copyright"
out = count > 1 ? "#{pref}::\n" : ""
owner.each { |ow| out += ow.to_asciibib "#{pref}.owner", owner.size }
out += "#{pref}.from:: #{from.year}\n" if from
out += "#{pref}.to:: #{to.year}\n" if to
out += "#{pref}.scope:: #{scope}\n" if scope
out
end
|
#to_hash ⇒ Hash
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/relaton_bib/copyright_association.rb', line 55
def to_hash owners = single_element_array(owner.map { |o| o.to_hash["organization"] })
hash = {
"owner" => owners,
"from" => from.year.to_s,
}
hash["to"] = to.year.to_s if to
hash["scope"] = scope if scope
hash
end
|
#to_xml(**opts) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/relaton_bib/copyright_association.rb', line 44
def to_xml(**opts)
opts[:builder].copyright do |builder|
builder.from from ? from.year : "unknown"
builder.to to.year if to
owner.each { |o| builder.owner { o.to_xml(**opts) } }
builder.scope scope if scope
end
end
|