class Blather::Stanza::Iq::Si::Si::File

File stanza fragment

Public Class Methods

find_or_create(parent) click to toggle source

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

@param [Si::Si] parent a si node where to find or create file

@return [Si::Si::File]

# 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) click to toggle source

Create a new Si::Si::File object

@param [XML::Node, nil] node a node to inherit from

@return [Si::Si::File]

Calls superclass method
# 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

Public Instance Methods

date() click to toggle source

Get the date

@return [Time, nil]

# File lib/blather/stanza/iq/si.rb, line 282
def date
  begin
    Time.xmlschema(read_attr(:date))
  rescue ArgumentError
    nil
  end
end
date=(date) click to toggle source

Set the date

@param [Time, nil] date the last modification time of the file

# File lib/blather/stanza/iq/si.rb, line 293
def date=(date)
  write_attr :date, (date ? date.xmlschema : nil)
end
desc() click to toggle source

Get the desc

@return [String, nil]

# File lib/blather/stanza/iq/si.rb, line 318
def desc
  content_from 'ns:desc', :ns => self.class.registered_ns
end
desc=(desc) click to toggle source

Set the desc

@param [String, nil] desc the description of the file

# File lib/blather/stanza/iq/si.rb, line 325
def desc=(desc)
  set_content_for :desc, desc
end
hash() click to toggle source

Get the hash

@return [String, nil]

# File lib/blather/stanza/iq/si.rb, line 268
def hash
  read_attr :hash
end
hash=(hash) click to toggle source

Set the hash

@param [String, nil] hash the MD5 hash of the file

# File lib/blather/stanza/iq/si.rb, line 275
def hash=(hash)
  write_attr :hash, hash
end
name() click to toggle source

Get the filename

@return [String, nil]

# File lib/blather/stanza/iq/si.rb, line 254
def name
  read_attr :name
end
name=(name) click to toggle source

Set the filename

@param [String, nil] name the name of the file

# File lib/blather/stanza/iq/si.rb, line 261
def name=(name)
  write_attr :name, name
end
range() click to toggle source

Find or create range node

@return [Si::Si::File::Range]

# File lib/blather/stanza/iq/si.rb, line 332
def range
  Range.find_or_create self
end
size() click to toggle source

Get the size

@return [Fixnum, nil]

# 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) click to toggle source

Set the size

@param [Fixnum, nil] size the size, in bytes, of the file

# File lib/blather/stanza/iq/si.rb, line 311
def size=(size)
  write_attr :size, size
end