class Blather::Stanza::Iq::Si::Si::File
File
stanza fragment
Public Class Methods
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
Create a new Si::Si::File
object
@param [XML::Node, nil] node a node to inherit from
@return [Si::Si::File]
# 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
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
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
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
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
Get the hash
@return [String, nil]
# File lib/blather/stanza/iq/si.rb, line 268 def hash read_attr :hash end
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
Get the filename
@return [String, nil]
# File lib/blather/stanza/iq/si.rb, line 254 def name read_attr :name end
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
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
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
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