class Redcli::Application

Constants

COLORS
ROOT

Public Class Methods

new(subreddit:, stdout:STDOUT, stdin: STDIN) click to toggle source
# File lib/redcli/application.rb, line 11
def initialize(subreddit:, stdout:STDOUT, stdin: STDIN)
  @subreddit = subreddit
  @stdout = stdout
  @stdin = stdin
end

Public Instance Methods

run() click to toggle source
# File lib/redcli/application.rb, line 17
def run
  @links = get_links
  if @links
    links
  else
    signal_failure
  end
end

Private Instance Methods

act_on_input() click to toggle source
# File lib/redcli/application.rb, line 85
def act_on_input
  input = @stdin.gets.chomp
  if input =~ /q/
    return
  elsif input =~ /[0-9]/
    link(input.to_i - 1)
  elsif input =~ /b/
    links
  elsif input =~ /o/
    open_current_link
  end
end
display_topic(topic_index) click to toggle source
# File lib/redcli/application.rb, line 71
def display_topic(topic_index)
  @stdout.puts "\n\n\n"
  @stdout.puts @links[topic_index].fetch("data", { "selftext" => "No Information Available" }).fetch("selftext")
  @stdout.puts "\n"
end
signal_failure() click to toggle source
# File lib/redcli/application.rb, line 58
def signal_failure
  @stdout.puts "Sorry, reddit is either not responding or the subreddit does not exist, try again"
end
url() click to toggle source
# File lib/redcli/application.rb, line 46
def url
  ROOT + "/r/" + @subreddit + ".json"
end