File: matcher.rb

package info (click to toggle)
ruby-glob 0.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 156 kB
  • sloc: ruby: 129; makefile: 7; sh: 4
file content (27 lines) | stat: -rw-r--r-- 442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module Glob
  class Matcher
    attr_reader :path, :regex

    def initialize(path)
      @path = path
      @reject = path.start_with?("!")

      pattern = Regexp.escape(path.gsub(/^!/, "")).gsub(/\\\*/, "[^.]+")
      @regex = Regexp.new("^#{pattern}")
    end

    def match?(other)
      other.match?(regex)
    end

    def include?
      !reject?
    end

    def reject?
      @reject
    end
  end
end