Class: Yandex::Disk::Client::Request::List::ListParser

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/yandex/disk/client/request/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListParser

Returns a new instance of ListParser.



25
26
27
# File 'lib/yandex/disk/client/request/list.rb', line 25

def initialize
  @list = []
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



23
24
25
# File 'lib/yandex/disk/client/request/list.rb', line 23

def list
  @list
end

Instance Method Details

#characters(string) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/yandex/disk/client/request/list.rb', line 72

def characters string
  @current[:href] = string if @is_href
  @current[:displayname] = string if @is_displayname
  @current[:getcontentlength] = string.to_i if @is_getcontentlength
  @current[:creationdate] = DateTime.parse(string) if @is_creationdate
  @current[:getlastmodified] = DateTime.parse(string) if @is_getlastmodified
end

#end_element(name, attributes = []) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/yandex/disk/client/request/list.rb', line 52

def end_element name, attributes = []
  case name
    when 'd:href'
      @list << @current if @current
      @is_href = false

    when 'd:displayname'
      @is_displayname = false

    when 'd:getcontentlength'
      @is_getcontentlength = false

    when 'd:creationdate'
      @is_creationdate = false

    when 'd:getlastmodified'
      @is_getlastmodified = false
  end
end

#start_element(name, attributes = []) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/yandex/disk/client/request/list.rb', line 29

def start_element name, attributes = []
  case name
    when 'd:href'
      @current = {}
      @is_href = true

    when 'd:displayname'
      @is_displayname = true

    when 'd:getcontentlength'
      @is_getcontentlength = true

    when 'd:creationdate'
      @is_creationdate = true

    when 'd:getlastmodified'
      @is_getlastmodified = true

    when 'd:collection'
      @current[:resourcetype] = :collection
  end
end