Class: RelatonBib::CopyrightAssociation
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/copyright_association.rb
Overview
Copyright association.
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #from ⇒ Date readonly
- #owner ⇒ Array<RelatonBib::ContributionInfo> readonly
- #scope ⇒ String, NilClass readonly
- #to ⇒ Date, NilClass readonly
Instance Method Summary collapse
-
#initialize(owner:, from:, to: nil, scope: nil) ⇒ CopyrightAssociation
constructor
A new instance of CopyrightAssociation.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(**opts) ⇒ Object
Methods included from RelatonBib
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 (readonly)
7 8 9 |
# File 'lib/relaton_bib/copyright_association.rb', line 7 def from @from end |
#owner ⇒ Array<RelatonBib::ContributionInfo> (readonly)
16 17 18 |
# File 'lib/relaton_bib/copyright_association.rb', line 16 def owner @owner end |
#scope ⇒ String, NilClass (readonly)
13 14 15 |
# File 'lib/relaton_bib/copyright_association.rb', line 13 def scope @scope end |
#to ⇒ Date, NilClass (readonly)
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) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity 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 # rubocop:disable Metrics/AbcSize 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 |