Sha256: e61ba5ad7e2f91b361bf3e03a3b6842da8a803380f7b6d020df05a2c15dc2168

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

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
            if info
              {
                  filepath: file,
                  mimetype: (info[:MIME].first rescue nil),
                  puid: (info[:PUID].first rescue nil),
                  matchtype: 'extension',
                  source: :type_database
              }
            end
          end.cleanup

        end

      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
libis-format-0.9.45 lib/libis/format/tool/extension_identification.rb