Class: Pidgin2Adium::XMLMessage
- Defined in:
- lib/pidgin2adium/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 entities.
- #to_s ⇒ Object
Constructor Details
#initialize(sender, time, buddy_alias, body) ⇒ XMLMessage
Returns a new instance of XMLMessage.
26 27 28 29 30 31 |
# File 'lib/pidgin2adium/message.rb', line 26 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.
32 33 34 |
# File 'lib/pidgin2adium/message.rb', line 32 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*”).
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pidgin2adium/message.rb', line 42 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 entities.
55 56 57 58 |
# File 'lib/pidgin2adium/message.rb', line 55 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
34 35 36 37 |
# File 'lib/pidgin2adium/message.rb', line 34 def to_s return sprintf('<message sender="%s" time="%s" alias="%s">%s</message>' << "\n", @sender, @time, @buddy_alias, @styled_body) end |