Class: Utils::Patterns::Pattern
Direct Known Subclasses
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the matcher object used for pattern matching.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Pattern
constructor
Initializes a new Pattern instance with the specified options.
-
#method_missing(*a, &b) ⇒ Object
The method_missing method delegates calls to the matcher object while handling UTF-8 encoding errors.
Constructor Details
#initialize(opts = {}) ⇒ Pattern
Initializes a new Pattern instance with the specified options.
This method sets up the pattern configuration by storing the character set, case sensitivity flag, and pattern string. It validates that a pattern is provided and optionally filters the pattern characters based on the specified character set.
17 18 19 20 21 22 23 |
# File 'lib/utils/patterns.rb', line 17 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
The method_missing method delegates calls to the matcher object while handling UTF-8 encoding errors.
This method acts as a fallback handler for undefined method calls, forwarding them to the internal matcher object. It specifically catches ArgumentError exceptions related to invalid byte sequences in UTF-8 and re-raises them unless they match the expected error pattern.
42 43 44 45 46 |
# File 'lib/utils/patterns.rb', line 42 def method_missing(*a, &b) @matcher.__send__(*a, &b) rescue ArgumentError => e raise e unless e..include?('invalid byte sequence in UTF-8') end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the matcher object used for pattern matching.
28 29 30 |
# File 'lib/utils/patterns.rb', line 28 def matcher @matcher end |