Class: S3PO::Event
- Inherits:
-
Object
- Object
- S3PO::Event
- Defined in:
- lib/s-3po/events.rb
Overview
Base event class; a generic event class should only come from Slack.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #channel ⇒ Object
- #channel=(string) ⇒ Object
-
#initialize(event = {}, opts = {}) ⇒ Event
constructor
A new instance of Event.
-
#is_im? ⇒ Boolean
Is is an IM, direct channel?.
-
#is_message? ⇒ Boolean
Is it a message event?.
-
#is_simplemessage? ⇒ Boolean
Is it a simple message event; a straight forward text message without a subtype?.
- #subtype ⇒ Symbol
- #ts ⇒ Object
- #type ⇒ Symbol
- #user ⇒ Object
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
#object ⇒ Object (readonly)
Returns the value of attribute object.
6 7 8 |
# File 'lib/s-3po/events.rb', line 6 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/s-3po/events.rb', line 7 def @options end |
Instance Method Details
#channel ⇒ Object
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_im? ⇒ Boolean
Is is an IM, direct channel?
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?
24 25 26 |
# File 'lib/s-3po/events.rb', line 24 def return !type.nil? && type == :message end |
#is_simplemessage? ⇒ Boolean
Is it a simple message event; a straight forward text message without a subtype?
36 37 38 |
# File 'lib/s-3po/events.rb', line 36 def && subtype.nil? end |
#subtype ⇒ 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 |
#ts ⇒ Object
60 61 62 |
# File 'lib/s-3po/events.rb', line 60 def ts object[:ts] end |
#type ⇒ 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 |
#user ⇒ Object
40 41 42 |
# File 'lib/s-3po/events.rb', line 40 def user object[:user] end |