class RaEvents::CLI

Constants

URL_BASE

Public Instance Methods

call() click to toggle source
# File lib/ra_events/cli.rb, line 8
def call
  welcome
  list_events
  goto_event_url
end
clear_events() click to toggle source
# File lib/ra_events/cli.rb, line 124
def clear_events
  Event.clear
end
display_and_format_event(event, i) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/ra_events/cli.rb, line 33
def goto_event_url
  prompt_for_event_menu_or_exit
  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
      main_menu
    else
      puts "Invalid"
      goto_event_url
    end
end
list_events() click to toggle source
# 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
      no_events_listed_message
      clear_events
      call
    else
      display_and_format_event(event, i)
    end
  end
end
main_menu() click to toggle source
no_events_listed_message() click to toggle source
# File lib/ra_events/cli.rb, line 92
def no_events_listed_message
  puts "There are currently no events listed for this week in this region."
  puts
end
open_url_in_browser(event) click to toggle source
# File lib/ra_events/cli.rb, line 114
def open_url_in_browser(event)
  `open #{URL_BASE + event.url}`
end
print_url(event) click to toggle source
prompt_for_event_menu_or_exit() click to toggle source
# File lib/ra_events/cli.rb, line 105
def prompt_for_event_menu_or_exit
  puts "Type the event # you'd like to view in your browser, 'menu' or 'exit':"
end
prompt_for_state() click to toggle source
# File lib/ra_events/cli.rb, line 88
def prompt_for_state
  puts "Please enter your state(ex: MI, NY, CA):"
end
scrape_events() click to toggle source
# File lib/ra_events/cli.rb, line 84
def scrape_events
  Scraper.scrape_events_page(get_event_url)
end
welcome() click to toggle source
# File lib/ra_events/cli.rb, line 14
def welcome
  puts "Welcome to ra_events! A gem that lists electronic music events."
end