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

Instance Attribute Summary

Attributes inherited from Pattern

#uri_decode

Instance Method Summary collapse

Methods inherited from Pattern

#+, #==, #=~, #eql?, #expand, #hash, #match, #named_captures, #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:


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

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:


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

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


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

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