Class: Hydra::FileCharacterization::Characterizer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Characterizer

Returns a new instance of Characterizer.



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

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



11
12
13
# File 'lib/hydra/file_characterization/characterizer.rb', line 11

def filename
  @filename
end

Instance Method Details

#callObject



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

def call
  unless File.exists?(filename)
    raise Hydra::FileCharacterization::FileNotFoundError.new("File: #{filename} does not exist.")
  end
  stdin, stdout, stderr, wait_thr = popen3(command)
  begin
    out = stdout.read
    err = stderr.read
    exit_status = wait_thr.value
    raise "Unable to execute command \"#{command}\"\n#{err}" unless exit_status.success?
    out
  ensure
    stdin.close
    stdout.close
    stderr.close
  end
end