Class: Hydra::FileCharacterization::ToTempFile
- Inherits:
-
Object
- Object
- Hydra::FileCharacterization::ToTempFile
- Includes:
- Open3
- Defined in:
- lib/hydra/file_characterization/to_temp_file.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#filename ⇒ Object
Returns the value of attribute filename.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(data, filename) ⇒ ToTempFile
constructor
A new instance of ToTempFile.
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
#data ⇒ Object
Returns the value of attribute data.
12 13 14 |
# File 'lib/hydra/file_characterization/to_temp_file.rb', line 12 def data @data end |
#filename ⇒ Object
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
#call ⇒ Object
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 |