diff --git a/feed.xml b/feed.xml new file mode 100644 index 0000000..50c7368 --- /dev/null +++ b/feed.xml @@ -0,0 +1,124 @@ + + + + + Que choa + + http://quechoa.info + quechoa.info + Sat, 11 Feb 2012 16:16:34 +0000 + vi + hourly + 1 + http://wordpress.com/ + + + http://1.gravatar.com/blavatar/76dcd732338d3ae5f90bbddec5c865fb?s=96&d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png + Quê choa + http://quechoa.info + + + diff --git a/feed_parser.rb b/feed_parser.rb new file mode 100644 index 0000000..3d6e9a9 --- /dev/null +++ b/feed_parser.rb @@ -0,0 +1,26 @@ +require 'rubygems' +require 'nokogiri' + +class FeedParser + attr_reader :file + def initialize(file) + @file = file + end + + def parse + f = File.open(file) + doc = Nokogiri::XML(f) + f.close + root = doc.css('channel') + return NewSource.new(root.css("title").first.text, root.css("link").first.text) + end + +end + +class NewSource + attr_reader :name, :root_url + def initialize(name, root_url) + @name = name + @root_url = root_url + end +end diff --git a/feed_parser_spec.rb b/feed_parser_spec.rb new file mode 100644 index 0000000..84beceb --- /dev/null +++ b/feed_parser_spec.rb @@ -0,0 +1,19 @@ +require 'rubygems' +require 'awesome_print' +require File.join(File.dirname(__FILE__), 'feed_parser') + +describe FeedParser do + + let(:feed_file) { 'feed.xml' } + + subject { FeedParser.new(feed_file).parse } + + it 'has a name' do + subject.name.should == 'Que choa' + end + + it 'has a root url' do + subject.root_url.should == 'http://quechoa.info' + end + +end