Sha256: 20f85aa95edeb66667c9de187037561fae9805189e43c3b5f2c4281264499156

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require 'json'

module Cocina
  module Models
    # Metadata for a File Set.  See http://sul-dlss.github.io/cocina-models/maps/Fileset.json
    class FileSet < Dry::Struct
      include Checkable

      TYPES = [
        Vocab.fileset
      ].freeze

      class Identification < Dry::Struct
      end

      # Structural sub-schema for the FileSet
      class Structural < Dry::Struct
        attribute :contains, Types::Strict::Array.of(Types::Coercible::String).meta(omittable: true)

        def self.from_dynamic(dyn)
          params = {}
          params[:contains] = dyn['contains'] if dyn['contains']
          Structural.new(params)
        end
      end

      attribute :externalIdentifier, Types::Strict::String
      attribute :type, Types::String.enum(*TYPES)
      attribute :label, Types::Strict::String
      attribute :version, Types::Coercible::Integer
      attribute(:identification, Identification.default { Identification.new })
      attribute(:structural, Structural.default { Structural.new })

      def self.from_dynamic(dyn)
        params = {
          externalIdentifier: dyn['externalIdentifier'],
          type: dyn['type'],
          label: dyn['label'],
          version: dyn['version'],
          size: dyn['size'],
          use: dyn['use']
        }
        params[:presentation] = Presentation.from_dynamic(dyn['presentation']) if dyn['presentation']
        if dyn['hasMessageDigests']
          params[:hasMessageDigests] = dyn['hasMessageDigests'].map { |p| Fixity.from_dynamic(p) }
        end
        params[:structural] = Structural.from_dynamic(dyn['structural']) if dyn['structural']

        FileSet.new(params)
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cocina-models-0.11.0 lib/cocina/models/file_set.rb
cocina-models-0.10.0 lib/cocina/models/file_set.rb
cocina-models-0.9.0 lib/cocina/models/file_set.rb