Sha256: 05228789aae230fbf5c5caf3ebdf4c2ede3f01e92a777e40d6cd853681cba2ab
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
require 'hpricot' class Hurricane 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 = (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 end class Blog def initialize @categories = Array.new @posts = Array.new end attr_accessor :title, :link, :description, :created_at, :categories, :posts end class Post attr_accessor :title, :link, :created_at, :description end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hurricane-0.0.0 | lib/hurricane.rb |