Class: Connfu::Message
- Inherits:
-
Object
- Object
- Connfu::Message
- Defined in:
- lib/connfu/message.rb
Overview
This class provides the relevant information got from an external event
Constant Summary collapse
- VOICE_TYPES =
valid voice messages
["join", "leave", "new_topic"]
- SMS_TYPES =
valid sms messages
["sms"]
Instance Attribute Summary collapse
-
#channel_name ⇒ Object
specific channel (twitter account, etc).
-
#channel_type ⇒ Object
readonly
twitter, voice, sms, rss, etc.
-
#content ⇒ Object
readonly
main content.
-
#from ⇒ Object
readonly
sender.
-
#id ⇒ Object
readonly
external identifier.
-
#message_type ⇒ Object
readonly
new, join.
-
#to ⇒ Object
readonly
receiver.
Class Method Summary collapse
-
.is_sms?(type) ⇒ Boolean
Checks if a message is a valid sms message (If it is included in SMS_TYPES) ==== Parameters *
typemessage type ==== Return true if the message is a sms message, false if not. -
.is_voice?(type) ⇒ Boolean
Checks if a message is a valid voice message (If it is included in VOICE_TYPES) ==== Parameters *
typemessage type ==== Return true if the message is a voice message, false if not.
Instance Method Summary collapse
-
#[](value) ⇒ Object
Retrieve an attribute using a Hash approach ==== Parameters *
valueattribute name ==== Return attribute value. -
#initialize(params) ⇒ Message
constructor
Initializer.
-
#to_s ⇒ Object
Trying to show the information properly.
Constructor Details
#initialize(params) ⇒ Message
Initializer
25 26 27 28 29 |
# File 'lib/connfu/message.rb', line 25 def initialize(params) params.each_pair { |key, value| self.instance_variable_set("@#{key}", value) } end |
Instance Attribute Details
#channel_name ⇒ Object
specific channel (twitter account, etc)
21 22 23 |
# File 'lib/connfu/message.rb', line 21 def channel_name @channel_name end |
#channel_type ⇒ Object (readonly)
twitter, voice, sms, rss, etc
20 21 22 |
# File 'lib/connfu/message.rb', line 20 def channel_type @channel_type end |
#content ⇒ Object (readonly)
main content
16 17 18 |
# File 'lib/connfu/message.rb', line 16 def content @content end |
#from ⇒ Object (readonly)
sender
17 18 19 |
# File 'lib/connfu/message.rb', line 17 def from @from end |
#id ⇒ Object (readonly)
external identifier
15 16 17 |
# File 'lib/connfu/message.rb', line 15 def id @id end |
#message_type ⇒ Object (readonly)
new, join
19 20 21 |
# File 'lib/connfu/message.rb', line 19 def @message_type end |
#to ⇒ Object (readonly)
receiver
18 19 20 |
# File 'lib/connfu/message.rb', line 18 def to @to end |
Class Method Details
.is_sms?(type) ⇒ Boolean
Checks if a message is a valid sms message (If it is included in SMS_TYPES)
Parameters
-
typemessage type
Return
true if the message is a sms message, false if not
68 69 70 |
# File 'lib/connfu/message.rb', line 68 def is_sms?(type) SMS_TYPES.include?(type) end |
.is_voice?(type) ⇒ Boolean
Checks if a message is a valid voice message (If it is included in VOICE_TYPES)
Parameters
-
typemessage type
Return
true if the message is a voice message, false if not
58 59 60 |
# File 'lib/connfu/message.rb', line 58 def is_voice?(type) VOICE_TYPES.include?(type) end |
Instance Method Details
#[](value) ⇒ Object
Retrieve an attribute using a Hash approach
Parameters
-
valueattribute name
Return
attribute value
47 48 49 |
# File 'lib/connfu/message.rb', line 47 def [](value) self.instance_variable_get("@#{value.to_s}") end |
#to_s ⇒ Object
Trying to show the information properly
33 34 35 36 37 38 39 |
# File 'lib/connfu/message.rb', line 33 def to_s value = [] self.instance_variables.each { |var| value << "#{var[1..-1]}: #{self.instance_variable_get(var)}" } value.join("; ").to_s end |