Sha256: 93083e3d19840a2e4e7680c23044b7dc7fd0d9bcdbcd118953ef690cc1c32e6d

Contents?: true

Size: 767 Bytes

Versions: 17

Compression:

Stored size: 767 Bytes

Contents

# frozen_string_literal: true

module EacRubyUtils
  # The `Wildcards` class provides pattern matching with wildcards using regular expressions.
  class Wildcards
    # Initializes a new instance of the `Wildcards` class with the specified pattern.
    #
    # @param pattern [String] The pattern to match against.
    def initialize(pattern)
      @pattern = pattern
    end

    # Matches the given string against the pattern.
    #
    # @param string [String] The string to match.
    # @return [Boolean] Returns `true` if the string matches the pattern, otherwise `false`.
    delegate :match?, to: :regex

    private

    # @return [Regexp]
    def regex
      ::Regexp.new("^#{::Regexp.escape(@pattern).gsub('\*', '.*').gsub('\?', '.?')}$")
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
eac_ruby_utils-0.124.0 lib/eac_ruby_utils/wildcards.rb
eac_tools-0.97.2 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_ruby_utils-0.123.0 lib/eac_ruby_utils/wildcards.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/wildcards.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/wildcards.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/wildcards.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/wildcards.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/wildcards.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/wildcards.rb