Class: InternetWisdom::CLI
- Inherits:
-
Object
- Object
- InternetWisdom::CLI
- Defined in:
- lib/internet_wisdom/cli.rb
Constant Summary collapse
- BORDER =
"~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
- WELCOME =
"\nWELCOME TO INTERNET WISDOM!!!"
- INSTRUCTIONS =
%q( Hotkeys: h - help f - follow the author on the web x - filter posts from a specific site [Enter] - get a new post q - quit )
Instance Attribute Summary collapse
-
#cur_site ⇒ Object
readonly
Returns the value of attribute cur_site.
-
#cur_site_index ⇒ Object
readonly
Returns the value of attribute cur_site_index.
-
#current_post ⇒ Object
readonly
Returns the value of attribute current_post.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
Instance Method Summary collapse
- #call ⇒ Object
- #display_instructions ⇒ Object
- #display_post(post) ⇒ Object
- #filter_sites ⇒ Object
- #get_input ⇒ Object
- #get_wisdom ⇒ Object
Instance Attribute Details
#cur_site ⇒ Object (readonly)
Returns the value of attribute cur_site.
14 15 16 |
# File 'lib/internet_wisdom/cli.rb', line 14 def cur_site @cur_site end |
#cur_site_index ⇒ Object (readonly)
Returns the value of attribute cur_site_index.
14 15 16 |
# File 'lib/internet_wisdom/cli.rb', line 14 def cur_site_index @cur_site_index end |
#current_post ⇒ Object (readonly)
Returns the value of attribute current_post.
14 15 16 |
# File 'lib/internet_wisdom/cli.rb', line 14 def current_post @current_post end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
14 15 16 |
# File 'lib/internet_wisdom/cli.rb', line 14 def manager @manager end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/internet_wisdom/cli.rb', line 16 def call puts WELCOME puts INSTRUCTIONS @manager = InternetWisdom::SiteManager.new @cur_site_index = -1 puts "\n" get_wisdom end |
#display_instructions ⇒ Object
78 79 80 81 82 |
# File 'lib/internet_wisdom/cli.rb', line 78 def display_instructions puts WELCOME puts INSTRUCTIONS get_input end |
#display_post(post) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/internet_wisdom/cli.rb', line 31 def display_post(post) puts BORDER @current_post = post.hash post.hash.each do |k, v| puts "#{v}\n\n" end puts BORDER get_input end |
#filter_sites ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/internet_wisdom/cli.rb', line 41 def filter_sites puts "\nEnter a number below to only get wisdom from a specific source" puts "0. Randomly select wisdom from all sites (default)" manager.sites.each.with_index(1) { |s, i| puts "#{i}. #{s.name}" } input = gets.strip.to_i if input >= 0 && input <= manager.sites.length @cur_site_index = input - 1 puts "\n" input < 1 ? (puts "Fetching wisdom from randomly chosen sites") : (puts "Fetching wisdom from #{manager.sites[cur_site_index].name}") get_wisdom else puts "Invalid entry, try again" filter_sites end end |
#get_input ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/internet_wisdom/cli.rb', line 57 def get_input input = nil while input != 'q' input = gets.strip case input when 'f' Launchy.open(current_post[:link]) if !current_post[:link].nil? when 'x' filter_sites when 'h' display_instructions when "" get_wisdom else puts "Command not recognized, type 'h' for instructions" if input != "q" end end puts "\n\nGoodbye!!" exit end |
#get_wisdom ⇒ Object
26 27 28 29 |
# File 'lib/internet_wisdom/cli.rb', line 26 def get_wisdom cur_site_index < 0 ? @cur_site = manager.sites.sample : @cur_site = manager.sites[cur_site_index] display_post(cur_site.get_post) end |