Class: Mustermann::Shell

Inherits:
Pattern show all
Defined in:
lib/mustermann/shell.rb

Overview

Matches strings that are identical to the pattern.

Examples:

Mustermann.new('/*.*', type: :shell) === '/bar' # => false

See Also:

Instance Method Summary collapse

Methods inherited from Pattern

#=~, #expand, #match, #named_captures, #names, new, #params, supported?, supported_options, #to_s

Constructor Details

#initialize(string, **options) ⇒ Shell, Pattern

Parameters:

  • string (String)

    the string representation of the pattern

  • options (Hash)

    options for fine-tuning the pattern behavior

See Also:



16
17
18
19
20
# File 'lib/mustermann/shell.rb', line 16

def initialize(string, **options)
  @flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
  @flags |= File::FNM_EXTGLOB if defined? File::FNM_EXTGLOB
  super(string, **options)
end

Instance Method Details

#===(string) ⇒ Boolean

Returns Whether or not the pattern matches the given string.

Parameters:

  • string (String)

    The string to match against

Returns:

  • (Boolean)

    Whether or not the pattern matches the given string

See Also:



25
26
27
# File 'lib/mustermann/shell.rb', line 25

def ===(string)
  File.fnmatch? @string, unescape(string), @flags
end