Class: S3PO::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/s-3po/events.rb

Overview

Base event class; a generic event class should only come from Slack.

Direct Known Subclasses

Message, Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event = {}) ⇒ Event

Returns a new instance of Event.



8
9
10
11
# File 'lib/s-3po/events.rb', line 8

def initialize(event = {})
  fail 'Must be a Hash.' unless event.class == Hash
  @object = event
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



6
7
8
# File 'lib/s-3po/events.rb', line 6

def object
  @object
end

Instance Method Details

#channelObject



42
43
44
# File 'lib/s-3po/events.rb', line 42

def channel
  object[:channel]
end

#channel=(string) ⇒ Object



46
47
48
49
50
# File 'lib/s-3po/events.rb', line 46

def channel=(string)
  fail 'Must be a String.' unless string.class == String
  fail 'Invalid channel' unless /[CD][0-9A-Z]+/ =~ string
  object[:channel] = string
end

#is_message?Boolean

Is it a message event?

Returns:

  • (Boolean)


22
23
24
# File 'lib/s-3po/events.rb', line 22

def is_message?
  return !type.nil? && type == :message
end

#is_simplemessage?Boolean

Is it a simple message event; a straight forward text message without a subtype?

Returns:

  • (Boolean)


34
35
36
# File 'lib/s-3po/events.rb', line 34

def is_simplemessage?
  is_message? && subtype.nil?
end

#subtypeSymbol

Returns:

  • (Symbol)


27
28
29
30
# File 'lib/s-3po/events.rb', line 27

def subtype
  return object[:subtype].to_sym if object[:subtype]
  return nil
end

#tsObject



52
53
54
# File 'lib/s-3po/events.rb', line 52

def ts
  object[:ts]
end

#typeSymbol

Returns:

  • (Symbol)


14
15
16
17
18
# File 'lib/s-3po/events.rb', line 14

def type
  return :response unless object[:ok].nil?
  return object[:type].to_sym if object[:type]
  return nil
end

#userObject



38
39
40
# File 'lib/s-3po/events.rb', line 38

def user
  object[:user]
end