Sha256: e977ceddc0bc54d50ee3e6e27d177f2f1fca7fc3dbd3fde19733bdb6d04bc58b

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require_relative 'identification_tool'

module Libis
  module Format
    module Tool
      class ExtensionIdentification < Libis::Format::Tool::IdentificationTool
        def run_list(filelist, **_options)
          output = runner(nil, filelist)

          process_output(output)
        end

        def run_dir(dir, recursive = true, **_options)
          filelist = find_files(dir, recursive)

          output = runner(nil, filelist)

          process_output(output)
        end

        def run(file, **_options)
          output = runner(file)

          process_output(output)
        end

        protected

        def runner(*args)
          args.map do |file|
            info = ::Libis::Format::TypeDatabase.ext_infos(File.extname(file)).first
            next unless info

            {
              filepath: file,
              mimetype: begin
                info[:MIME].first
              rescue StandardError
                nil
              end,
              puid: begin
                info[:PUID].first
              rescue StandardError
                nil
              end,
              matchtype: 'extension',
              tool: :type_database
            }
          end.cleanup
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
libis-format-1.3.4 lib/libis/format/tool/extension_identification.rb
libis-format-1.3.3 lib/libis/format/tool/extension_identification.rb
libis-format-1.3.2 lib/libis/format/tool/extension_identification.rb
libis-format-1.3.0 lib/libis/format/tool/extension_identification.rb
libis-format-1.2.9 lib/libis/format/tool/extension_identification.rb
libis-format-1.2.8 lib/libis/format/tool/extension_identification.rb