Class: Libis::Format::Identifier

Inherits:
Object
  • Object
show all
Includes:
Tools::Logger, Singleton
Defined in:
lib/libis/format/identifier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xml_validationsObject (readonly)

Returns the value of attribute xml_validations.



37
38
39
# File 'lib/libis/format/identifier.rb', line 37

def xml_validations
  @xml_validations
end

Class Method Details

.add_xml_validation(mimetype, xsd_file) ⇒ Object



25
26
27
# File 'lib/libis/format/identifier.rb', line 25

def self.add_xml_validation(mimetype, xsd_file)
  instance.xml_validations[mimetype] = xsd_file
end

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



33
34
35
# File 'lib/libis/format/identifier.rb', line 33

def self.get(file, options = {})
  instance.get file, options
end

.xml_validationsObject



29
30
31
# File 'lib/libis/format/identifier.rb', line 29

def self.xml_validations
  instance.xml_validations
end

Instance Method Details

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



39
40
41
42
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
# File 'lib/libis/format/identifier.rb', line 39

def get(file, options = {})
  options[:droid] = true unless options.keys.include?(:droid) || (options[:tool] && (options[:tool] != :droid))
  options[:fido] = true unless options.keys.include?(:fido) || (options[:tool] && (options[:tool] != :fido))
  options[:file] = true unless options.keys.include?(:file) || (options[:tool] && (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 StandardError => 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 StandardError => 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 StandardError => 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 StandardError => e
    log_msg(result, :error, "Error validating XML files: #{e.message} @ #{e.backtrace.first}")
  end

  process_results(result, !options[:keep_output])

  result
end