Class: Pidgin2Adium::XMLMessage

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

AutoReplyMessage, Event

Instance Attribute Summary collapse

Attributes inherited from Message

#buddy_alias, #sender, #time

Instance Method Summary collapse

Methods inherited from Message

#<=>

Constructor Details

#initialize(sender, time, buddy_alias, body) ⇒ XMLMessage

Returns a new instance of 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

#bodyObject

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.balance_tags_c(@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 “&lt;”, “&gt;”, “&amp;”, “&quot;”, and “&apos;”.



35
36
37
38
# File 'lib/pidgin2adium/messages/xml_message.rb', line 35

def normalize_body_entities!
  # Convert '&' to '&amp;' only if it's not followed by an entity.
  @body.gsub!(/&(?!lt|gt|amp|quot|apos)/, '&amp;')
end

#to_sObject



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