lib/rrimm/config.rb in rrimm-0.4.0 vs lib/rrimm/config.rb in rrimm-0.5.0

- old
+ new

@@ -2,10 +2,11 @@ module RRImm class Config attr :feeds, :cache attr :default_formatter, :pipe + attr_accessor :output def initialize @feeds = {} cache "default cache" do path File.join(ENV['HOME'], '.cache', 'rrimm') @@ -19,41 +20,35 @@ def get_cache @cache end - def show - puts "Cache: #{@cache.name}" - puts " path: #{@cache.path}" unless @cache.path.eql? @cache.name + def show(ios) + ios.write "Cache: #{@cache.name}\n" + ios.write " path: #{@cache.path}\n" unless @cache.path.eql? @cache.name - puts "Default formatter: #{default_formatter}" if default_formatter + ios.write "Default formatter: #{default_formatter}\n" if default_formatter - puts "Feeds:" + ios.write "Feeds:\n" @feeds.values.group_by { |f| f.category }.map do |cat, feeds| - if cat.nil? or cat.empty? - puts "" - else - puts "#{cat}:" - end + ios.write "#{cat || "unamed category"}:\n" feeds.each do |feed| - fqdn = [feed.name] - fqdn << feed.uri unless feed.name.eql? feed.uri - puts "- #{fqdn.join ': '}" + fqdn = [feed.name, feed.uri].uniq + ios.write "- #{fqdn.join ': '}\n" end end end - def status(old_timestamp, very_old_timestamp, display_old_only) - ordered_feeds = @feeds.values.map { |f| [get_cache.read(f), f] }.sort_by { |el| el.first } - ordered_feeds.each do |el| - f = el[1] - case el.first + def status(ios, old_timestamp, very_old_timestamp, display_old_only) + @feeds.values.map { |f| [ Time.at(get_cache.read(f)), f] }.sort_by { |el| el.first }.each do |el| + date, f = el + case date.to_i when 0..very_old_timestamp - puts "#{Time.at(el.first)} #{f.name}".colorize(:red) + ios.write "#{date} #{f.name}\n".red when very_old_timestamp..old_timestamp - puts "#{Time.at(el.first)} #{f.name}".colorize(:yellow) + ios.write "#{date} #{f.name}\n".yellow else - puts "#{Time.at(el.first)} #{f.name}".colorize(:green) unless display_old_only + ios.write "#{date} #{f.name}\n".green unless display_old_only end end end def evaluate_feed_definition(feed_name, &block)