Class: Mobb::Matcher
- Inherits:
-
Object
- Object
- Mobb::Matcher
- Defined in:
- lib/mobb/base.rb
Defined Under Namespace
Classes: Matched
Instance Method Summary collapse
-
#initialize(pattern, options) ⇒ Matcher
constructor
A new instance of Matcher.
- #inspect ⇒ Object
- #invoke(time = Time.now) ⇒ Object
- #match?(context) ⇒ Boolean
- #pattern ⇒ Object
- #regexp? ⇒ Boolean
- #string_matcher(string) ⇒ Object
Constructor Details
#initialize(pattern, options) ⇒ Matcher
Returns a new instance of Matcher.
6 |
# File 'lib/mobb/base.rb', line 6 def initialize(pattern, ) @pattern, @options = pattern, ; end |
Instance Method Details
#inspect ⇒ Object
8 |
# File 'lib/mobb/base.rb', line 8 def inspect; "pattern: #{@pattern}, options #{@options}"; end |
#invoke(time = Time.now) ⇒ Object
9 |
# File 'lib/mobb/base.rb', line 9 def invoke(time = Time.now) @options[:last_invoked] = time; end |
#match?(context) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mobb/base.rb', line 11 def match?(context) case context when String string_matcher(context) when Time # TODO: do something false when Array context.all? { |c| match?(c) } else false end end |
#pattern ⇒ Object
30 |
# File 'lib/mobb/base.rb', line 30 def pattern; @pattern; end |
#regexp? ⇒ Boolean
7 |
# File 'lib/mobb/base.rb', line 7 def regexp?; pattern.is_a?(Regexp); end |
#string_matcher(string) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mobb/base.rb', line 32 def string_matcher(string) case pattern when Regexp if res = pattern.match(string) Matched.new(pattern, res.captures) else false end when String @options[:laziness] ? string.include?(pattern) : string == pattern else false end end |