Class: Diligence::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/diligence/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, matcher:, handler:) ⇒ Route

Returns a new instance of Route.



7
8
9
10
11
# File 'lib/diligence/route.rb', line 7

def initialize(type:, matcher:, handler:)
  @type = type
  @matcher = matcher
  @handler = handler
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



5
6
7
# File 'lib/diligence/route.rb', line 5

def handler
  @handler
end

#matcherObject (readonly)

Returns the value of attribute matcher.



5
6
7
# File 'lib/diligence/route.rb', line 5

def matcher
  @matcher
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/diligence/route.rb', line 5

def type
  @type
end

Instance Method Details

#match(message_update) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/diligence/route.rb', line 13

def match(message_update)
  result = (
    case @type
    when :chat_id
      match_chat_id?(message_update)
    when :user_id
      match_user_id?(message_update)
    when :chat_type
      match_chat_type?(message_update)
    when :message_type
      match_message_type?(message_update)
    when :text_pattern
      match_text_pattern?(message_update)
    when :default
      true
    else
      false
    end
  )

  result ? @handler : nil
end