Method: Libis::Format::Identifier#get

Defined in:
lib/libis/format/identifier.rb

#get(file, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/libis/format/identifier.rb', line 43

def get(file, options = {})

  options[:droid] = true unless options.keys.include?(:droid) or (options[:tool] and options[:tool] != :droid)
  options[:fido] = true unless options.keys.include?(:fido) or (options[:tool] and options[:tool] != :fido)
  options[:file] = true unless options.keys.include?(:file) or (options[:tool] and options[:tool] != :file)
  options[:xml_validation] = true if options[:xml_validation].nil?

  result = {messages: [], output: {}, formats: {}}

  begin
    get_droid_identification(file, result, options) if options[:droid]
  rescue => e
    log_msg(result, :error, "Error running Droid: #{e.message} @ #{e.backtrace.first}")
  end

  begin
    get_fido_identification(file, result, options) if options[:fido]
  rescue => e
    log_msg(result, :error, "Error running Fido: #{e.message} @ #{e.backtrace.first}")
  end

  begin
    get_file_identification(file, result, options) if options[:file]
  rescue => e
    log_msg(result, :error, "Error running File: #{e.message} @ #{e.backtrace.first}")
  end

  # Let's not waiste time on this. If not standard, it will fail in Rosetta anyway.
  # get_extension_identification(file, options[:recursive], result)

  # determine XML type. Add custom types at runtime with
  # Libis::Tools::Format::Identifier.add_xml_validation('my_type', '/path/to/my_type.xsd')
  begin
    validate_against_xml_schema(result, options[:base_dir]) if options[:xml_validation]
  rescue => e
    log_msg(result, :error, "Error validating XML files: #{e.message} @ #{e.backtrace.first}")
  end

  process_results(result, !options[:keep_output])

  result

end