Move to Apache License
[amazing.git] / lib / amazing / widgets / raggle.rb
blobdf7881d645b69017fd3f6b562ec21b20816fd5e8
1 # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 #    http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 require 'amazing/widget'
17 module Amazing
18   module Widgets
19     class Raggle < Widget
20       description "Unread posts in raggle"
21       dependency "pstore", "Ruby standard library"
22       option :feed_list_path, "Path to feeds list", "~/.raggle/feeds.yaml"
23       option :feed_cache_path, "Path to feeds cache", "~/.raggle/feed_cache.store"
24       field :count, "Ammount of unread posts", 0
25       default { @count }
27       init do
28         @feed_list_path = ::File.expand_path(@feed_list_path, "~")
29         feeds = YAML.load_file(@feed_list_path)
30         @feed_cache_path = ::File.expand_path(@feed_cache_path, "~")
31         cache = PStore.new(@feed_cache_path)
32         cache.transaction(false) do
33           feeds.each do |feed|
34             cache[feed["url"]].each do |item|
35               @count += 1 unless item["read?"]
36             end
37           end
38         end
39       end
40     end
41   end
42 end