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 =~ /\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_hashHash

Returns:

  • (Hash)


53
54
55
56
57
58
59
60
61
62
# File 'lib/relaton_bib/copyright_association.rb', line 53

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(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


42
43
44
45
46
47
48
49
# File 'lib/relaton_bib/copyright_association.rb', line 42

def to_xml(builder)
  builder.copyright do
    builder.from from ? from.year : "unknown"
    builder.to to.year if to
    owner.each { |o| builder.owner { o.to_xml builder } }
    builder.scope scope if scope
  end
end