Class: Mustermann::Shell

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

Overview

Matches strings that are identical to the pattern.

Examples:

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

See Also:

Constant Summary

Constants included from Mustermann

CompileError, DEFAULT_TYPE, Error, ExpandError, ParseError, TrieError

Instance Attribute Summary

Attributes inherited from Pattern

#uri_decode

Instance Method Summary collapse

Methods inherited from Pattern

#+, #==, #=~, #eql?, #expand, #hash, #identity_params?, #match, #names, new, #params, #peek, #peek_match, #peek_params, supported?, supported_options, #to_proc, #to_s, #to_templates, #|

Methods included from Mustermann

[], new

Constructor Details

#initialize(string, **options) ⇒ Pattern

Returns a new instance of Pattern.

Parameters:

  • string (String)

    the string representation of the pattern

  • options (Hash)

    options for fine-tuning the pattern behavior

See Also:



33
34
35
36
# File 'mustermann-contrib/lib/mustermann/shell.rb', line 33

def initialize(string, **options)
  @flags = File::FNM_PATHNAME | File::FNM_DOTMATCH | 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:



41
42
43
# File 'mustermann-contrib/lib/mustermann/shell.rb', line 41

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

#peek_size(string) ⇒ Integer?

Returns the number of characters that match.

Parameters:

  • string (String)

    The string to match against

Returns:

  • (Integer, nil)

    the number of characters that match



48
49
50
51
# File 'mustermann-contrib/lib/mustermann/shell.rb', line 48

def peek_size(string)
  @peek_string ||= @string + "{**,/**,/**/*}"
  super if File.fnmatch? @peek_string, unescape(string), @flags
end