Class: Mrt::Ingest::IObject

Inherits:
Object
  • Object
show all
Defined in:
lib/mrt/ingest/iobject.rb

Overview

An object prepared for ingest into Merritt.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ IObject

Options can have the keys :primary_identifier, :local_identifier, or :erc. :erc can be a #File, #Uri or a #Hash of metadata.



20
21
22
23
24
25
# File 'lib/mrt/ingest/iobject.rb', line 20

def initialize(options = {})
  @primary_identifier = options[:primary_identifier]
  @local_identifier = options[:local_identifier]
  @erc = options[:erc] || {}
  @components = []
end

Instance Attribute Details

#ercObject

Returns the value of attribute erc.



15
16
17
# File 'lib/mrt/ingest/iobject.rb', line 15

def erc
  @erc
end

#local_identifierObject

Returns the value of attribute local_identifier.



15
16
17
# File 'lib/mrt/ingest/iobject.rb', line 15

def local_identifier
  @local_identifier
end

#primary_identifierObject

Returns the value of attribute primary_identifier.



15
16
17
# File 'lib/mrt/ingest/iobject.rb', line 15

def primary_identifier
  @primary_identifier
end

#whatObject

Returns the value of attribute what.



15
16
17
# File 'lib/mrt/ingest/iobject.rb', line 15

def what
  @what
end

#whenObject

Returns the value of attribute when.



15
16
17
# File 'lib/mrt/ingest/iobject.rb', line 15

def when
  @when
end

#whoObject

Returns the value of attribute who.



15
16
17
# File 'lib/mrt/ingest/iobject.rb', line 15

def who
  @who
end

Instance Method Details

#add_component(where, options = {}) ⇒ Object

Add a component to the object. where can be either a #URI or a #File. Options is a hash whose keys may be :name, :digest, :mime_type, or :size. If :digest is supplied, it must be a subclass of Mrt::Ingest::MessageDigest::Base. If where is a #File, it will be hosted on an embedded web server.



32
33
34
# File 'lib/mrt/ingest/iobject.rb', line 32

def add_component(where, options = {})
  @components.push(Component.new(where, options))
end

#finish_ingestObject

Wait for the ingest of this object to finish.



67
68
69
70
# File 'lib/mrt/ingest/iobject.rb', line 67

def finish_ingest
  # XXX Right now we only join the hosting server; in the future
  # we will check the status via the ingest server.
end

#mk_manifest(manifest) ⇒ Object

rubocop:disable Metrics/LineLength



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mrt/ingest/iobject.rb', line 46

def mk_manifest(manifest) # :nodoc:
  manifest.write("#%checkm_0.7\n")
  manifest.write("#%profile http://uc3.cdlib.org/registry/ingest/manifest/mrt-ingest-manifest\n")
  manifest.write("#%prefix | mrt: | http://uc3.cdlib.org/ontology/mom#\n")
  manifest.write("#%prefix | nfo: | http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#\n")
  manifest.write("#%fields | nfo:fileUrl | nfo:hashAlgorithm | nfo:hashValue | nfo:fileSize | nfo:fileLastModified | nfo:fileName | mrt:mimeType\n")
  @components.each do |c|
    manifest.write(c.to_manifest_entry)
  end
  manifest.write("#%EOF\n")
end

#mk_request(profile, user_agent) ⇒ Object

Make a Mrt::Ingest::Request object for this mrt-object



37
38
39
40
41
42
43
# File 'lib/mrt/ingest/iobject.rb', line 37

def mk_request(profile, user_agent)
  manifest_file = Tempfile.new('mrt-ingest')
  mk_manifest(manifest_file)
  # reset to beginning
  manifest_file.open
  new_request(manifest_file, profile, user_agent)
end

#start_ingest(client, profile, submitter) ⇒ Object

Begin an ingest on the given client, with a profile and submitter.



61
62
63
64
# File 'lib/mrt/ingest/iobject.rb', line 61

def start_ingest(client, profile, submitter)
  request = mk_request(profile, submitter)
  @response = client.ingest(request)
end