Class: Tochtli::BaseController::KeyPattern
- Inherits:
-
Object
- Object
- Tochtli::BaseController::KeyPattern
- 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
- #!~(key) ⇒ Object
- #=~(key) ⇒ Object
-
#initialize(pattern) ⇒ KeyPattern
constructor
A new instance of KeyPattern.
- #to_s ⇒ Object
Constructor Details
#initialize(pattern) ⇒ KeyPattern
Returns a new instance of KeyPattern.
338 339 340 341 342 343 344 345 346 347 |
# File 'lib/tochtli/base_controller.rb', line 338 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
357 358 359 |
# File 'lib/tochtli/base_controller.rb', line 357 def !~(key) !(self =~ key) end |
#=~(key) ⇒ Object
349 350 351 352 353 354 355 |
# File 'lib/tochtli/base_controller.rb', line 349 def =~(key) if @simple @pattern == key else @pattern =~ key end end |
#to_s ⇒ Object
361 362 363 |
# File 'lib/tochtli/base_controller.rb', line 361 def to_s @str end |