class Mobb::Matcher
Public Class Methods
new(pattern, options = {})
click to toggle source
# File lib/mobb/base.rb, line 9 def initialize(pattern, options = {}) @pattern, @options = pattern, options; end
Public Instance Methods
cron?()
click to toggle source
# File lib/mobb/base.rb, line 12 def cron?; pattern.is_a?(CronParser); end
cron_matcher(time)
click to toggle source
# File lib/mobb/base.rb, line 51 def cron_matcher(time) last = last_tick tick(time) if !last || time > last return false if time < last pattern.next(time) == pattern.next(last) ? false : true end
inspect()
click to toggle source
# File lib/mobb/base.rb, line 11 def inspect; "pattern: #{@pattern}, options #{@options}"; end
last_tick()
click to toggle source
# File lib/mobb/base.rb, line 14 def last_tick; @options[:last_tick] end
match?(context)
click to toggle source
# File lib/mobb/base.rb, line 16 def match?(context) case context when String string_matcher(context) when Time cron_matcher(context) when Array context.all? { |c| match?(c) } else false end end
pattern()
click to toggle source
# File lib/mobb/base.rb, line 34 def pattern; @pattern; end
regexp?()
click to toggle source
# File lib/mobb/base.rb, line 10 def regexp?; pattern.is_a?(Regexp); end
string_matcher(string)
click to toggle source
# File lib/mobb/base.rb, line 36 def string_matcher(string) case pattern when Regexp if res = pattern.match(string) Matched.new(pattern, res) else false end when String @options[:laziness] ? string.include?(pattern) : string == pattern else false end end
tick(time = Time.now)
click to toggle source
# File lib/mobb/base.rb, line 13 def tick(time = Time.now) @options[:last_tick] = time; end