27
28
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/douban/subject.rb', line 27
def initialize(atom='')
doc = case atom
when REXML::Document then atom.root
when REXML::Element then atom
when nil then nil
else REXML::Document.new(atom).root
end
@doc = doc
id=REXML::XPath.first(doc,"./id")
@id=id.text if id
title=REXML::XPath.first(doc,"./title")
@title=title.text if title
@category={}
category=REXML::XPath.first(doc,"./category")
@category['term']=category.attributes['term'] if category
@category['scheme']=category.attributes['scheme'] if category
REXML::XPath.each(doc,"./db:tag") do |tag|
@tag||=[]
t=Tag.new
t.title=tag.attributes['name']
t.count=tag.attributes['count']
@tag<< t
end
@author||=Author.new
name=REXML::XPath.first(doc,"./author/name")
@author.name=name.text if name
uri=REXML::XPath.first(doc,"./author/uri")
@author.uri=uri.text if uri
REXML::XPath.each(doc,"./author/link") do |link|
@author.link||={}
@author.link[link.attributes['rel']]=link.attributes['href']
end
summary=REXML::XPath.first(doc,"./summary")
@summary=summary.text if summary
REXML::XPath.each(doc,"./link") do |link|
@link||={}
@link[link.attributes['rel']]=link.attributes['href']
end
REXML::XPath.each(doc,"./db:attribute") do |attribute|
@attribute ||= {}
@attribute[attribute.attributes['name']] ||= []
@attribute[attribute.attributes['name']] << attribute.text
end
@rating={}
rating=REXML::XPath.first(doc,"./gd:rating")
if rating
@rating['min']=rating.attributes['min']
@rating['numRaters']=rating.attributes['numRaters']
@rating['average']=rating.attributes['average']
@rating['max']=rating.attributes['max']
end
end
|