Class: MadChatter::Message
- Inherits:
-
Object
- Object
- MadChatter::Message
- Defined in:
- lib/mad_chatter/message.rb
Instance Attribute Summary collapse
-
#add_to_history ⇒ Object
Returns the value of attribute add_to_history.
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#filtered_text ⇒ Object
Returns the value of attribute filtered_text.
-
#growl ⇒ Object
Returns the value of attribute growl.
-
#html ⇒ Object
Returns the value of attribute html.
-
#json ⇒ Object
Returns the value of attribute json.
-
#original_text ⇒ Object
Returns the value of attribute original_text.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#token ⇒ Object
Returns the value of attribute token.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_to_history? ⇒ Boolean
- #filter(text) ⇒ Object
-
#initialize(type, text = nil, token = nil, channel_id = nil) ⇒ Message
constructor
A new instance of Message.
-
#text ⇒ Object
Helper method for returning filtered text.
- #to_json ⇒ Object
- #user ⇒ Object
- #username ⇒ Object
- #username=(username) ⇒ Object
Constructor Details
#initialize(type, text = nil, token = nil, channel_id = nil) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mad_chatter/message.rb', line 8 def initialize(type, text = nil, token = nil, channel_id = nil) @type = type if text @original_text = text @filtered_text = filter(text) @html = @filtered_text @growl = text end @token = token @channel = channel_id @add_to_history = true @timestamp = Time.now.to_i end |
Instance Attribute Details
#add_to_history ⇒ Object
Returns the value of attribute add_to_history.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def add_to_history @add_to_history end |
#channel ⇒ Object
Returns the value of attribute channel.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def channel @channel end |
#filtered_text ⇒ Object
Returns the value of attribute filtered_text.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def filtered_text @filtered_text end |
#growl ⇒ Object
Returns the value of attribute growl.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def growl @growl end |
#html ⇒ Object
Returns the value of attribute html.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def html @html end |
#json ⇒ Object
Returns the value of attribute json.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def json @json end |
#original_text ⇒ Object
Returns the value of attribute original_text.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def original_text @original_text end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def @timestamp end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def token @token end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/mad_chatter/message.rb', line 6 def type @type end |
Instance Method Details
#add_to_history? ⇒ Boolean
61 62 63 |
# File 'lib/mad_chatter/message.rb', line 61 def add_to_history? @add_to_history end |
#filter(text) ⇒ Object
57 58 59 |
# File 'lib/mad_chatter/message.rb', line 57 def filter(text) CGI::escapeHTML(text).strip end |
#text ⇒ Object
Helper method for returning filtered text.
40 41 42 |
# File 'lib/mad_chatter/message.rb', line 40 def text @filtered_text end |
#to_json ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mad_chatter/message.rb', line 44 def to_json JSON.generate({ type: @type, text: @original_text, html: @html, json: @json, username: username, channel: @channel, growl: @growl, time: @timestamp }) end |
#user ⇒ Object
35 36 37 |
# File 'lib/mad_chatter/message.rb', line 35 def user MadChatter.find_user_by_token(@token) if @token end |
#username ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/mad_chatter/message.rb', line 26 def username unless @username MadChatter.users.each do |user| @username = user.username if user.has_token?(@token) end end @username end |
#username=(username) ⇒ Object
22 23 24 |
# File 'lib/mad_chatter/message.rb', line 22 def username=(username) @username = username end |