Class: Cuboid::Support::Glob

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

Overview

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(glob) ⇒ Glob

Returns a new instance of Glob.



14
15
16
# File 'lib/cuboid/support/glob.rb', line 14

def initialize( glob )
    @regexp = self.class.to_regexp( glob )
end

Instance Attribute Details

#regexpObject (readonly)

Returns the value of attribute regexp.



12
13
14
# File 'lib/cuboid/support/glob.rb', line 12

def regexp
  @regexp
end

Class Method Details

.to_regexp(glob) ⇒ Object



7
8
9
10
# File 'lib/cuboid/support/glob.rb', line 7

def self.to_regexp( glob )
    escaped = Regexp.escape( glob ).gsub( '\*', '.*?' )
    Regexp.new( "^#{escaped}$", Regexp::IGNORECASE )
end

Instance Method Details

#=~(str) ⇒ Object Also known as: matches?



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

def =~( str )
    @regexp.match? str
end