Class: Hydra::FileCharacterization::ToTempFile

Inherits:
Object
  • Object
show all
Includes:
Open3
Defined in:
lib/hydra/file_characterization/to_temp_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, filename) ⇒ ToTempFile

Returns a new instance of ToTempFile.



14
15
16
17
# File 'lib/hydra/file_characterization/to_temp_file.rb', line 14

def initialize(data, filename)
  @data = data
  @filename = filename
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



12
13
14
# File 'lib/hydra/file_characterization/to_temp_file.rb', line 12

def data
  @data
end

#filenameObject

Returns the value of attribute filename.



12
13
14
# File 'lib/hydra/file_characterization/to_temp_file.rb', line 12

def filename
  @filename
end

Class Method Details

.open(*args, &block) ⇒ Object



8
9
10
# File 'lib/hydra/file_characterization/to_temp_file.rb', line 8

def self.open(*args, &block)
  new(*args).call(&block)
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hydra/file_characterization/to_temp_file.rb', line 19

def call
  return if data.empty?
  f = Tempfile.new([File.basename(filename),File.extname(filename)])
  begin
    f.binmode
    f.write(data)
    f.rewind
    yield(f)
  ensure
    f.close
    f.unlink
  end

end