aboutsummaryrefslogtreecommitdiffstats
path: root/rss.rb
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2015-05-05 10:42:59 +0200
committerHarald Eilertsen <haraldei@anduin.net>2015-05-05 10:42:59 +0200
commitfb1cc37a6789fa08a7becf911c3892504627810b (patch)
tree2a9387ba6c39fa187e7672652e47f7a2fcbc566a /rss.rb
parent8adcbede3f2b326bb65cbb63a0dbf3dfa0a26a79 (diff)
downloadrss2html-fb1cc37a6789fa08a7becf911c3892504627810b.tar.gz
rss2html-fb1cc37a6789fa08a7becf911c3892504627810b.tar.bz2
rss2html-fb1cc37a6789fa08a7becf911c3892504627810b.zip
Refactor Feed and FeedItem into separate files.
Diffstat (limited to 'rss.rb')
-rw-r--r--rss.rb49
1 files changed, 6 insertions, 43 deletions
diff --git a/rss.rb b/rss.rb
index 12a439c..15be5ed 100644
--- a/rss.rb
+++ b/rss.rb
@@ -14,56 +14,19 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-require 'rss'
-require 'open-uri'
-require 'yaml'
-
-
-class Item
- attr_reader :title, :author, :date, :summary, :url
-
- def initialize(item)
- @title = item.title.content
- @author = item.author.name.content
- @date = item.updated.content
- @summary = item.summary.content.strip
- @url = item.link.href
- end
-end
-
-
-class Feed
- attr_reader :title, :url, :items
-
- def initialize(title, args)
- @title, @url = title, args['url']
- @items = []
- slurp
- end
-
- private
-
- def slurp
- open(url) do |rss|
- feed = RSS::Parser.parse(rss)
-
- feed.entries.each do |item|
- add Item.new(item)
- end
- end
- end
+require_relative 'lib/feed_item'
+require_relative 'lib/feed'
- def add(item)
- @items << item
- end
-end
+require 'yaml'
feeds = YAML.load(IO.read('feeds.yml'))
items = []
feeds.each do |t, f|
feed = Feed.new(t, f)
- feed.items.each do |item|
+ feed.fetch do |entry|
+ item = FeedItem.new(entry)
+
puts %{<article>}
puts %{ <header>}
puts %{ <h1>#{item.title}</h1>}