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.



41
42
43
# File 'lib/libis/format/identifier.rb', line 41

def xml_validations
  @xml_validations
end

Class Method Details

.add_xml_validation(mimetype, xsd_file) ⇒ Object



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

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

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



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

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

.xml_validationsObject



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

def self.xml_validations
  instance.xml_validations
end

Instance Method Details

#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) and options[:tool] and options[:tool] != :droid
  options[:fido] = true unless options.keys.include?(:fido) and options[:tool] and options[:tool] != :fido
  options[:file] = true unless options.keys.include?(:file) and options[:tool] and options[:tool] != :file
  options[:xml_validation] = true unless options.keys.include?(:xml_validation) and !options[:xml_validation]

  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