class Cli
Public Instance Methods
__print_version()
click to toggle source
# File lib/cli.rb, line 15 def __print_version puts version end
add(url)
click to toggle source
# File lib/cli.rb, line 22 def add(url) unless valid_url?(url) puts 'Invalid URL' return end unless feed_works?(url) puts 'A test fetch failed for the feed and as such it won\'t be added.' return end LideoController.new.add(url, group(options)) end
feeds()
click to toggle source
# File lib/cli.rb, line 62 def feeds url_to_remove = from_r_option(options) if url_to_remove.nil? list_feeds else remove_feed(url_to_remove) end end
fetch()
click to toggle source
# File lib/cli.rb, line 50 def fetch headlines = LideoController.new.fetch(group(options)) puts 'No news for you this time' if headlines.empty? export_html(headlines) && return if options[:to] && options[:to].downcase == 'html' puts "#{banner}#{format_headlines_output(headlines)}" unless headlines.empty? || !options[:to].nil? end
Private Instance Methods
export_html(headlines)
click to toggle source
# File lib/cli.rb, line 90 def export_html(headlines) puts Html.new.export(headlines) end
feed_works?(url)
click to toggle source
# File lib/cli.rb, line 73 def feed_works?(url) Fetcher.new.fetch(Feed.new(url, '')) rescue false end
format_headlines_output(headlines_grouped)
click to toggle source
# File lib/cli.rb, line 120 def format_headlines_output(headlines_grouped) s = StringIO.new headlines_grouped.each_key do |channel| s << "\n#{channel}\n" headlines_grouped[channel].each do |headline| s << " > #{headline}\n" end end s.string end
from_r_option(options)
click to toggle source
# File lib/cli.rb, line 98 def from_r_option(options) options[:r] unless options[:r].nil? || options[:r].empty? end
group(options)
click to toggle source
# File lib/cli.rb, line 94 def group(options) options[:g].nil? || options[:g].empty? ? 'default' : options[:g] end
list_feeds()
click to toggle source
# File lib/cli.rb, line 79 def list_feeds s = StringIO.new LideoController.new.feeds.map { |feed| s << "#{feed.to_s}\n" } output = !s.string.empty? ? s.string : 'You have not added any feeds yet' puts output end
remove_feed(url)
click to toggle source
# File lib/cli.rb, line 86 def remove_feed(url) LideoController.new.remove_feed(url) end
valid_url?(url)
click to toggle source
# File lib/cli.rb, line 102 def valid_url?(url) uri = URI.parse(url) uri.is_a?(URI::HTTP) && !uri.host.nil? rescue URI::InvalidURIError false end
version()
click to toggle source
# File lib/cli.rb, line 109 def version @version ||= Gem::Specification.load('lideo.gemspec').version end