Class: RaEvents::CLI
- Inherits:
-
Object
- Object
- RaEvents::CLI
- Defined in:
- lib/ra_events/cli.rb
Constant Summary collapse
- EVENT_LINKS_BY_STATE =
{"AL"=>"/events.aspx?ai=108", "AK"=>"/events.aspx?ai=109", "AZ"=>"/events.aspx?ai=102", "AR"=>"/events.aspx?ai=110", "CA"=>"/events.aspx?ai=308", "CO"=>"/events.aspx?ai=82", "CT"=>"/events.aspx?ai=111", "DE"=>"/events.aspx?ai=112", "DC"=>"District of Columbia", "FL"=>"/events.aspx?ai=317", "GA"=>"/events.aspx?ai=64", "HI"=>"/events.aspx?ai=133", "ID"=>"/events.aspx?ai=113", "IL"=>"/events.aspx?ai=359", "IN"=>"/events.aspx?ai=85", "IA"=>"/events.aspx?ai=114", "KS"=>"/events.aspx?ai=90", "KY"=>"/events.aspx?ai=115", "LA"=>"/events.aspx?ai=65", "ME"=>"/events.aspx?ai=116", "MD"=>"/events.aspx?ai=117", "MA"=>"/events.aspx?ai=79", "MI"=>"/events.aspx?ai=360", "MN"=>"/events.aspx?ai=81", "MS"=>"/events.aspx?ai=103", "MO"=>"/events.aspx?ai=118", "MT"=>"/events.aspx?ai=119", "NE"=>"/events.aspx?ai=120", "NV"=>"/events.aspx?ai=47", "NH"=>"/events.aspx?ai=121", "NJ"=>"/events.aspx?ai=48", "NM"=>"/events.aspx?ai=122", "NY"=>"/events.aspx?ai=8", "NC"=>"/events.aspx?ai=123", "ND"=>"/events.aspx?ai=124", "OH"=>"/events.aspx?ai=84", "OK"=>"/events.aspx?ai=104", "OR"=>"/events.aspx?ai=125", "PA"=>"/events.aspx?ai=80", "RI"=>"/events.aspx?ai=127", "SC"=>"/events.aspx?ai=105", "SD"=>"/events.aspx?ai=128", "TN"=>"/events.aspx?ai=72", "TX"=>"/events.aspx?ai=318", "UT"=>"/events.aspx?ai=106", "VT"=>"/events.aspx?ai=129", "VA"=>"/events.aspx?ai=130", "WA"=>"Washington", "WV"=>"/events.aspx?ai=131", "WI"=>"/events.aspx?ai=107", "WY"=>"/events.aspx?ai=132"}
- URL_BASE =
"https://www.residentadvisor.net"
Instance Method Summary collapse
- #call ⇒ Object
- #clear_events ⇒ Object
- #display_and_format_event(event, i) ⇒ Object
- #display_events_this_week_text ⇒ Object
- #exit_program ⇒ Object
- #get_event_url ⇒ Object
- #goto_event_url ⇒ Object
- #list_events ⇒ Object
- #main_menu ⇒ Object
- #no_events_listed_message ⇒ Object
- #open_url_in_browser(event) ⇒ Object
- #print_url(event) ⇒ Object
- #prompt_for_event_menu_or_exit ⇒ Object
- #prompt_for_state ⇒ Object
- #scrape_events ⇒ Object
- #welcome ⇒ Object
Instance Method Details
#call ⇒ Object
8 9 10 11 12 |
# File 'lib/ra_events/cli.rb', line 8 def call welcome list_events goto_event_url end |
#clear_events ⇒ Object
124 125 126 |
# File 'lib/ra_events/cli.rb', line 124 def clear_events Event.clear end |
#display_and_format_event(event, i) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/ra_events/cli.rb', line 97 def display_and_format_event(event, i) puts "#{i}. #{event.title} " puts "Location: #{event.location} " unless event.artists.nil? puts "Artists: #{event.artists}" unless event.artists.nil? puts "Date: #{event.date.gsub("T00:00", "")}" puts end |
#display_events_this_week_text ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ra_events/cli.rb', line 68 def display_events_this_week_text puts "Events this week:" puts "****************" sleep 0.1 puts "*************" sleep 0.1 puts "**********" sleep 0.1 puts "*******" sleep 0.1 puts "****" sleep 0.1 puts "**" sleep 0.1 end |
#exit_program ⇒ Object
118 119 120 121 122 |
# File 'lib/ra_events/cli.rb', line 118 def exit_program clear_events puts "Bye, see you on the dance floor!" exit end |
#get_event_url ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ra_events/cli.rb', line 53 def get_event_url prompt_for_state state = gets.strip.upcase if EVENT_LINKS_BY_STATE.key?(state) url = URL_BASE + EVENT_LINKS_BY_STATE[state] else puts "Invalid" get_event_url end end |
#goto_event_url ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ra_events/cli.rb', line 33 def goto_event_url input = gets.strip.downcase if input.to_i > 0 && input.to_i <= Event.all.count event = Event.all[input.to_i - 1] print_url(event) open_url_in_browser(event) goto_event_url elsif input == "exit" exit_program elsif input == "menu" clear_events else puts "Invalid" goto_event_url end end |
#list_events ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ra_events/cli.rb', line 18 def list_events scrape_events display_events_this_week_text Event.all.each.with_index(1) do |event, i| if event.no_events_listed == true clear_events call else display_and_format_event(event, i) end end end |
#main_menu ⇒ Object
64 65 66 |
# File 'lib/ra_events/cli.rb', line 64 def call end |
#no_events_listed_message ⇒ Object
92 93 94 95 |
# File 'lib/ra_events/cli.rb', line 92 def puts "There are currently no events listed for this month in this region." puts end |
#open_url_in_browser(event) ⇒ Object
114 115 116 |
# File 'lib/ra_events/cli.rb', line 114 def open_url_in_browser(event) `open #{URL_BASE + event.url}` end |
#print_url(event) ⇒ Object
109 110 111 112 |
# File 'lib/ra_events/cli.rb', line 109 def print_url(event) puts "Opening residentadvisor.net..." puts "#{URL_BASE + event.url}" end |
#prompt_for_event_menu_or_exit ⇒ Object
105 106 107 |
# File 'lib/ra_events/cli.rb', line 105 def puts "Type the event # you'd like to view in your browser, 'menu' or 'exit':" end |
#prompt_for_state ⇒ Object
88 89 90 |
# File 'lib/ra_events/cli.rb', line 88 def prompt_for_state puts "Please enter your state(ex: MI, NY, CA):" end |
#scrape_events ⇒ Object
84 85 86 |
# File 'lib/ra_events/cli.rb', line 84 def scrape_events Scraper.scrape_events_page(get_event_url) end |
#welcome ⇒ Object
14 15 16 |
# File 'lib/ra_events/cli.rb', line 14 def welcome puts "Welcome to ra_events! A gem that lists electronic music events." end |