hurricane 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/hurricane.gemspec +1 -1
- data/lib/hurricane.rb +38 -34
- data/spec/hurricane_spec.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/hurricane.gemspec
CHANGED
data/lib/hurricane.rb
CHANGED
@@ -2,42 +2,46 @@ require 'rubygems'
|
|
2
2
|
require 'time'
|
3
3
|
require 'hpricot'
|
4
4
|
|
5
|
-
|
6
|
-
def self.from(file)
|
7
|
-
blog = Blog.new
|
8
|
-
doc = Hpricot::XML(file)
|
9
|
-
(doc/:channel).each do |info|
|
10
|
-
blog.title = (info/:title)[0].inner_html
|
11
|
-
blog.description = (info/:description).inner_html
|
12
|
-
blog.link = (info/:link)[0].inner_html
|
13
|
-
blog.created_at = Time.rfc2822((info/'pubDate')[0].inner_html)
|
5
|
+
module Hurricane
|
14
6
|
|
15
|
-
|
16
|
-
|
7
|
+
class Parse
|
8
|
+
def self.from(file)
|
9
|
+
blog = Blog.new
|
10
|
+
doc = Hpricot::XML(file)
|
11
|
+
(doc/:channel).each do |info|
|
12
|
+
blog.title = (info/:title)[0].inner_html
|
13
|
+
blog.description = (info/:description).inner_html
|
14
|
+
blog.link = (info/:link)[0].inner_html
|
15
|
+
blog.created_at = Time.rfc2822((info/'pubDate')[0].inner_html)
|
16
|
+
|
17
|
+
(info/'wp:category'/'wp:category_nicename').each do |category|
|
18
|
+
blog.categories << category.inner_html
|
19
|
+
end
|
20
|
+
|
21
|
+
(info/:item).each do |item|
|
22
|
+
post = Post.new
|
23
|
+
post.title = (item/:title).inner_html
|
24
|
+
post.link = (item/:link).inner_html
|
25
|
+
post.created_at = (item/'pubDate').inner_html
|
26
|
+
post.description = (item/'content:encoded').inner_html.gsub('<![CDATA[', '').gsub(']]>', '')
|
27
|
+
blog.posts << post
|
28
|
+
end
|
29
|
+
|
17
30
|
end
|
18
|
-
|
19
|
-
(info/:item).each do |item|
|
20
|
-
post = Post.new
|
21
|
-
post.title = (item/:title).inner_html
|
22
|
-
post.link = (item/:link).inner_html
|
23
|
-
post.created_at = (item/'pubDate').inner_html
|
24
|
-
post.description = (item/'content:encoded').inner_html.gsub('<![CDATA[', '').gsub(']]>', '')
|
25
|
-
blog.posts << post
|
26
|
-
end
|
27
|
-
|
31
|
+
blog
|
28
32
|
end
|
29
|
-
blog
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Blog
|
34
|
-
def initialize
|
35
|
-
@categories = Array.new
|
36
|
-
@posts = Array.new
|
37
33
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
|
35
|
+
class Blog
|
36
|
+
def initialize
|
37
|
+
@categories = Array.new
|
38
|
+
@posts = Array.new
|
39
|
+
end
|
40
|
+
attr_accessor :title, :link, :description, :created_at, :categories, :posts
|
41
|
+
end
|
42
|
+
|
43
|
+
class Post
|
44
|
+
attr_accessor :title, :link, :created_at, :description
|
45
|
+
end
|
46
|
+
|
43
47
|
end
|
data/spec/hurricane_spec.rb
CHANGED