Sha256: 84a90eea466e878f21da1f03b6711ea05570b5c44a402ccef071d160cfd9e0d1

Contents?: true

Size: 708 Bytes

Versions: 35

Compression:

Stored size: 708 Bytes

Contents

module Wovnrb
  # inspired by https://github.com/isaacs/node-glob
  #
  # "*" Matches 0 or more characters in a single path portion
  # "**" If a "globstar" is alone in a path portion,
  #   then it matches zero or more directories and subdirectories searching for matches.
  #
  # @note "?" or other pattern is not implemented
  class Glob
    def initialize(pattern)
      sub_directories = pattern.split('/**', -1)
      regexp = sub_directories.map do |sub_dir|
        sub_dir.split('*', -1)
          .map {|p| Regexp.escape(p)}
          .join('[^/]*')
      end.join('(/[^/]*)*')

      @regexp = Regexp.new("^#{regexp}$")
    end

    def match?(url)
      !@regexp.match(url).nil?
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
wovnrb-1.1.0 lib/wovnrb/services/glob.rb
wovnrb-1.0.13 lib/wovnrb/services/glob.rb
wovnrb-1.0.12 lib/wovnrb/services/glob.rb
wovnrb-1.0.11 lib/wovnrb/services/glob.rb
wovnrb-1.0.10 lib/wovnrb/services/glob.rb
wovnrb-1.0.9 lib/wovnrb/services/glob.rb
wovnrb-1.0.8 lib/wovnrb/services/glob.rb
wovnrb-1.0.7 lib/wovnrb/services/glob.rb
wovnrb-1.0.6 lib/wovnrb/services/glob.rb
wovnrb-1.0.5 lib/wovnrb/services/glob.rb
wovnrb-1.0.4 lib/wovnrb/services/glob.rb
wovnrb-1.0.2 lib/wovnrb/services/glob.rb
wovnrb-1.0.1 lib/wovnrb/services/glob.rb
wovnrb-1.0.0 lib/wovnrb/services/glob.rb
wovnrb-0.2.30 lib/wovnrb/services/glob.rb
wovnrb-0.2.29 lib/wovnrb/services/glob.rb
wovnrb-0.2.28 lib/wovnrb/services/glob.rb
wovnrb-0.2.27 lib/wovnrb/services/glob.rb
wovnrb-0.2.26 lib/wovnrb/services/glob.rb
wovnrb-0.2.25 lib/wovnrb/services/glob.rb