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


76
77
78
79
80
81
82
# File 'lib/xmpp4r/delay/x/delay.rb', line 76

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

#from=(jid) ⇒ Object

Set the timestamp’s origin

jid
JID


87
88
89
# File 'lib/xmpp4r/delay/x/delay.rb', line 87

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

#set_from(jid) ⇒ Object

Set the timestamp’s origin (chaining-friendly)



93
94
95
96
# File 'lib/xmpp4r/delay/x/delay.rb', line 93

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

#set_stamp(t) ⇒ Object

Set the timestamp (chaining-friendly)



68
69
70
71
# File 'lib/xmpp4r/delay/x/delay.rb', line 68

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
51
52
53
# File 'lib/xmpp4r/delay/x/delay.rb', line 41

def stamp
  if attributes['stamp']
    begin
      # Actually this should be Time.xmlschema,
      # but "unfortunately, the 'jabber:x:delay' namespace predates" JEP 0082
      Time.parse("#{attributes['stamp']}Z")
    rescue ArgumentError
      nil
    end
  else
    nil
  end
end

#stamp=(t) ⇒ Object

Set the timestamp

t
Time

or nil



58
59
60
61
62
63
64
# File 'lib/xmpp4r/delay/x/delay.rb', line 58

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