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 = {}, opts = {}) ⇒ Event

Returns a new instance of Event


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

def initialize(event = {}, opts = {})
  fail 'Must be a Hash.' unless event.class == Hash
  @object = event
  @options = opts
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

#optionsObject (readonly)

Returns the value of attribute options


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

def options
  @options
end

Instance Method Details

#channelObject


50
51
52
# File 'lib/s-3po/events.rb', line 50

def channel
  object[:channel]
end

#channel=(string) ⇒ Object


54
55
56
57
58
# File 'lib/s-3po/events.rb', line 54

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_hidden?Boolean

Is it a hidden event?

Returns:

  • (Boolean)

66
67
68
# File 'lib/s-3po/events.rb', line 66

def is_hidden?
  object[:hidden] ? true : false
end

#is_im?Boolean

Is is an IM, direct channel?

Returns:

  • (Boolean)

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

def is_im?
  !object[:channel].nil? && channel.start_with?('D')
end

#is_message?Boolean

Is it a message event?

Returns:

  • (Boolean)

24
25
26
# File 'lib/s-3po/events.rb', line 24

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)

36
37
38
# File 'lib/s-3po/events.rb', line 36

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

#subtypeSymbol

Returns:

  • (Symbol)

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

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

#tsObject


60
61
62
# File 'lib/s-3po/events.rb', line 60

def ts
  object[:ts]
end

#typeSymbol

Returns:

  • (Symbol)

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

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

#userObject


40
41
42
# File 'lib/s-3po/events.rb', line 40

def user
  object[:user]
end