Module: Wordlist::Format

Defined in:
lib/wordlist/format.rb

Overview

Handles wordlist format detection.

Since:

  • 1.0.0

Constant Summary collapse

FILE_FORMATS =

Mapping of file extensions to formats

Since:

  • 1.0.0

{
  '.txt' => :txt,
  '.gz'  => :gzip,
  '.bz2' => :bzip2,
  '.xz'  => :xz,
  '.zip' => :zip,
  '.7z'  => :"7zip"
}
FORMATS =

Valid formats.

Since:

  • 1.0.0

FILE_FORMATS.values

Class Method Summary collapse

Class Method Details

.infer(path) ⇒ :txt, ...

Infers the format from the given file name.

Parameters:

  • path (String)

    The path to the file.

Returns:

  • (:txt, :gzip, :bzip2, :xz, :zip, :7zip)

Raises:

  • (UnknownFormat)

    The format could not be inferred from the file path.

Since:

  • 1.0.0



35
36
37
38
39
# File 'lib/wordlist/format.rb', line 35

def self.infer(path)
  FILE_FORMATS.fetch(::File.extname(path)) do
    raise(UnknownFormat,"could not infer the format of file: #{path.inspect}")
  end
end