Employ File.expand_path as appropriate
[amazing.git] / lib / amazing / widgets / raggle.rb
blob67873aa5358e479329601b1a4cf1c2282da9497a
1 # Copyright (C) 2008 Dag Odenhall <dag.odenhall@gmail.com>
2 # Licensed under the Academic Free License version 3.0
4 require 'amazing/widget'
6 module Amazing
7   module Widgets
8     class Raggle < Widget
9       description "Unread posts in raggle"
10       dependency "pstore", "Ruby standard library"
11       option :feed_list_path, "Path to feeds list", "~/.raggle/feeds.yaml"
12       option :feed_cache_path, "Path to feeds cache", "~/.raggle/feed_cache.store"
13       field :count, "Ammount of unread posts", 0
14       default { @count }
16       init do
17         @feed_list_path = ::File.expand_path(@feed_list_path, "~")
18         feeds = YAML.load_file(@feed_list_path)
19         @feed_cache_path = ::File.expand_path(@feed_cache_path, "~")
20         cache = PStore.new(@feed_cache_path)
21         cache.transaction(false) do
22           feeds.each do |feed|
23             cache[feed["url"]].each do |item|
24               @count += 1 unless item["read?"]
25             end
26           end
27         end
28       end
29     end
30   end
31 end