Class: LiveJournal::Sync::CommentsXML::WithExpat::Parser

Inherits:
XMLParser
  • Object
show all
Defined in:
lib/livejournal/comments-xml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



95
96
97
98
99
100
101
102
# File 'lib/livejournal/comments-xml.rb', line 95

def initialize
  super
  @maxid = nil
  @cur_comment = nil
  @comments = {}
  @usermap = {}
  @content = nil
end

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



94
95
96
# File 'lib/livejournal/comments-xml.rb', line 94

def comments
  @comments
end

#maxidObject (readonly)

Returns the value of attribute maxid.



94
95
96
# File 'lib/livejournal/comments-xml.rb', line 94

def maxid
  @maxid
end

#usermapObject (readonly)

Returns the value of attribute usermap.



94
95
96
# File 'lib/livejournal/comments-xml.rb', line 94

def usermap
  @usermap
end

Instance Method Details

#character(data) ⇒ Object



124
125
126
# File 'lib/livejournal/comments-xml.rb', line 124

def character(data)
  @content << data if @content
end

#endElement(name) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/livejournal/comments-xml.rb', line 127

def endElement(name)
  return unless @content
  case name
  when 'maxid'
    @maxid = @content.to_i
  when 'date'
    @cur_comment.time = Time::xmlschema(@content)
  when 'subject'
    @cur_comment.subject = @content
  when 'body'
    @cur_comment.body = @content
  end
  @content = nil
end

#startElement(name, attrs) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/livejournal/comments-xml.rb', line 103

def startElement(name, attrs)
  case name
  when 'maxid'
    @content = ''
  when 'comment'
    id = attrs['id'].to_i
    @cur_comment = @comments[id] || Comment.new
    @comments[id] = @cur_comment
    CommentsXML::load_comment_from_attrs(@cur_comment, attrs)
  when 'usermap'
    id = attrs['id'].to_i
    user = attrs['user']
    @usermap[id] = user
  when 'date'
    @content = ''
  when 'subject'
    @content = ''
  when 'body'
    @content = ''
  end
end