Sha256: b59b872d59c4296fff070e253bdb2560c73beec23f80d17b65aff2db5f4fb810

Contents?: true

Size: 964 Bytes

Versions: 1

Compression:

Stored size: 964 Bytes

Contents

# frozen_string_literal: true

require 'json'

module Cocina
  module Models
    # A digital repository object.  See https://github.com/sul-dlss-labs/taco/blob/master/maps/DRO.json
    class DRO < Dry::Struct
      attribute :externalIdentifier, Types::Strict::String
      attribute :type, Types::Strict::String
      attribute :label, Types::Strict::String
      attribute :access, Dry::Struct.meta(omittable: true) do
        attribute :embargoReleaseDate, Types::Params::Date
      end

      def self.from_dynamic(d)
        params = {
          externalIdentifier: d['externalIdentifier'],
          type: d['type'],
          label: d['label']
        }
        if d['access']
          access = {
            embargoReleaseDate: d['access']['embargoReleaseDate']
          }
          params[:access] = access
        end

        DRO.new(params)
      end

      def self.from_json(json)
        from_dynamic(JSON.parse(json))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocina-models-0.2.0 lib/cocina/models/dro.rb