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, context, analytics) ⇒ Responder

Returns a new instance of Responder.



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

def initialize(message, user, responses, handler, context, analytics)
  @message = message
  @user = user
  @responses = responses
  @handler = handler
  @context = context
  @analytics = analytics
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

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @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

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)


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

def can_handle?
  !responses.count
end

#can_respond_to_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#handleObject

Raises:

  • (NotImplementedError)


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

def handle
  raise NotImplementedError
end