class Hydra::FileCharacterization::Characterizer

Attributes

filename[R]

Public Class Methods

new(filename, tool_path = nil) click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 13
def initialize(filename, tool_path = nil)
  @filename = filename
  @tool_path = tool_path
end

Public Instance Methods

call() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 18
def call
  raise Hydra::FileCharacterization::FileNotFoundError, "File: #{filename} does not exist." unless File.exist?(filename)

  post_process(output)
end
logger() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 28
def logger
  @logger ||= activefedora_logger || Logger.new(STDERR)
end
tool_path() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 24
def tool_path
  @tool_path || self.class.tool_path || convention_based_tool_name
end

Protected Instance Methods

command() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 59
def command
  raise NotImplementedError, "Method #command should be overriden in child classes"
end
convention_based_tool_name() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 40
def convention_based_tool_name
  self.class.name.split("::").last.downcase
end
internal_call() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 44
def internal_call
  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
post_process(raw_output) click to toggle source

Override this method if you want your processor to mutate the raw output

# File lib/hydra/file_characterization/characterizer.rb, line 36
def post_process(raw_output)
  raw_output
end

Private Instance Methods

activefedora_logger() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 73
def activefedora_logger
  ActiveFedora::Base.logger if defined? ActiveFedora
end
output() click to toggle source
# File lib/hydra/file_characterization/characterizer.rb, line 65
def output
  if tool_path.respond_to?(:call)
    tool_path.call(filename)
  else
    internal_call
  end
end