Class: Mrt::Ingest::Component

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

Overview

Represents a component of an object to ingest. Either a #URI or a #File.

Instance Method Summary collapse

Constructor Details

#initialize(server, where, options) ⇒ Component

:nodoc:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mrt/ingest/iobject.rb', line 13

def initialize(server, where, options)
  @name = options[:name]
  @digest = options[:digest]
  @mime_type = options[:mime_type]
  @size = options[:size]
  
  case where
  when File, Tempfile
    @name = File.basename(where.path) if @name.nil?
    @uri = server.add_file(where)[0]
    if @digest.nil? then
      @digest = Mrt::Ingest::MessageDigest::MD5.from_file(where)
    end
    @size = File.size(where.path) if @size.nil?
  when URI
    @name = File.basename(where.to_s) if @name.nil?
    @uri = where
  else
    raise IngestException.new("Trying to add a component that is not a File or URI")
  end
  
end

Instance Method Details

#to_manifest_entryObject



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

def to_manifest_entry
  (digest_alg, digest_value) = if @digest.nil? then
                                 ['', '']
                               else
                                 [@digest.type, @digest.value]
                               end
  return "#{@uri} | #{digest_alg} | #{digest_value} | #{@size || ''} | | #{@name} | #{@mime_type || '' }\n"
end