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-0.2.24 lib/wovnrb/services/glob.rb
wovnrb-0.2.23 lib/wovnrb/services/glob.rb
wovnrb-0.2.22 lib/wovnrb/services/glob.rb
wovnrb-0.2.21 lib/wovnrb/services/glob.rb
wovnrb-0.2.20 lib/wovnrb/services/glob.rb
wovnrb-0.2.19 lib/wovnrb/services/glob.rb
wovnrb-0.2.18 lib/wovnrb/services/glob.rb
wovnrb-0.2.17 lib/wovnrb/services/glob.rb
wovnrb-0.2.16 lib/wovnrb/services/glob.rb
wovnrb-0.2.15 lib/wovnrb/services/glob.rb
wovnrb-0.2.14 lib/wovnrb/services/glob.rb
wovnrb-0.2.13 lib/wovnrb/services/glob.rb
wovnrb-0.2.12 lib/wovnrb/services/glob.rb
wovnrb-0.2.11 lib/wovnrb/services/glob.rb
wovnrb-0.2.10 lib/wovnrb/services/glob.rb