Class: TedTalks::CLI
- Inherits:
-
Object
- Object
- TedTalks::CLI
- Defined in:
- lib/ted_talks/cli.rb
Overview
Our CLI Controller
Instance Method Summary collapse
- #call ⇒ Object
- #display_talk_info(talk_info) ⇒ Object
- #goodbye ⇒ Object
- #list_categories ⇒ Object
- #list_talks(url = 'http://www.ted.com/talks') ⇒ Object
- #menu ⇒ Object
Instance Method Details
#call ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/ted_talks/cli.rb', line 4 def call puts "Today's TED ideas worth spreading. Check out the top 10 talks today!" puts " " list_categories goodbye end |
#display_talk_info(talk_info) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ted_talks/cli.rb', line 95 def display_talk_info(talk_info) puts " " puts "------------------TED------------------------" puts talk_info. puts talk_info.title puts " " puts "-----------------Details---------------------" puts talk_info.description puts " " puts "Time #{talk_info.time} " puts talk_info.date puts " " puts "Total views: #{talk_info.views} " puts "----------------------------------------------" end |
#goodbye ⇒ Object
111 112 113 |
# File 'lib/ted_talks/cli.rb', line 111 def goodbye puts "See you tomorrow for more talks." end |
#list_categories ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ted_talks/cli.rb', line 22 def list_categories puts "Here are 7 different categories. Enter the number or name of the category you'd like to see more videos about." puts " " puts "1. Top Talks" puts "2. Technology" puts "3. Entertainment" puts "4. Design" puts "5. Business" puts "6. Science" puts "7. Global Issues" puts " " puts "Or enter search if you would like to search for videos." input = gets.strip.downcase categories_hash = { "top talks" => "1", "technology" => "2", "entertainment" => "3", "design" => "4", "business" => "5", "science" => "6", "global+issues" => "7" } if input.to_i == 1 list_talks elsif input.to_i > 1 && input.to_i <= 7 url_value = categories_hash.key(input) url = "http://www.ted.com/talks?topics%5B%5D=#{url_value}&sort=newest" list_talks(url) elsif categories_hash.key?(input) url_value = input url = "http://www.ted.com/talks?topics%5B%5D=#{url_value}&sort=newest" list_talks(url) elsif input == "search" puts "Enter your search term." url_value = gets.strip.downcase url_value.gsub! /\s+/, '+' url = "http://www.ted.com/talks?q=#{url_value}&sort=newest" list_talks(url) elsif input == "exit" exit end end |
#list_talks(url = 'http://www.ted.com/talks') ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/ted_talks/cli.rb', line 12 def list_talks(url='http://www.ted.com/talks') @talks = TedTalks::Talk.top_talks(url) @talks.each.with_index do |talk, i| puts "#{i+1}. #{talk.title} - #{talk.} - Posted #{talk.date} - Rated #{talk.}" puts " " end end |
#menu ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ted_talks/cli.rb', line 69 def input = nil while input != "exit" puts " " puts "Enter the number of the talk you'd like to learn more about." puts "Enter talks to see the talks again." puts "Enter categories to see the categories again." puts "Enter exit to end the program." input = gets.strip.downcase if input.to_i > 0 the_talk = @talks[input.to_i - 1] @talk_info = TedTalks::Info.talk_info(the_talk.url) display_talk_info(@talk_info) elsif input == "talks" list_talks elsif input == "categories" list_categories elsif input != "exit" puts "Invalid entry." end end end |