29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/douban/collection.rb', line 29
def initialize(atom)
doc = case atom
when REXML::Document then atom.root
when REXML::Element then atom
else REXML::Document.new(atom).root
end
subject=REXML::XPath.first(doc,"./db:subject")
@subject=Subject.new(subject) if subject
author=REXML::XPath.first(doc,"./author")
@author=Author.new(author.to_s) if author
title=REXML::XPath.first(doc,"./title")
@title=title.text if !title.nil?
updated=REXML::XPath.first(doc,"./updated")
@updated=updated.text if updated
@summary = REXML::XPath.first(doc, "./summary/text()").to_s
@status = REXML::XPath.first(doc, "./db:status/text()").to_s
@link = Hash.new
REXML::XPath.each(doc, "./link") do |e|
@link[e.attributes["rel"]] = e.attributes["href"]
end
id=REXML::XPath.first(doc,"./id")
@id=id.text if id
REXML::XPath.each(doc,"./db:tag") do |tag|
@tag||=[]
@tag<< tag.attributes['name']
end
rating=REXML::XPath.first(doc,"./db:rating")
if rating
@rating={}
@rating['min']=rating.attributes['min']
@rating['value']=rating.attributes['value']
@rating['max']=rating.attributes['max']
end
end
|