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:

Constant Summary

Constants inherited from Pattern

Pattern::PATTERN_METHODS

Constants included from Mustermann

DEFAULT_TYPE, VERSION

Instance Method Summary collapse

Methods inherited from Pattern

#&, #=~, #^, #expand, #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, register

Constructor Details

#initialize(string, options = {}) ⇒ Shell, Pattern

Parameters:

  • string (String)

    the string representation of the pattern

  • options (Hash) (defaults to: {})

    options for fine-tuning the pattern behavior

See Also:



18
19
20
21
22
# File 'lib/mustermann/shell.rb', line 18

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:



27
28
29
# File 'lib/mustermann/shell.rb', line 27

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



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

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