Class: Pidgin2Adium::XMLMessage
- Defined in:
- lib/pidgin2adium/messages/xml_message.rb
Overview
Basic message with body text (as opposed to pure status messages, which have no body).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Attributes inherited from Message
Instance Method Summary collapse
-
#initialize(sender, time, buddy_alias, body) ⇒ XMLMessage
constructor
A new instance of XMLMessage.
-
#normalize_body! ⇒ Object
Balances mismatched tags, normalizes body style, and fixes actions so they are in Adium style (Pidgin uses “***Buddy waves at you”, Adium uses “*Buddy waves at you*”).
-
#normalize_body_entities! ⇒ Object
Escapes all entities in @body except for “<”, “>”, “&”, “"”, and “'”.
- #to_s ⇒ Object
Methods inherited from Message
Constructor Details
#initialize(sender, time, buddy_alias, body) ⇒ XMLMessage
5 6 7 8 9 10 |
# File 'lib/pidgin2adium/messages/xml_message.rb', line 5 def initialize(sender, time, buddy_alias, body) super(sender, time, buddy_alias) @body = body @styled_body = '<div><span style="font-family: Helvetica; font-size: 12pt;">%s</span></div>' % @body normalize_body!() end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
11 12 13 |
# File 'lib/pidgin2adium/messages/xml_message.rb', line 11 def body @body end |
Instance Method Details
#normalize_body! ⇒ Object
Balances mismatched tags, normalizes body style, and fixes actions so they are in Adium style (Pidgin uses “***Buddy waves at you”, Adium uses “*Buddy waves at you*”).
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pidgin2adium/messages/xml_message.rb', line 21 def normalize_body! normalize_body_entities!() # Fix mismatched tags. Yes, it's faster to do it per-message # than all at once. @body = Pidgin2Adium.(@body) if @buddy_alias[0,3] == '***' # "***<alias>" is what pidgin sets as the alias for a /me action @buddy_alias.slice!(0,3) @body = '*' << @body << '*' end end |
#normalize_body_entities! ⇒ Object
Escapes all entities in @body except for “<”, “>”, “&”, “"”, and “'”.
35 36 37 38 |
# File 'lib/pidgin2adium/messages/xml_message.rb', line 35 def normalize_body_entities! # Convert '&' to '&' only if it's not followed by an entity. @body.gsub!(/&(?!lt|gt|amp|quot|apos)/, '&') end |
#to_s ⇒ Object
13 14 15 16 |
# File 'lib/pidgin2adium/messages/xml_message.rb', line 13 def to_s return sprintf('<message sender="%s" time="%s" alias="%s">%s</message>' << "\n", @sender, @time, @buddy_alias, @styled_body) end |