Class: Blather::Stanza::Iq::Si::Si::File

Inherits:
XMPPNode
  • Object
show all
Defined in:
lib/blather/stanza/iq/si.rb

Overview

File stanza fragment

Constant Summary

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XMPPNode

class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza

Class Method Details

.find_or_create(parent) ⇒ Si::Si::File

Find or create file node in si node and converts it to Si::Si::File

Parameters:

  • parent (Si::Si)

    a si node where to find or create file

Returns:



239
240
241
242
243
244
245
246
247
248
249
# File 'lib/blather/stanza/iq/si.rb', line 239

def self.find_or_create(parent)
  if found_file = parent.find_first('//ns:file', :ns => self.registered_ns)
    file = self.new found_file
    found_file.remove
  else
    file = self.new
  end
  parent << file

  file
end

.new(name = nil, size = nil) ⇒ Si::Si::File

Create a new Si::Si::File object

Parameters:

  • node (XML::Node, nil)

    a node to inherit from

Returns:



221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/blather/stanza/iq/si.rb', line 221

def self.new(name = nil, size = nil)
  new_node = super :file

  case name
  when Nokogiri::XML::Node
    new_node.inherit name
  else
    new_node.name = name
    new_node.size = size
  end
  new_node
end

Instance Method Details

#dateTime?

Get the date

Returns:

  • (Time, nil)


282
283
284
285
286
287
288
# File 'lib/blather/stanza/iq/si.rb', line 282

def date
  begin
    Time.xmlschema(read_attr(:date))
  rescue ArgumentError
    nil
  end
end

#date=(date) ⇒ Object

Set the date

Parameters:

  • date (Time, nil)

    the last modification time of the file



293
294
295
# File 'lib/blather/stanza/iq/si.rb', line 293

def date=(date)
  write_attr :date, (date ? date.xmlschema : nil)
end

#descString?

Get the desc

Returns:

  • (String, nil)


318
319
320
# File 'lib/blather/stanza/iq/si.rb', line 318

def desc
  content_from 'ns:desc', :ns => self.class.registered_ns
end

#desc=(desc) ⇒ Object

Set the desc

Parameters:

  • desc (String, nil)

    the description of the file



325
326
327
# File 'lib/blather/stanza/iq/si.rb', line 325

def desc=(desc)
  set_content_for :desc, desc
end

#hashString?

Get the hash

Returns:

  • (String, nil)


268
269
270
# File 'lib/blather/stanza/iq/si.rb', line 268

def hash
  read_attr :hash
end

#hash=(hash) ⇒ Object

Set the hash

Parameters:

  • hash (String, nil)

    the MD5 hash of the file



275
276
277
# File 'lib/blather/stanza/iq/si.rb', line 275

def hash=(hash)
  write_attr :hash, hash
end

#nameString?

Get the filename

Returns:

  • (String, nil)


254
255
256
# File 'lib/blather/stanza/iq/si.rb', line 254

def name
  read_attr :name
end

#name=(name) ⇒ Object

Set the filename

Parameters:

  • name (String, nil)

    the name of the file



261
262
263
# File 'lib/blather/stanza/iq/si.rb', line 261

def name=(name)
  write_attr :name, name
end

#rangeSi::Si::File::Range

Find or create range node

Returns:

  • (Si::Si::File::Range)


332
333
334
# File 'lib/blather/stanza/iq/si.rb', line 332

def range
  Range.find_or_create self
end

#sizeFixnum?

Get the size

Returns:

  • (Fixnum, nil)


300
301
302
303
304
305
306
# File 'lib/blather/stanza/iq/si.rb', line 300

def size
  if (s = read_attr(:size)) && (s =~ /^\d+$/)
    s.to_i
  else
    nil
  end
end

#size=(size) ⇒ Object

Set the size

Parameters:

  • size (Fixnum, nil)

    the size, in bytes, of the file



311
312
313
# File 'lib/blather/stanza/iq/si.rb', line 311

def size=(size)
  write_attr :size, size
end