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:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mrt/ingest/iobject.rb', line 15

def initialize(server, where, options)
  @name = options[:name]
  @digest = options[:digest]
  @mime_type = options[:mime_type]
  @size = options[:size]
  # @prefetch = options[:prefetch] || false
  @prefetch = false

  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?
    if @prefetch then
      digest = Digest::MD5.new()
      @uri, ignore = server.add_file do |f|
        open(where, (options[:prefetch_options] || {})) do |u|
          while (buff = u.read(1024)) do
            f << buff
            digest << buff
          end
        end
      end
      @digest = Mrt::Ingest::MessageDigest::MD5.new(digest.hexdigest)
    else
      @uri = where
    end
  else
    raise IngestException.new("Trying to add a component that is not a File or URI")
  end
  
end

Instance Method Details

#to_manifest_entryObject



53
54
55
56
57
58
59
60
# File 'lib/mrt/ingest/iobject.rb', line 53

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