cocina-models 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 918a0472029fa8a0ca3b66adb2984203f3d830ee30c449f44d9d3fa6a1ba7592
4
- data.tar.gz: 1bb461d3aba413ceb273912c34abb20c87aae08fdece11356ccff6ef44b22415
3
+ metadata.gz: d545662f72b0cc61f2d380d2a659b5eceedd07261e3bbcbf093748bb83313921
4
+ data.tar.gz: 0e7dfe39087cf1550e6d5ec421cfc19247e1345dc1ccc6789936a11b5f48f143
5
5
  SHA512:
6
- metadata.gz: 245d6b97f84147c73c61404527d5bef0f3b3dccf8c18bf9d02183f65a3e5111af300c5b964e006c3bd547e3bd5de134ed5c4b8de3ca7242ae4430c4901ef0d05
7
- data.tar.gz: 4c5cc681c427448de988238584d37986c6af158c553ebdf8fe7cbbbca118d4e946cd8d0bed5031a9b35f29a0c4f3ac99f3846db39662daa948332b14e3914fc0
6
+ metadata.gz: 87e6e541b2de60c90a0a788367cef62a1c3d55ab8f2bbf687fd85a1198a025e81fe2ccd258a1cc59ce5bbcaa1dbfe3020aa8c687cba29d813af5e9df09df9c97
7
+ data.tar.gz: b35a5fecfbcef1376ca2d61d7b046787814c6a0a106fa4625fff4c6c024dab56803426f5253e36bfd2ed9723c6ea8363480ee88323ba74efce436d00cbf41509
data/.rubocop.yml CHANGED
@@ -12,7 +12,7 @@ Metrics/LineLength:
12
12
  Max: 114
13
13
 
14
14
  Metrics/MethodLength:
15
- Max: 13
15
+ Max: 14
16
16
 
17
17
  RSpec/MultipleExpectations:
18
18
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -0,0 +1,23 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-10-24 15:36:09 -0500 using RuboCop version 0.74.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 18
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ Metrics/MethodLength:
16
+ Max: 14
17
+
18
+ # Offense count: 2
19
+ # Configuration parameters: Max.
20
+ RSpec/ExampleLength:
21
+ Exclude:
22
+ - 'spec/cocina/models/dro_spec.rb'
23
+ - 'spec/cocina/models/file_spec.rb'
data/docs/maps/File.json CHANGED
@@ -34,7 +34,21 @@
34
34
  },
35
35
  "hasMessageDigests": {
36
36
  "description": "The output of the message digest algorithm.",
37
- "type": "object"
37
+ "type": "array",
38
+ "items": {
39
+ "required": ["type", "digest"],
40
+ "properties": {
41
+ "type": {
42
+ "description": "The algorithm that was used",
43
+ "type": "string",
44
+ "enum": ["md5", "sha1"]
45
+ },
46
+ "digest": {
47
+ "description": "The digest value",
48
+ "type": "string"
49
+ }
50
+ }
51
+ }
38
52
  },
39
53
  "hasMimeType": {
40
54
  "description": "MIME Type of the File.",
@@ -46,7 +60,17 @@
46
60
  },
47
61
  "presentation": {
48
62
  "description": "Presentation data for the File.",
49
- "type": "object"
63
+ "type": "object",
64
+ "properties": {
65
+ "height": {
66
+ "description": "Height in pixels",
67
+ "type": "integer",
68
+ },
69
+ "width": {
70
+ "description": "Width in pixels",
71
+ "type": "integer",
72
+ },
73
+ }
50
74
  },
