Class: LiveJournal::Sync::CommentsXML::WithREXML

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

Instance Attribute Summary

Attributes inherited from Base

#comments, #maxid, #usermap

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from LiveJournal::Sync::CommentsXML::Base

Instance Method Details

#parse(data) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/livejournal/comments-xml.rb', line 67

def parse(data)
  doc = REXML::Document.new(data)
  root = doc.root
  
  root.elements.each('maxid') { |e| @maxid = e.text.to_i }

  root.elements.each('comments/comment') do |e|
    id = e.attributes['id'].to_i
    comment = @comments[id] || Comment.new
    CommentsXML::load_comment_from_attrs(comment, e.attributes)
    e.elements.each('subject') { |s| comment.subject = s.text }
    e.elements.each('body') { |s| comment.body = s.text }
    e.elements.each('date') { |s| comment.time = Time::xmlschema s.text }
    @comments[id] = comment
  end

  root.elements.each('usermaps/usermap') do |e|
    id = e.attributes['id'].to_i
    user = e.attributes['user']
    @usermap[id] = user
  end
end