Sha256: d9ab37c97e62dfeea5414fcb2b6b69f8c02d84f73056e36842b77f5bf6bcea53

Contents?: true

Size: 1.7 KB

Versions: 8

Compression:

Stored size: 1.7 KB

Contents

module RelatonBib
  # Copyright association.
  class CopyrightAssociation
    include RelatonBib

    # @return [Date]
    attr_reader :from

    # @return [Date, NilClass]
    attr_reader :to

    # @return [String, NilClass]
    attr_reader :scope

    # @return [Array<RelatonBib::ContributionInfo>]
    attr_reader :owner

    # rubocop:disable Metrics/AbcSize

    # @param owner [Array<Hash, RelatonBib::ContributionInfo>] contributor
    # @option owner [String] :name
    # @option owner [String] :abbreviation
    # @option owner [String] :url
    # @param from [String] date
    # @param to [String, NilClass] date
    # @param scope [String, NilClass]
    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

    # @param builder [Nokogiri::XML::Builder]
    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
    # rubocop:enable Metrics/AbcSize

    # @return [Hash]
    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
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/relaton-bib-1.2.4/lib/relaton_bib/copyright_association.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/relaton-bib-1.2.4/lib/relaton_bib/copyright_association.rb
relaton-bib-1.2.4 lib/relaton_bib/copyright_association.rb
relaton-bib-1.2.2 lib/relaton_bib/copyright_association.rb
relaton-bib-1.2.1 lib/relaton_bib/copyright_association.rb
relaton-bib-1.2.0 lib/relaton_bib/copyright_association.rb
relaton-bib-1.1.1 lib/relaton_bib/copyright_association.rb
relaton-bib-1.1.0 lib/relaton_bib/copyright_association.rb