Class: Connfu::Message

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject

specific channel (twitter account, etc)



21
22
23
# File 'lib/connfu/message.rb', line 21

def channel_name
  @channel_name
end

#channel_typeObject (readonly)

twitter, voice, sms, rss, etc



20
21
22
# File 'lib/connfu/message.rb', line 20

def channel_type
  @channel_type
end

#contentObject (readonly)

main content



16
17
18
# File 'lib/connfu/message.rb', line 16

def content
  @content
end

#fromObject (readonly)

sender



17
18
19
# File 'lib/connfu/message.rb', line 17

def from
  @from
end

#idObject (readonly)

external identifier



15
16
17
# File 'lib/connfu/message.rb', line 15

def id
  @id
end

#message_typeObject (readonly)

new, join



19
20
21
# File 'lib/connfu/message.rb', line 19

def message_type
  @message_type
end

#toObject (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

  • type message type

Return

true if the message is a sms message, false if not

Returns:

  • (Boolean)


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

  • type message type

Return

true if the message is a voice message, false if not

Returns:

  • (Boolean)


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

  • value attribute 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_sObject

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