douban-ruby 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,69 +1,69 @@
1
- require 'rexml/document'
2
- require 'douban/subject'
3
- require 'douban/author'
4
-
5
- module Douban
6
- class Collection
7
-
8
- include Douban::Equal
9
-
10
- class << self
11
- def attr_names
12
- [
13
- :tag,
14
- :updated,
15
- :subject,
16
- :author,
17
- :title,
18
- :summary,
19
- :link,
20
- :id,
21
- :rating,
22
- :status
23
- ]
24
- end
25
- end
26
- attr_names.each do |attr|
27
- attr_accessor attr
28
- end
29
- def initialize(atom)
30
- doc = case atom
31
- when REXML::Document then atom.root
32
- when REXML::Element then atom
33
- else REXML::Document.new(atom).root
34
- end
35
- subject=REXML::XPath.first(doc,"./db:subject")
36
- @subject=Subject.new(subject) if subject
37
- author=REXML::XPath.first(doc,"./author")
38
- @author=Author.new(author.to_s) if author
39
- title=REXML::XPath.first(doc,"./title")
40
- @title=title.text if !title.nil?
41
- updated=REXML::XPath.first(doc,"./updated")
42
- @updated=updated.text if updated
43
- @summary = REXML::XPath.first(doc, "./summary/text()").to_s
44
- @status = REXML::XPath.first(doc, "./db:status/text()").to_s
45
- @link = Hash.new
46
- REXML::XPath.each(doc, "./link") do |e|
47
- @link[e.attributes["rel"]] = e.attributes["href"]
48
- end
49
- id=REXML::XPath.first(doc,"./id")
50
- @id=id.text if id
51
- REXML::XPath.each(doc,"./db:tag") do |tag|
52
- @tag||=[]
53
- @tag<< tag.attributes['name']
54
- end
55
- rating=REXML::XPath.first(doc,"./db:rating")
56
- if rating
57
- @rating={}
58
- @rating['min']=rating.attributes['min']
59
- @rating['value']=rating.attributes['value']
60
- @rating['max']=rating.attributes['max']
61
- end
62
- end
63
-
64
- def collection_id
65
- /\/(\d+)$/.match(@id)[1].to_i rescue nil
66
- end
67
- end
68
- end
69
-
1
+ require 'rexml/document'
2
+ require 'douban/subject'
3
+ require 'douban/author'
4
+
5
+ module Douban
6
+ class Collection
7
+
8
+ include Douban::Equal
9
+
10
+ class << self
11
+ def attr_names
12
+ [
13
+ :tag,
14
+ :updated,
15
+ :subject,
16
+ :author,
17
+ :title,
18
+ :summary,
19
+ :link,
20
+ :id,
21
+ :rating,
22
+ :status
23
+ ]
24
+ end
25
+ end
26
+ attr_names.each do |attr|
27
+ attr_accessor attr
28
+ end
29
+ def initialize(atom)
30
+ doc = case atom
31
+ when REXML::Document then atom.root
32
+ when REXML::Element then atom
33
+ else REXML::Document.new(atom).root
34
+ end
35
+ subject=REXML::XPath.first(doc,"./db:subject")
36
+ @subject=Subject.new(subject) if subject
37
+ author=REXML::XPath.first(doc,"./author")
38
+ @author=Author.new(author.to_s) if author
39
+ title=REXML::XPath.first(doc,"./title")
40
+ @title=title.text if !title.nil?
41
+ updated=REXML::XPath.first(doc,"./updated")
42
+ @updated=updated.text if updated
43
+ @summary = REXML::XPath.first(doc, "./summary/text()").to_s
44
+ @status = REXML::XPath.first(doc, "./db:status/text()").to_s
45
+ @link = Hash.new
46
+ REXML::XPath.each(doc, "./link") do |e|
47
+ @link[e.attributes["rel"]] = e.attributes["href"]
48
+ end
49
+ id=REXML::XPath.first(doc,"./id")
50
+ @id=id.text if id
51
+ REXML::XPath.each(doc,"./db:tag") do |tag|
52
+ @tag||=[]
53
+ @tag<< tag.attributes['name']
54
+ end
55
+ rating=REXML::XPath.first(doc,"./db:rating")
56
+ if rating
57
+ @rating={}
58
+ @rating['min']=rating.attributes['min']
59
+ @rating['value']=rating.attributes['value']
60
+ @rating['max']=rating.attributes['max']
61
+ end
62
+ end
63
+
64
+ def collection_id
65
+ /\/(\d+)$/.match(@id)[1].to_i rescue nil
66
+ end
67
+ end
68
+ end
69
+
@@ -1,80 +1,80 @@
1
- require 'rexml/document'
2
- require 'douban/equal'
3
- require 'douban/author'
4
-
5
- module Douban
6
- class Event
7
- include Douban::Equal
8
- class << self
9
- def attr_names
10
- [
11
- :id,
12
- :title,
13
- :category,
14
- :author,
15
- :link,
16
- :summary,
17
- :content,
18
- :attribute,
19
- :location,
20
- :when,
21
- :where
22
- ]
23
- end
24
- end
25
- attr_names.each do |attr|
26
- attr_accessor attr
27
- end
28
- def initialize(atom='')
29
- doc = case atom
30
- when REXML::Document then atom.root
31
- when REXML::Element then atom
32
- else REXML::Document.new(atom).root
33
- end
34
-
35
- @id=REXML::XPath.first(doc,"./id/text()").to_s
36
- title=REXML::XPath.first(doc,"./title")
37
- @title=title.text if title
38
- @category={}
39
- category=REXML::XPath.first(doc,"./category")
40
- @category['term']=category.attributes['term'] if category
41
- @category['scheme']=category.attributes['scheme'] if category
42
- @author||=Author.new
43
- name=REXML::XPath.first(doc,"//author/name")
44
- @author.name=name.text if name
45
- uri=REXML::XPath.first(doc,"//author/uri")
46
- @author.uri=uri.text if uri
47
- REXML::XPath.each(doc,"//author/link") do |link|
48
- @author.link||={}
49
- @author.link[link.attributes['rel']]=link.attributes['href']
50
- end
51
- summary=REXML::XPath.first(doc,"./summary")
52
- @summary=summary.text if summary
53
- content=REXML::XPath.first(doc,"./content")
54
- @content=content.text if content
55
- REXML::XPath.each(doc,"./link") do |link|
56
- @link||={}
57
- @link[link.attributes['rel']]=link.attributes['href']
58
- end
59
- REXML::XPath.each(doc,"./db:attribute") do |attribute|
60
- @attribute||={}
61
- @attribute[attribute.attributes['name']]=attribute.text
62
- end
63
- location=REXML::XPath.first(doc,"./db:location")
64
- @location=location.text if location
65
- @when={}
66
- time=REXML::XPath.first(doc,"./gd:when")
67
- if time
68
- @when['startTime']=time.attributes['startTime']
69
- @when['endTime']=time.attributes['endTime']
70
- end
71
- where=REXML::XPath.first(doc,"./gd:where")
72
- @where=where.attributes['valueString'] if where
73
- end
74
-
75
- def event_id
76
- /\/(\d+)$/.match(@id)[1].to_i rescue nil
77
- end
78
- end
79
- end
80
-
1
+ require 'rexml/document'
2
+ require 'douban/equal'
3
+ require 'douban/author'
4
+
5
+ module Douban
6
+ class Event
7
+ include Douban::Equal
8
+ class << self
9
+ def attr_names
10
+ [
11
+ :id,
12
+ :title,
13
+ :category,
14
+ :author,
15
+ :link,
16
+ :summary,
17
+ :content,
18
+ :attribute,
19
+ :location,
20
+ :when,
21
+ :where
22
+ ]
23
+ end
24
+ end
25
+ attr_names.each do |attr|
26
+ attr_accessor attr
27
+ end
28
+ def initialize(atom='')
29
+ doc = case atom
30
+ when REXML::Document then atom.root
31
+ when REXML::Element then atom
32
+ else REXML::Document.new(atom).root
33
+ end
34
+
35
+ @id=REXML::XPath.first(doc,"./id/text()").to_s
36
+ title=REXML::XPath.first(doc,"./title")
37
+ @title=title.text if title
38
+ @category={}
39
+ category=REXML::XPath.first(doc,"./category")
40
+ @category['term']=category.attributes['term'] if category
41
+ @category['scheme']=category.attributes['scheme'] if category
42
+ @author||=Author.new
43
+ name=REXML::XPath.first(doc,"//author/name")
44
+ @author.name=name.text if name
45
+ uri=REXML::XPath.first(doc,"//author/uri")
46
+ @author.uri=uri.text if uri
47
+ REXML::XPath.each(doc,"//author/link") do |link|
48
+ @author.link||={}
49
+ @author.link[link.attributes['rel']]=link.attributes['href']
50
+ end
51
+ summary=REXML::XPath.first(doc,"./summary")
52
+ @summary=summary.text if summary
53
+ content=REXML::XPath.first(doc,"./content")
54
+ @content=content.text if content
55
+ REXML::XPath.each(doc,"./link") do |link|
56
+ @link||={}
57
+ @link[link.attributes['rel']]=link.attributes['href']
58
+ end
59
+ REXML::XPath.each(doc,"./db:attribute") do |attribute|
60
+ @attribute||={}
61
+ @attribute[attribute.attributes['name']]=attribute.text
62
+ end
63
+ location=REXML::XPath.first(doc,"./db:location")
64
+ @location=location.text if location
65
+ @when={}
66
+ time=REXML::XPath.first(doc,"./gd:when")
67
+ if time
68
+ @when['startTime']=time.attributes['startTime']
69
+ @when['endTime']=time.attributes['endTime']
70
+ end
71
+ where=REXML::XPath.first(doc,"./gd:where")
72
+ @where=where.attributes['valueString'] if where
73
+ end
74
+
75
+ def event_id
76
+ /\/(\d+)$/.match(@id)[1].to_i rescue nil
77
+ end
78
+ end
79
+ end
80
+
@@ -1,63 +1,63 @@
1
- require'rexml/document'
2
-
3
- require 'douban/author'
4
- require 'douban/equal'
5
-
6
- module Douban
7
- class Miniblog
8
- include Douban::Equal
9
- class << self
10
- def attr_names
11
- [
12
- :id,
13
- :title,
14
- :category,
15
- :published,
16
- :link,
17
- :content,
18
- :attribute,
19
- :author
20
- ]
21
- end
22
- end
23
- attr_names.each do |attr|
24
- attr_accessor attr
25
- end
26
- def initialize(atom)
27
- doc = case atom
28
- when REXML::Document then atom.root
29
- when REXML::Element then atom
30
- else REXML::Document.new(atom).root
31
- end
32
- title=REXML::XPath.first(doc,"./title")
33
- @title=title.text if title
34
- published=REXML::XPath.first(doc,"./published")
35
- @published=published.text if published
36
- REXML::XPath.each(doc,"./link") do |link|
37
- @link||={}
38
- @link[link.attributes['rel']]=link.attributes['href']
39
- end
40
- id=REXML::XPath.first(doc,"./id")
41
- @id=id.text if id
42
- REXML::XPath.each(doc,"./db:attribute") do |attr|
43
- @attribute||={}
44
- @attribute[attr.attributes['name']]=attr.text
45
- end
46
- category=REXML::XPath.first(doc,"./category")
47
- if category
48
- @category={}
49
- @category['term']=category.attributes['term']
50
- @category['scheme']=category.attributes['scheme']
51
- end
52
- content=REXML::XPath.first(doc,"./content")
53
- @content=content.text if content
54
- author=REXML::XPath.first(doc,"./author")
55
- @author=Author.new(author.to_s) if author
56
- end
57
-
58
- def miniblog_id
59
- /\/(\d+)$/.match(@id)[1].to_i rescue nil
60
- end
61
- end
62
- end
63
-
1
+ require'rexml/document'
2
+
3
+ require 'douban/author'
4
+ require 'douban/equal'
5
+
6
+ module Douban
7
+ class Miniblog
8
+ include Douban::Equal
9
+ class << self
10
+ def attr_names
11
+ [
12
+ :id,
13
+ :title,
14
+ :category,
15
+ :published,
16
+ :link,
17
+ :content,
18
+ :attribute,
19
+ :author
20
+ ]
21
+ end
22
+ end
23
+ attr_names.each do |attr|
24
+ attr_accessor attr
25
+ end
26
+ def initialize(atom)
27
+ doc = case atom
28
+ when REXML::Document then atom.root
29
+ when REXML::Element then atom
30
+ else REXML::Document.new(atom).root
31
+ end
32
+ title=REXML::XPath.first(doc,"./title")
33
+ @title=title.text if title
34
+ published=REXML::XPath.first(doc,"./published")
35
+ @published=published.text if published
36
+ REXML::XPath.each(doc,"./link") do |link|
37
+ @link||={}
38
+ @link[link.attributes['rel']]=link.attributes['href']
39
+ end
40
+ id=REXML::XPath.first(doc,"./id")
41
+ @id=id.text if id
42
+ REXML::XPath.each(doc,"./db:attribute") do |attr|
43
+ @attribute||={}
44
+ @attribute[attr.attributes['name']]=attr.text
45
+ end
46
+ category=REXML::XPath.first(doc,"./category")
47
+ if category
48
+ @category={}
49
+ @category['term']=category.attributes['term']
50
+ @category['scheme']=category.attributes['scheme']
51
+ end
52
+ content=REXML::XPath.first(doc,"./content")
53
+ @content=content.text if content
54
+ author=REXML::XPath.first(doc,"./author")
55
+ @author=Author.new(author.to_s) if author
56
+ end
57
+
58
+ def miniblog_id
59
+ /\/(\d+)$/.match(@id)[1].to_i rescue nil
60
+ end
61
+ end
62
+ end
63
+
@@ -1,60 +1,60 @@
1
- require'rexml/document'
2
-
3
- require 'douban/author'
4
- require 'douban/equal'
5
-
6
- module Douban
7
- class Note
8
- include Douban::Equal
9
-
10
- class << self
11
- def attr_names
12
- [
13
- :id,
14
- :title,
15
- :summary,
16
- :updated,
17
- :published,
18
- :link,
19
- :content,
20
- :attribute,
21
- :author
22
- ]
23
- end
24
- end
25
- attr_names.each do |attr|
26
- attr_accessor attr
27
- end
28
- def initialize(doc)
29
- doc = REXML::Document.new(doc).root unless doc.kind_of?(REXML::Element)
30
- doc = doc.root if doc.kind_of?(REXML::Document)
31
-
32
- title=REXML::XPath.first(doc,"./title")
33
- @title=title.text if title
34
- published=REXML::XPath.first(doc,"./published")
35
- @published=published.text if published
36
- updated=REXML::XPath.first(doc,"./updated")
37
- @updated=updated.text if updated
38
- REXML::XPath.each(doc,"./link") do |link|
39
- @link||={}
40
- @link[link.attributes['rel']]=link.attributes['href']
41
- end
42
- id=REXML::XPath.first(doc,"./id")
43
- @id=id.text if id
44
- REXML::XPath.each(doc,"./db:attribute") do |attr|
45
- @attribute||={}
46
- @attribute[attr.attributes['name']]=attr.text
47
- end
48
- content=REXML::XPath.first(doc,"./content")
49
- @content=content.text if content
50
- summary=REXML::XPath.first(doc,"./summary")
51
- @summary=summary.text if summary
52
- author=REXML::XPath.first(doc,"./author")
53
- @author=Author.new(author.to_s) if author
54
- end
55
-
56
- def note_id
57
- /\/(\d+)$/.match(@id)[1].to_i rescue nil
58
- end
59
- end
60
- end
1
+ require'rexml/document'
2
+
3
+ require 'douban/author'
4
+ require 'douban/equal'
5
+
6
+ module Douban
7
+ class Note
8
+ include Douban::Equal
9
+
10
+ class << self
11
+ def attr_names
12
+ [
13
+ :id,
14
+ :title,
15
+ :summary,
16
+ :updated,
17
+ :published,
18
+ :link,
19
+ :content,
20
+ :attribute,
21
+ :author
22
+ ]
23
+ end
24
+ end
25
+ attr_names.each do |attr|
26
+ attr_accessor attr
27
+ end
28
+ def initialize(doc)
29
+ doc = REXML::Document.new(doc).root unless doc.kind_of?(REXML::Element)
30
+ doc = doc.root if doc.kind_of?(REXML::Document)
31
+
32
+ title=REXML::XPath.first(doc,"./title")
33
+ @title=title.text if title
34
+ published=REXML::XPath.first(doc,"./published")
35
+ @published=published.text if published
36
+ updated=REXML::XPath.first(doc,"./updated")
37
+ @updated=updated.text if updated
38
+ REXML::XPath.each(doc,"./link") do |link|
39
+ @link||={}
40
+ @link[link.attributes['rel']]=link.attributes['href']
41
+ end
42
+ id=REXML::XPath.first(doc,"./id")
43
+ @id=id.text if id
44
+ REXML::XPath.each(doc,"./db:attribute") do |attr|
45
+ @attribute||={}
46
+ @attribute[attr.attributes['name']]=attr.text
47
+ end
48
+ content=REXML::XPath.first(doc,"./content")
49
+ @content=content.text if content
50
+ summary=REXML::XPath.first(doc,"./summary")
51
+ @summary=summary.text if summary
52
+ author=REXML::XPath.first(doc,"./author")
53
+ @author=Author.new(author.to_s) if author
54
+ end
55
+
56
+ def note_id
57
+ /\/(\d+)$/.match(@id)[1].to_i rescue nil
58
+ end
59
+ end
60
+ end