Class: Bot::Responder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, ActionView::Helpers::TextHelper
Defined in:
lib/bot/responder.rb

Direct Known Subclasses

ApplicationResponder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, user, responses, handler, analytics, user_context, chat_context) ⇒ Responder

Returns a new instance of Responder.



16
17
18
19
20
21
22
23
24
# File 'lib/bot/responder.rb', line 16

def initialize(message, user, responses, handler, analytics, user_context, chat_context)
  @message = message
  @user = user
  @responses = responses
  @handler = handler
  @analytics = analytics
  @user_context = user_context
  @chat_context = chat_context
end

Instance Attribute Details

#analyticsObject (readonly)

Returns the value of attribute analytics.



8
9
10
# File 'lib/bot/responder.rb', line 8

def analytics
  @analytics
end

#chat_contextObject (readonly)

Returns the value of attribute chat_context.



8
9
10
# File 'lib/bot/responder.rb', line 8

def chat_context
  @chat_context
end

#handlerObject (readonly)

Returns the value of attribute handler.



8
9
10
# File 'lib/bot/responder.rb', line 8

def handler
  @handler
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/bot/responder.rb', line 8

def message
  @message
end

#responsesObject (readonly)

Returns the value of attribute responses.



8
9
10
# File 'lib/bot/responder.rb', line 8

def responses
  @responses
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/bot/responder.rb', line 8

def user
  @user
end

#user_contextObject (readonly)

Returns the value of attribute user_context.



8
9
10
# File 'lib/bot/responder.rb', line 8

def user_context
  @user_context
end

Class Method Details

.respond_to(*types) ⇒ Object



10
11
12
13
14
# File 'lib/bot/responder.rb', line 10

def self.respond_to(*types)
  new_types = (respond_to_types || []).dup
  types.each { |type| new_types << type.to_s }.uniq
  self.respond_to_types = new_types.freeze
end

Instance Method Details

#can_handle?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/bot/responder.rb', line 31

def can_handle?
  !responses.count
end

#can_respond_to_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/bot/responder.rb', line 26

def can_respond_to_type?(type)
  valid_message_types = self.class.respond_to_types || ['text']
  valid_message_types.include?(type)
end

#handleObject

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/bot/responder.rb', line 35

def handle
  raise NotImplementedError
end