Class: Tochtli::BaseController::KeyPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/tochtli/base_controller.rb

Constant Summary collapse

ASTERIX_EXP =
'[a-zA-Z0-9]+'
HASH_EXP =
'[a-zA-Z0-9\.]*'

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ KeyPattern

Returns a new instance of KeyPattern.



332
333
334
335
336
337
338
339
340
341
# File 'lib/tochtli/base_controller.rb', line 332

def initialize(pattern)
        @str = pattern
        @simple = !pattern.include?('*') && !pattern.include?('#')
        if @simple
@pattern = pattern
        else
@pattern = Regexp.new('^' + pattern.gsub('.', '\\.').
    gsub('*', ASTERIX_EXP).gsub(/(\\\.)?#(\\\.)?/, HASH_EXP) + '$')
        end
end

Instance Method Details

#!~(key) ⇒ Object



351
352
353
# File 'lib/tochtli/base_controller.rb', line 351

def !~(key)
 !(self =~ key)
end

#=~(key) ⇒ Object



343
344
345
346
347
348
349
# File 'lib/tochtli/base_controller.rb', line 343

def =~(key)
        if @simple
@pattern == key
        else
@pattern =~ key
        end
end

#to_sObject



355
356
357
# File 'lib/tochtli/base_controller.rb', line 355

def to_s
 @str
end