Class: Medusa::Collection

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/medusa/collection.rb

Overview

Represents a Medusa collection.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#exists?, #id, #uuid

Methods included from Uuidable

#uuid_url

Constructor Details

#initializeCollection

Returns a new instance of Collection.



36
37
38
39
40
41
42
# File 'lib/medusa/collection.rb', line 36

def initialize
  @loading     = false
  @loaded      = false
  @file_groups = Set.new
  @id          = nil
  @uuid        = nil
end

Class Method Details

.with_id(id) ⇒ Medusa::Collection

Returns a new instance with the given ID. Existence is not checked, so an instance is returned regardless of whether the ID is valid.

Parameters:

  • id (Integer)

    Medusa database ID.

Returns:



17
18
19
20
21
# File 'lib/medusa/collection.rb', line 17

def self.with_id(id)
  col = Collection.new
  col.instance_variable_set('@id', id)
  col
end

.with_uuid(uuid) ⇒ Medusa::Collection

Returns a new instance with the given UUID. Existence is not checked, so an instance is returned regardless of whether the UUID is valid.

Parameters:

  • uuid (String)

    Medusa UUID.

Returns:



30
31
32
33
34
# File 'lib/medusa/collection.rb', line 30

def self.with_uuid(uuid)
  col = Collection.new
  col.instance_variable_set('@uuid', uuid)
  col
end

Instance Method Details

#access_urlString

Returns:

  • (String)


47
48
49
50
# File 'lib/medusa/collection.rb', line 47

def access_url
  load
  @access_url
end

#contact_emailString

Returns:

  • (String)


55
56
57
58
# File 'lib/medusa/collection.rb', line 55

def contact_email
  load
  @contact_email
end

#descriptionString

Returns:

  • (String)


63
64
65
66
# File 'lib/medusa/collection.rb', line 63

def description
  load
  @description
end

#description_htmlString

Returns:

  • (String)


71
72
73
74
# File 'lib/medusa/collection.rb', line 71

def description_html
  load
  @description_html
end

#external_idString

Returns:

  • (String)


79
80
81
82
# File 'lib/medusa/collection.rb', line 79

def external_id
  load
  @external_id
end

#file_groupsEnumerable<Medusa::FileGroup>

Returns:



87
88
89
90
# File 'lib/medusa/collection.rb', line 87

def file_groups
  load
  @file_groups
end

#loadObject

Updates the instance with current properties from Medusa.

It should not typically be necessary to use this method publicly.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/medusa/collection.rb', line 153

def load
  return if @loading || @loaded
  @loading                 = true
  struct                   = fetch_body
  @access_url              = struct['access_url']
  @contact_email           = struct['contact_email']
  @description             = struct['description']
  @description_html        = struct['description_html']
  @external_id             = struct['external_id']
  @id                      = struct['id']
  @physical_collection_url = struct['physical_collection_url']
  @private_description     = struct['private_description']
  @published               = struct['publish']
  @representative_image    = struct['representative_image']
  @representative_item     = struct['representative_item']
  @repository_uuid         = struct['repository_uuid']
  @title                   = struct['title']
  @uuid                    = struct['uuid']
  struct['file_groups'].each do |group|
    @file_groups << FileGroup.with_id(group['id'])
  end
  @loaded = true
ensure
  @loading = false
end

#physical_collection_urlString

Returns:

  • (String)


95
96
97
98
# File 'lib/medusa/collection.rb', line 95

def physical_collection_url
  load
  @physical_collection_url
end

#private_descriptionString

Returns:

  • (String)


103
104
105
106
# File 'lib/medusa/collection.rb', line 103

def private_description
  load
  @private_description
end

#published?Boolean

Returns:

  • (Boolean)


111
112
113
114
# File 'lib/medusa/collection.rb', line 111

def published?
  load
  @published
end

#repositoryMedusa::Repository

Returns:



119
120
121
122
# File 'lib/medusa/collection.rb', line 119

def repository
  load
  @repository ||= Repository.with_uuid(@repository_uuid)
end

#representative_imageString

Returns:

  • (String)


127
128
129
130
# File 'lib/medusa/collection.rb', line 127

def representative_image
  load
  @representative_image
end

#representative_itemString

Returns Digital Library item UUID.

Returns:

  • (String)

    Digital Library item UUID.



135
136
137
138
# File 'lib/medusa/collection.rb', line 135

def representative_item
  load
  @representative_item
end

#titleString

Returns:

  • (String)


143
144
145
146
# File 'lib/medusa/collection.rb', line 143

def title
  load
  @title
end

#urlString

Returns Absolute URI of the corresponding Medusa resource.

Returns:

  • (String)

    Absolute URI of the corresponding Medusa resource.



182
183
184
185
186
# File 'lib/medusa/collection.rb', line 182

def url
  [::Medusa::Client.configuration[:medusa_base_url].chomp('/'),
   'collections',
   self.id].join('/')
end