Class: TildeScraper::CommandLineInterface
- Inherits:
-
Object
- Object
- TildeScraper::CommandLineInterface
- Defined in:
- lib/tilde_scraper/cli.rb
Instance Method Summary collapse
- #comments(index_string) ⇒ Object
- #front_page ⇒ Object
- #group(index_string) ⇒ Object
- #groups ⇒ Object
- #help ⇒ Object
- #next_page ⇒ Object
- #page_list ⇒ Object
- #prev_page ⇒ Object
- #run ⇒ Object
- #view(index_string) ⇒ Object
Instance Method Details
#comments(index_string) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/tilde_scraper/cli.rb', line 84 def comments(index_string) index = validate_index(index_string, @page.topics.length) return nil if !index topic = @page.topics[index] if topic.comments.length == 0 TildeScraper::get_comments(topic.comment_link) end TildeScraper::Comment.display_page(topic.comment_link) end |
#front_page ⇒ Object
80 81 82 |
# File 'lib/tilde_scraper/cli.rb', line 80 def front_page @page = TildeScraper::get_page("https://tildes.net") end |
#group(index_string) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/tilde_scraper/cli.rb', line 70 def group(index_string) if TildeScraper::Group.all.length == 0 TildeScraper::get_groups end index = validate_index(index_string, TildeScraper::Group.all.length) return nil if !index @page = TildeScraper::get_page(TildeScraper::Group.all[index].get_url) page_list end |
#groups ⇒ Object
63 64 65 66 67 68 |
# File 'lib/tilde_scraper/cli.rb', line 63 def groups if TildeScraper::Group.all.length == 0 TildeScraper::get_groups end TildeScraper::Group.display end |
#help ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tilde_scraper/cli.rb', line 102 def help puts "To view this list, type: help" puts "To view groups: groups" puts "To view group page: group [index]" puts "To return to front page: frontpage" puts "To view topics of current page: list" puts "To view next page: next" puts "To view prev page: prev" puts "To view submission contents: view [index]" puts "To view submission comments: comments [index]" end |
#next_page ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/tilde_scraper/cli.rb', line 45 def next_page if @page.next_link @page = TildeScraper::get_page(@page.next_link) page_list else puts "Last page" end end |
#page_list ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/tilde_scraper/cli.rb', line 94 def page_list if !@page puts "No page selected" else @page.display end end |
#prev_page ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/tilde_scraper/cli.rb', line 54 def prev_page if @page.next_link @page = TildeScraper::get_page(@page.prev_link) page_list else puts "No previous page" end end |
#run ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tilde_scraper/cli.rb', line 2 def run front_page help input = nil until input == "exit" print "Please Enter A Command: " input = gets.strip.downcase case input.split(" ").first when "help" help when "exit" puts "Goodbye" when "frontpage" front_page page_list when "groups" groups when "group" group(input.split(" ")[1]) when "page" page when "list" page_list when "next" next_page when "prev" prev_page when "view" view(input.split(" ")[1]) when "comments" comments(input.split(" ")[1]) else puts "Invalid command" end end end |
#view(index_string) ⇒ Object
39 40 41 42 43 |
# File 'lib/tilde_scraper/cli.rb', line 39 def view(index_string) index = validate_index(index_string, @page.topics.length) return nil if !index @page.topics[index].display_content end |