Class: Waylon::Conditions::Regex

Inherits:
Waylon::Condition show all
Defined in:
lib/waylon/conditions/regex.rb

Overview

Routing via Regular Expression

Instance Attribute Summary

Attributes inherited from Waylon::Condition

#action, #help, #mechanism

Instance Method Summary collapse

Methods inherited from Waylon::Condition

#initialize, #mention_only?, #permits?, #properly_mentions?

Constructor Details

This class inherits a constructor from Waylon::Condition

Instance Method Details

#matches?(message) ⇒ Boolean

Checks if this condition matches the message

Parameters:

  • message (String)

    The message text

Returns:

  • (Boolean)


10
11
12
# File 'lib/waylon/conditions/regex.rb', line 10

def matches?(message)
  @mechanism =~ message
end

#named_tokens(input) ⇒ Hash<Symbol,String>

Provides the named regular expression match groups as a hash

Parameters:

  • input (String)

    The message text

Returns:

  • (Hash<Symbol,String>)

    The named regular expression match groups



24
25
26
27
# File 'lib/waylon/conditions/regex.rb', line 24

def named_tokens(input)
  match_data = @mechanism.match(input)
  match_data.names.to_h { |n| [n.to_sym, match_data[n]] }
end

#tokens(input) ⇒ Array<String>

Provides the regular expression match groups as tokens

Parameters:

  • input (String)

    The message text

Returns:

  • (Array<String>)

    The regular expression match groups



17
18
19
# File 'lib/waylon/conditions/regex.rb', line 17

def tokens(input)
  @mechanism.match(input).to_a[1..]
end