Class: Hurricane

Inherits:
Object
  • Object
show all
Defined in:
lib/hurricane.rb

Class Method Summary collapse

Class Method Details

.from(file) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hurricane.rb', line 6

def self.from(file)
		blog = Blog.new	
		doc = Hpricot::XML(file)
		(doc/:channel).each do |info|
blog.title = (info/:title)[0].inner_html
blog.description = (info/:description).inner_html
blog.link = (info/:link)[0].inner_html
blog.created_at = Time.rfc2822((info/'pubDate')[0].inner_html)

(info/'wp:category'/'wp:category_nicename').each do |category|
	blog.categories << category.inner_html
end

(info/:item).each do |item|
	post = Post.new
	post.title = (item/:title).inner_html
	post.link = (item/:link).inner_html
	post.created_at = (item/'pubDate').inner_html
	post.description = (item/'content:encoded').inner_html.gsub('<![CDATA[', '').gsub(']]>', '')
	blog.posts << post
end

		end
		blog
end