Class: RelatonBib::CopyrightAssociation

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_bib/copyright_association.rb

Overview

Copyright association.

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(owner:, from:, to: nil, scope: nil) ⇒ CopyrightAssociation

Returns a new instance of CopyrightAssociation.

Parameters:

  • owner (Array<Hash, RelatonBib::ContributionInfo>)

    contributor

  • from (String)

    date

  • to (String, NilClass) (defaults to: nil)

    date

  • scope (String, NilClass) (defaults to: nil)

Options Hash (owner:):

  • :name (String)
  • :abbreviation (String)
  • :url (String)


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

#fromDate (readonly)

Returns:

  • (Date)


7
8
9
# File 'lib/relaton_bib/copyright_association.rb', line 7

def from
  @from
end

#ownerArray<RelatonBib::ContributionInfo> (readonly)



16
17
18
# File 'lib/relaton_bib/copyright_association.rb', line 16

def owner
  @owner
end

#scopeString, NilClass (readonly)

Returns:

  • (String, NilClass)


13
14
15
# File 'lib/relaton_bib/copyright_association.rb', line 13

def scope
  @scope
end

#toDate, NilClass (readonly)

Returns:

  • (Date, NilClass)


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

Parameters:

  • prefix (String) (defaults to: "")
  • count (Iteger) (defaults to: 1)

    number of copyright elements

Returns:

  • (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_hashHash

Returns:

  • (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

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :builder (Nokogiri::XML::Builder)

    XML builder

  • :lang (String, Symbol)

    language



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