Class: PodcastFinder::CLI
- Inherits:
-
Object
- Object
- PodcastFinder::CLI
- Defined in:
- lib/podcast_finder/commandline.rb
Instance Attribute Summary collapse
-
#category_choice ⇒ Object
Returns the value of attribute category_choice.
-
#episode_choice ⇒ Object
Returns the value of attribute episode_choice.
-
#input ⇒ Object
Returns the value of attribute input.
-
#podcast_choice ⇒ Object
Returns the value of attribute podcast_choice.
-
#podcast_counter ⇒ Object
Returns the value of attribute podcast_counter.
-
#quit ⇒ Object
Returns the value of attribute quit.
Instance Method Summary collapse
-
#browse_all_categories ⇒ Object
methods for browsing categories and viewing podcasts.
- #browse_category ⇒ Object
- #call ⇒ Object
- #choose_action_episode_info ⇒ Object
- #choose_action_no_episodes ⇒ Object
- #choose_after_help ⇒ Object
- #choose_category ⇒ Object
- #choose_episode ⇒ Object
- #choose_podcast ⇒ Object
- #choose_podcast_action ⇒ Object
- #display_episode_info ⇒ Object
- #display_episode_list ⇒ Object
-
#display_podcast_info ⇒ Object
methods for getting details on a specific podcast.
- #display_podcasts ⇒ Object
-
#get_input ⇒ Object
methods for gets-ing, parsing and acting based on user input.
-
#help ⇒ Object
basic menu display methods.
-
#initialize(quit = "NO") ⇒ CLI
constructor
A new instance of CLI.
- #parse_input(input) ⇒ Object
- #proceed_based_on_input ⇒ Object
- #start_import ⇒ Object
-
#startup_sequence ⇒ Object
methods needed for startup.
Constructor Details
#initialize(quit = "NO") ⇒ CLI
Returns a new instance of CLI.
5 6 7 |
# File 'lib/podcast_finder/commandline.rb', line 5 def initialize(quit = "NO") @quit = quit end |
Instance Attribute Details
#category_choice ⇒ Object
Returns the value of attribute category_choice.
3 4 5 |
# File 'lib/podcast_finder/commandline.rb', line 3 def category_choice @category_choice end |
#episode_choice ⇒ Object
Returns the value of attribute episode_choice.
3 4 5 |
# File 'lib/podcast_finder/commandline.rb', line 3 def episode_choice @episode_choice end |
#input ⇒ Object
Returns the value of attribute input.
3 4 5 |
# File 'lib/podcast_finder/commandline.rb', line 3 def input @input end |
#podcast_choice ⇒ Object
Returns the value of attribute podcast_choice.
3 4 5 |
# File 'lib/podcast_finder/commandline.rb', line 3 def podcast_choice @podcast_choice end |
#podcast_counter ⇒ Object
Returns the value of attribute podcast_counter.
3 4 5 |
# File 'lib/podcast_finder/commandline.rb', line 3 def podcast_counter @podcast_counter end |
#quit ⇒ Object
Returns the value of attribute quit.
3 4 5 |
# File 'lib/podcast_finder/commandline.rb', line 3 def quit @quit end |
Instance Method Details
#browse_all_categories ⇒ Object
methods for browsing categories and viewing podcasts
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/podcast_finder/commandline.rb', line 105 def browse_all_categories @podcast_counter = 0 puts "" puts "Main Menu: All Categories".colorize(:light_blue) PodcastFinder::Category.list_categories puts "" puts "To get started, choose a category above (1-#{PodcastFinder::Category.all.size}) or type 'help' to see a list of commands.".colorize(:light_blue) puts "You can also type 'exit' at any point to quit.".colorize(:light_blue) self.choose_category end |
#browse_category ⇒ Object
143 144 145 146 147 148 |
# File 'lib/podcast_finder/commandline.rb', line 143 def browse_category puts "" puts "Category: #{@category_choice.name}".colorize(:light_blue) self.display_podcasts self.choose_podcast end |
#call ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/podcast_finder/commandline.rb', line 9 def call self.startup_sequence until @quit == "YES" self.browse_all_categories end puts "Thanks for using the Command Line Podcast Finder!" end |
#choose_action_episode_info ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/podcast_finder/commandline.rb', line 311 def choose_action_episode_info self.get_input if @input == "BACK" @episode_choice = nil self.display_episode_list elsif @input == "PODCASTS" @podcast_counter = 0 @podcast_choice = nil @episode_choice = nil self.browse_category else @input = "STUCK" unless @input == "EXIT" || @input == "HELP" if @input == "HELP" self.proceed_based_on_input if @input == "BACK" self.display_episode_info end end self.proceed_based_on_input self.choose_action_episode_info unless @quit == "YES" end end |
#choose_action_no_episodes ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/podcast_finder/commandline.rb', line 256 def choose_action_no_episodes self.get_input if @input == "BACK" @podcast_counter = 0 self.browse_category elsif @input == "MENU" self.proceed_based_on_input else @input = "STUCK" unless @input == "EXIT" || @input == "HELP" if @input == "HELP" self.proceed_based_on_input if @input == "BACK" self.display_episode_list end end self.proceed_based_on_input self.choose_action_no_episodes unless @quit == "YES" end end |
#choose_after_help ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/podcast_finder/commandline.rb', line 59 def choose_after_help self.get_input if @input == "MENU" || @input == "EXIT" || @input == "HELP" || @input == "BACK" self.proceed_based_on_input else puts "Sorry, that's not an option. Please type a command from the help menu or type 'back' to return to what you were doing".colorize(:light_blue) self.choose_after_help end end |
#choose_category ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/podcast_finder/commandline.rb', line 116 def choose_category self.get_input if @input.class == Fixnum && @input.between?(1, 16) @category_choice = PodcastFinder::Category.all[@input - 1] puts "Loading podcasts from #{@category_choice.name}, please wait..." PodcastFinder::DataImporter.import_podcast_data(@category_choice) self.browse_category else if @input.class == Fixnum && !@input.between?(1,16) puts "Sorry, that's not a category. Please enter a number between 1 and 16" self.choose_category else @input = "STUCK" unless @input == "EXIT" || @input == "HELP" || @input == "BACK" if @input == "BACK" @input = "MENU" elsif @input == "HELP" self.proceed_based_on_input if @input == "BACK" self.browse_all_categories end end self.proceed_based_on_input self.choose_category unless @quit == "YES" end end end |
#choose_episode ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/podcast_finder/commandline.rb', line 276 def choose_episode self.get_input if @input.class == Fixnum && @input.between?(1, @podcast_choice.episodes.count) @episode_choice = @podcast_choice.episodes[@input-1] self.display_episode_info elsif @input.class == Fixnum && !@input.between?(1, @podcast_choice.episodes.count) puts "Sorry, that's not an episode option. Please enter a number between 1 and #{@podcast_choice.episodes.count} to proceed." self.choose_episode elsif @input == "BACK" @podcast_counter = 0 self.browse_category else @input = "STUCK" unless @input == "EXIT" || @input == "HELP" if @input == "HELP" self.proceed_based_on_input if @input == "BACK" self.display_episode_list end end self.proceed_based_on_input self.choose_episode unless @quit == "YES" end end |
#choose_podcast ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/podcast_finder/commandline.rb', line 165 def choose_podcast self.get_input if @input.class == Fixnum && @input.between?(1, @podcast_counter + @listed_podcasts) @podcast_choice = @category_choice.podcasts[@input - 1] self.display_podcast_info elsif @input.class == Fixnum && !@input.between?(1, @podcast_counter + @listed_podcasts) puts "Sorry, that's not an option. Please choose a number that corresponds to a podcast.".colorize(:light_blue) self.choose_podcast elsif @input == "MENU" @category_choice = nil self.proceed_based_on_input elsif @input == "MORE" @podcast_counter += 10 self.browse_category else @input = "STUCK" unless @input == "EXIT" || @input == "HELP" || @input == "BACK" if @input == "BACK" @input = "MENU" elsif @input == "HELP" self.proceed_based_on_input if @input == "BACK" self.browse_category end end self.proceed_based_on_input self.choose_podcast unless @quit == "YES" end end |
#choose_podcast_action ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/podcast_finder/commandline.rb', line 208 def choose_podcast_action self.get_input if @input == "MORE" self.display_episode_list elsif @input == "BACK" @podcast_counter = 0 self.browse_category elsif @input == "MENU" self.proceed_based_on_input else @input = "STUCK" unless @input == "EXIT" || @input == "HELP" if @input == "HELP" self.proceed_based_on_input if @input == "BACK" self.display_podcast_info end end self.proceed_based_on_input self.choose_podcast_action unless @quit == "YES" end end |
#display_episode_info ⇒ Object
300 301 302 303 304 305 306 307 308 309 |
# File 'lib/podcast_finder/commandline.rb', line 300 def display_episode_info puts "" @episode_choice.list_data puts "" puts "Options:".colorize(:light_blue) puts "Type 'back' to return to episode listing for #{@podcast_choice.name}".colorize(:light_blue) puts "Type 'podcasts' to return to the podcast list for #{@category_choice.name}".colorize(:light_blue) puts "Type 'menu' to see the category list".colorize(:light_blue) self.choose_action_episode_info end |
#display_episode_list ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/podcast_finder/commandline.rb', line 230 def display_episode_list puts "Getting episodes for #{@podcast_choice.name}..." PodcastFinder::DataImporter.import_episodes(@podcast_choice) if !@podcast_choice.episodes.empty? puts "" puts "#{@podcast_choice.name} Recent Episode List".colorize(:light_blue) @podcast_choice.list_episodes puts "" puts "These are all the options currently available in Podcast Finder.".colorize(:light_blue) puts "To see more, check out #{@podcast_choice.name} online at #{@podcast_choice.url}" puts "" puts "Options:".colorize(:light_blue) puts "Select an episode (1-#{@podcast_choice.episodes.count}) to get a description and download link".colorize(:light_blue) puts "Type 'back' to return to podcast listing for #{@category_choice.name}".colorize(:light_blue) puts "Type 'menu' to see the category list".colorize(:light_blue) self.choose_episode else #for edge case where a podcast has no associated episodes but is listed as active by website puts "" puts "Looks like #{@podcast_choice.name} doesn't have episodes online.".colorize(:light_red) puts "" puts "Type 'back' to return to podcast listing for #{@category_choice.name}".colorize(:light_blue) puts "Type 'menu' to see the category list".colorize(:light_blue) self.choose_action_no_episodes end end |
#display_podcast_info ⇒ Object
methods for getting details on a specific podcast
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/podcast_finder/commandline.rb', line 195 def display_podcast_info puts "Loading details for #{@podcast_choice.name}..." PodcastFinder::DataImporter.import_description(@podcast_choice) puts "" @podcast_choice.list_data puts "" puts "Choose an option below to proceed:".colorize(:light_blue) puts "Type 'more' to get episode list".colorize(:light_blue) puts "Type 'back' to return to podcast listing for #{@category_choice.name}".colorize(:light_blue) puts "Type 'menu' to return to main category menu".colorize(:light_blue) self.choose_podcast_action end |
#display_podcasts ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/podcast_finder/commandline.rb', line 150 def display_podcasts @listed_podcasts = @category_choice.list_podcasts(@podcast_counter) if @listed_podcasts == 10 && @category_choice.podcasts.size > @podcast_counter + @listed_podcasts puts "" puts "Enter the number of the podcast you'd like to check out (1-#{@podcast_counter + @listed_podcasts})".colorize(:light_blue) puts "Type 'menu' to return to the category list".colorize(:light_blue) puts "Type 'more' to see the next 10 podcasts".colorize(:light_blue) else puts "" puts "That's all the podcasts for this category!".colorize(:light_blue) puts "Enter the number of the podcast you'd like to check out (1-#{@podcast_counter + @listed_podcasts})".colorize(:light_blue) puts "Type 'menu' to return to the category list".colorize(:light_blue) end end |
#get_input ⇒ Object
methods for gets-ing, parsing and acting based on user input
71 72 73 74 |
# File 'lib/podcast_finder/commandline.rb', line 71 def get_input input = gets.strip self.parse_input(input) end |
#help ⇒ Object
basic menu display methods
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/podcast_finder/commandline.rb', line 43 def help puts "" puts "Help: Commands".colorize(:light_blue) puts "--To access any numbered menu, simply type the number of the item you're selecting and press Enter to confirm." puts " Example Menu: All Categories" puts " (1) Arts" puts " (2) Business" puts " (3) Comedy" puts " For example: if you want to view the Comedy category, just type '3' (without the quotes) and press Enter" puts "--Type 'exit' at any time to quit the browser" puts "--Type 'menu' at any time to go back to the main category menu" puts "--Type 'help' if you need a quick reminder about the commands" puts "To proceed, enter a command from above or type 'back' to return to what you were doing".colorize(:light_blue) self.choose_after_help end |
#parse_input(input) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/podcast_finder/commandline.rb', line 76 def parse_input(input) if input.match(/^\d+$/) @input = input.to_i elsif input.upcase == "HELP" || input.upcase == "MENU" || input.upcase == "EXIT" || input.upcase == "MORE" || input.upcase == "BACK" || input.upcase == "PODCASTS" @input = input.upcase else @input = "STUCK" end end |
#proceed_based_on_input ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/podcast_finder/commandline.rb', line 86 def proceed_based_on_input case @input when "STUCK" puts "Sorry, that's not an option. Please type a command from the options above. Stuck? Type 'help'.".colorize(:light_blue) when "HELP" self.help when "MENU" self.browse_all_categories when "EXIT" @quit = "YES" when @input == "BACK" || @input == "MORE" || @input == "PODCASTS" @input when @input == Fixnum && @input >= 1 @input end end |
#start_import ⇒ Object
37 38 39 |
# File 'lib/podcast_finder/commandline.rb', line 37 def start_import PodcastFinder::DataImporter.import_categories('http://www.npr.org/podcasts') end |
#startup_sequence ⇒ Object
methods needed for startup
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/podcast_finder/commandline.rb', line 19 def startup_sequence puts "Setting up your command line podcast finder...".colorize(:light_red) self.start_import sleep(0.5) puts ".".colorize(:light_red) sleep(0.5) puts ".".colorize(:light_yellow) sleep(0.5) puts ".".colorize(:light_green) sleep(0.5) puts "Setup complete.".colorize(:light_green) sleep(0.5) puts "" puts "Welcome to the Command Line Podcast Finder!" puts "You can use this command line gem to find and listen to interesting podcasts produced by NPR and affiliated stations." sleep(0.5) end |