Class: FFIDB::Glob

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, ignore_case: nil, match_substring: nil) ⇒ Glob

Returns a new instance of Glob.



8
9
10
11
12
13
14
# File 'lib/ffidb/glob.rb', line 8

def initialize(pattern, ignore_case: nil, match_substring: nil)
  @pattern = pattern.to_s
  regexp_pattern = Regexp.escape(@pattern).gsub('\*', '.*').gsub('\?', '.')
  regexp_pattern = "^#{regexp_pattern}$" unless match_substring
  regexp_options = ignore_case ? Regexp::IGNORECASE : nil
  @compiled = Regexp.new(regexp_pattern, regexp_options)
end

Instance Attribute Details

#compiledObject (readonly)

Returns the value of attribute compiled.



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

def compiled
  @compiled
end

#patternObject (readonly)

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

Instance Method Details

#===(string) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ffidb/glob.rb', line 24

def ===(string)
  self.compiled === string
end

#to_sString

Returns:

  • (String)


18
19
20
# File 'lib/ffidb/glob.rb', line 18

def to_s
  self.pattern
end