Class: Goodcheck::Glob

Inherits:
Object
  • Object
show all
Defined in:
lib/goodcheck/glob.rb

Constant Summary collapse

FNM_FLAGS =
File::FNM_PATHNAME | File::FNM_EXTGLOB | File::FNM_DOTMATCH

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern:, encoding:, exclude:) ⇒ Glob

Returns a new instance of Glob.



9
10
11
12
13
# File 'lib/goodcheck/glob.rb', line 9

def initialize(pattern:, encoding:, exclude:)
  @pattern = pattern
  @encoding = encoding
  @exclude = exclude
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



6
7
8
# File 'lib/goodcheck/glob.rb', line 6

def encoding
  @encoding
end

#excludeObject (readonly)

Returns the value of attribute exclude.



7
8
9
# File 'lib/goodcheck/glob.rb', line 7

def exclude
  @exclude
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/goodcheck/glob.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
23
24
# File 'lib/goodcheck/glob.rb', line 19

def ==(other)
  other.is_a?(Glob) &&
    other.pattern == pattern &&
    other.encoding == encoding &&
    other.exclude == exclude
end

#test(path) ⇒ Object



15
16
17
# File 'lib/goodcheck/glob.rb', line 15

def test(path)
  path.fnmatch?(pattern, FNM_FLAGS) && !excluded?(path)
end