Class: Sp2010::File

Inherits:
Object
  • Object
show all
Defined in:
lib/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ File

Returns a new instance of File.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/file.rb', line 8

def initialize(node)
  @xml = node
  
  @name = dav_prop_at("./DAV:displayname").content
  @url = @xml.at_xpath("./DAV:href", webdav_namespace).content
  @uri = Domainatrix.parse(@url)
  @path = @uri.path
  
  @is_aspx = name[-5..-1] == ".aspx"
  
  length = dav_prop_at("./DAV:getcontentlength").content
  @size = length ? length.to_i : nil
  
  isFolder = dav_prop_at("./DAV:isFolder")
  @is_folder = isFolder ? isFolder.content == "t" : false
  
  c = dav_prop_at("./DAV:getetag").content
  @etag = c.match(/^['"](.*)['"]$/)[1]
  
  @updated_at = dav_prop_at("./DAV:getlastmodified").content
  @created_at = dav_prop_at("./DAV:creationdate").content
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/file.rb', line 6

def created_at
  @created_at
end

#etagObject (readonly)

Returns the value of attribute etag.



6
7
8
# File 'lib/file.rb', line 6

def etag
  @etag
end

#is_aspxObject (readonly)

Returns the value of attribute is_aspx.



6
7
8
# File 'lib/file.rb', line 6

def is_aspx
  @is_aspx
end

#is_folderObject (readonly)

Returns the value of attribute is_folder.



6
7
8
# File 'lib/file.rb', line 6

def is_folder
  @is_folder
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/file.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/file.rb', line 6

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/file.rb', line 6

def size
  @size
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



6
7
8
# File 'lib/file.rb', line 6

def updated_at
  @updated_at
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/file.rb', line 6

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/file.rb', line 6

def url
  @url
end

#xmlObject (readonly)

Returns the value of attribute xml.



5
6
7
# File 'lib/file.rb', line 5

def xml
  @xml
end

Instance Method Details

#dav_prop_at(prop) ⇒ Object



35
36
37
# File 'lib/file.rb', line 35

def dav_prop_at(prop)      
  @xml.xpath("./DAV:propstat/DAV:prop", webdav_namespace).at_xpath(prop, webdav_namespace)
end

#webdav_namespaceObject



31
32
33
# File 'lib/file.rb', line 31

def webdav_namespace
  webdav_namespace = {"DAV" => "DAV:"}
end