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.
-
#original_text ⇒ Object
Returns the value of attribute original_text.
-
#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 = 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 = nil) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mad_chatter/message.rb', line 8 def initialize(type, text = nil, token = nil, channel = nil) @type = type if text @original_text = text @filtered_text = filter(text) @html = @filtered_text @growl = text end @token = token @channel = channel @add_to_history = true 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 |
#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 |
#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
58 59 60 |
# File 'lib/mad_chatter/message.rb', line 58 def add_to_history? @add_to_history end |
#filter(text) ⇒ Object
54 55 56 |
# File 'lib/mad_chatter/message.rb', line 54 def filter(text) CGI::escapeHTML(text).strip end |
#text ⇒ Object
Helper method for returning filtered text.
39 40 41 |
# File 'lib/mad_chatter/message.rb', line 39 def text @filtered_text end |
#to_json ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mad_chatter/message.rb', line 43 def to_json JSON.generate({ type: @type, text: @original_text, html: @html, username: username, channel: @channel, growl: @growl, }) end |
#user ⇒ Object
34 35 36 |
# File 'lib/mad_chatter/message.rb', line 34 def user MadChatter.find_user_by_token(@token) if @token end |
#username ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/mad_chatter/message.rb', line 25 def username unless @username MadChatter.users.each do |user| @username = user.username if user.has_token?(@token) end end @username end |
#username=(username) ⇒ Object
21 22 23 |
# File 'lib/mad_chatter/message.rb', line 21 def username=(username) @username = username end |