Class: Utils::Patterns::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/patterns.rb

Direct Known Subclasses

FuzzyPattern, RegexpPattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Pattern

Returns a new instance of Pattern.



4
5
6
7
8
9
10
# File 'lib/utils/patterns.rb', line 4

def initialize(opts = {})
  @cset    = opts[:cset]
  @icase   = opts[:icase]
  @pattern = opts[:pattern] or
    raise ArgumentError, "pattern option required"
  @pattern = @pattern.gsub(/[^#{@cset}]/, '') if @cset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*a, &b) ⇒ Object



14
15
16
17
18
# File 'lib/utils/patterns.rb', line 14

def method_missing(*a, &b)
  @matcher.__send__(*a, &b)
rescue ArgumentError => e
  raise e unless e.message.include?('invalid byte sequence in UTF-8')
end

Instance Attribute Details

#matcherObject (readonly)

Returns the value of attribute matcher.



12
13
14
# File 'lib/utils/patterns.rb', line 12

def matcher
  @matcher
end