51
75
  "size": {
52
76
  "description": "Size of the File (binary) in bytes.",
@@ -121,6 +121,13 @@
121
121
  "type": "object",
122
122
  "required": ["isContainedBy"],
123
123
  "properties": {
124
+ "contains": {
125
+ "description": "Files that are members of the fileset.",
126
+ "type": "array",
127
+ "items": {
128
+ "type": "string"
129
+ }
130
+ },
124
131
  "isContainedBy": {
125
132
  "description": "Parent DRO that is represented by the files in this Fileset.",
126
133
  "type": "string"
@@ -66,7 +66,15 @@ module Cocina
66
66
  class Identification < Dry::Struct
67
67
  end
68
68
 
69
+ # Structural sub-schema for the DRO
69
70
  class Structural < Dry::Struct
71
+ attribute :contains, Types::Strict::Array.of(Types::Coercible::String).meta(omittable: true)
72
+
73
+ def self.from_dynamic(dyn)
74
+ params = {}
75
+ params[:contains] = dyn['contains'] if dyn['contains']
76
+ Structural.new(params)
77
+ end
70
78
  end
71
79
 
72
80
  attribute :externalIdentifier, Types::Strict::String
@@ -88,6 +96,7 @@ module Cocina
88
96
 
89
97
  params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
90
98
  params[:administrative] = Administrative.from_dynamic(dyn['administrative']) if dyn['administrative']
99
+ params[:structural] = Structural.from_dynamic(dyn['structural']) if dyn['structural']
91
100
 
92
101
  DRO.new(params)
93
102
  end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Cocina
6
+ module Models
7
+ # Metadata for a file. See http://sul-dlss.github.io/cocina-models/maps/File.json
8
+ class File < Dry::Struct
9
+ TYPES = %w[
10
+ http://cocina.sul.stanford.edu/models/file.jsonld
11
+ ].freeze
12
+
13
+ class Identification < Dry::Struct
14
+ end
15
+
16
+ class Structural < Dry::Struct
17
+ end
18
+
19
+ # Represents a digest value for a file
20
+ class Fixity < Dry::Struct
21
+ attribute :type, Types::String.enum('md5', 'sha1')
22
+ attribute :digest, Types::Strict::String
23
+
24
+ def self.from_dynamic(dyn)
25
+ params = {
26
+ type: dyn['type'],
27
+ digest: dyn['digest']
28
+ }
29
+
30
+ Fixity.new(params)
31
+ end
32
+ end
33
+
34
+ # Represents some technical aspect of the file
35
+ class Presentation < Dry::Struct
36
+ attribute :height, Types::Coercible::Integer.optional.default(nil)
37
+ attribute :width, Types::Coercible::Integer.optional.default(nil)
38
+
39
+ def self.from_dynamic(dyn)
40
+ params = {
41
+ height: dyn['height'],
42
+ width: dyn['width']
43
+ }
44
+
45
+ Presentation.new(params)
46
+ end
47
+ end
48
+
49
+ attribute :externalIdentifier, Types::Strict::String
50
+ attribute :type, Types::String.enum(*TYPES)
51
+ attribute :label, Types::Strict::String
52
+ attribute :filename, Types::String.optional.default(nil)
53
+ attribute :use, Types::String.enum('original', 'preservation', 'access').optional.default(nil)
54
+ attribute :size, Types::Coercible::Integer.optional.default(nil)
55
+ attribute :hasMessageDigests, Types::Strict::Array.of(Fixity).default([])
56
+ attribute :presentation, Presentation.optional.default(Presentation.new)
57
+ attribute :version, Types::Coercible::Integer
58
+ attribute(:identification, Identification.default { Identification.new })
59
+ attribute(:structural, Structural.default { Structural.new })
60
+
61
+ def self.from_dynamic(dyn)
62
+ params = {
63
+ externalIdentifier: dyn['externalIdentifier'],
64
+ type: dyn['type'],
65
+ label: dyn['label'],
66
+ version: dyn['version'],
67
+ size: dyn['size'],
68
+ use: dyn['use']
69
+ }
70
+ params[:presentation] = Presentation.from_dynamic(dyn['presentation']) if dyn['presentation']
71
+ if dyn['hasMessageDigests']
72
+ params[:hasMessageDigests] = dyn['hasMessageDigests'].map { |p| Fixity.from_dynamic(p) }
73
+ end
74
+ File.new(params)
75
+ end
76
+
77
+ def self.from_json(json)
78
+ from_dynamic(JSON.parse(json))
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Cocina
6
+ module Models
7
+ # Metadata for a File Set. See http://sul-dlss.github.io/cocina-models/maps/Fileset.json
8
+ class FileSet < Dry::Struct
9
+ TYPES = %w[
10
+ http://cocina.sul.stanford.edu/models/fileset.jsonld
11
+ ].freeze
12
+
13
+ class Identification < Dry::Struct
14
+ end
15
+
16
+ # Structural sub-schema for the FileSet
17
+ class Structural < Dry::Struct
18
+ attribute :contains, Types::Strict::Array.of(Types::Coercible::String).meta(omittable: true)
19
+
20
+ def self.from_dynamic(dyn)
21
+ params = {}
22
+ params[:contains] = dyn['contains'] if dyn['contains']
23
+ Structural.new(params)
24
+ end
25
+ end
26
+
27
+ attribute :externalIdentifier, Types::Strict::String
28
+ attribute :type, Types::String.enum(*TYPES)
29
+ attribute :label, Types::Strict::String
30
+ attribute :version, Types::Coercible::Integer
31
+ attribute(:identification, Identification.default { Identification.new })
32
+ attribute(:structural, Structural.default { Structural.new })
33
+
34
+ def self.from_dynamic(dyn)
35
+ params = {
36
+ externalIdentifier: dyn['externalIdentifier'],
37
+ type: dyn['type'],
38
+ label: dyn['label'],
39
+ version: dyn['version'],
40
+ size: dyn['size'],
41
+ use: dyn['use']
42
+ }
43
+ params[:presentation] = Presentation.from_dynamic(dyn['presentation']) if dyn['presentation']
44
+ if dyn['hasMessageDigests']
45
+ params[:hasMessageDigests] = dyn['hasMessageDigests'].map { |p| Fixity.from_dynamic(p) }
46
+ end
47
+ params[:structural] = Structural.from_dynamic(dyn['structural']) if dyn['structural']
48
+
49
+ FileSet.new(params)
50
+ end
51
+
52
+ def self.from_json(json)
53
+ from_dynamic(JSON.parse(json))
54
+ end
55
+ end
56
+ end
57
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cocina
4
4
  module Models
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocina-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-11 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -157,6 +157,8 @@ files:
157
157
  - lib/cocina/models/admin_policy.rb
158
158
  - lib/cocina/models/collection.rb
159
159
  - lib/cocina/models/dro.rb
160
+ - lib/cocina/models/file.rb
161
+ - lib/cocina/models/file_set.rb
160
162
  - lib/cocina/models/types.rb
161
163
  - lib/cocina/models/version.rb
162
164
  homepage: https://github.com/sul-dlss-labs/cocina-models