Class: Jabber::Delay::XDelay

Inherits:
X show all
Defined in:
lib/xmpp4r/delay/x/delay.rb

Overview

Implementation of JEP 0091 for <x xmlns='jabber:x:delay' stamp='…' …/> applied on <message/> and <presence/> stanzas

One may also use XDelay#text for a descriptive reason for the delay.

Please note that you must require 'xmpp4r/xdelay' to use this class as it's not required by a basic XMPP implementation. <x/> elements with the specific namespace will then be converted to XDelay automatically.

Instance Method Summary collapse

Methods inherited from XMPPElement

class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=

Methods inherited from REXML::Element

#==, #delete_elements, #each_elements, #first_element, #first_element_content, #first_element_text, #import, import, #replace_element_content, #replace_element_text, #typed_add

Constructor Details

#initialize(insertnow = true) ⇒ XDelay

Initialize a new XDelay element

insertnow
Boolean

Set the stamp to [Time::now]



30
31
32
33
34
35
36
# File 'lib/xmpp4r/delay/x/delay.rb', line 30

def initialize(insertnow=true)
  super()

  if insertnow
    set_stamp(Time.now)
  end
end

Instance Method Details

#fromObject

Get the timestamp's origin

result
JID


73
74
75
76
77
78
79
# File 'lib/xmpp4r/delay/x/delay.rb', line 73

def from
  if attributes['from']
    JID.new(attributes['from'])
  else
    nil
  end
end

#from=(jid) ⇒ Object

Set the timestamp's origin

jid
JID


84
85
86
# File 'lib/xmpp4r/delay/x/delay.rb', line 84

def from=(jid)
  attributes['from'] = jid.nil? ? nil : jid.to_s
end

#set_from(jid) ⇒ Object

Set the timestamp's origin (chaining-friendly)



90
91
92
93
# File 'lib/xmpp4r/delay/x/delay.rb', line 90

def set_from(jid)
  self.from = jid
  self
end

#set_stamp(t) ⇒ Object

Set the timestamp (chaining-friendly)



65
66
67
68
# File 'lib/xmpp4r/delay/x/delay.rb', line 65

def set_stamp(t)
  self.stamp = t
  self
end

#stampObject

Get the timestamp

result
Time

or nil



41
42
43
44
45
46
47
48
49
50
# File 'lib/xmpp4r/delay/x/delay.rb', line 41

def stamp
  if attributes['stamp']
    begin
      # XEP-0091 has been marked obsolete; replaced by XEP-0203
      Time.xmlschema("#{attributes['stamp']}")
    rescue ArgumentError
      nil
    end
  end
end

#stamp=(t) ⇒ Object

Set the timestamp

t
Time

or nil



55
56
57
58
59
60
61
# File 'lib/xmpp4r/delay/x/delay.rb', line 55

def stamp=(t)
  if t.nil?
    attributes['stamp'] = nil
  else
    attributes['stamp'] = t.getutc.strftime("%Y-%m-%dT%H:%M:%SZ")
  end
end