class EventsNearby::CLI
CLI
Controller
Public Instance Methods
choose_city()
click to toggle source
Ask user for city input, find or create new city and set @city instance variable
# File lib/events_nearby/cli.rb, line 4 def choose_city puts "What city would you like to see events nearby? (e.g. 'San Francisco, CA')" input = gets.strip.downcase parsed_input = EventsNearby::City.parse_city_input(input) name = parsed_input[:name] state = parsed_input[:state] if EventsNearby::City.find_by(name, state) @city = EventsNearby::City.find_by(name, state) list_events else @city = EventsNearby::Scraper.new.scrape_events(name, state) @city == false ? choose_city : list_events end end
list_events()
click to toggle source
# File lib/events_nearby/cli.rb, line 21 def list_events separator puts "These are the upcoming events for #{@city.name.bold}:".red separator @city.events.each_with_index do |event, i| puts "#{i+1}. #{event.format_event}" end menu end
separator()
click to toggle source
# File lib/events_nearby/cli.rb, line 80 def separator puts "--------------**********--------------".red end
show_details(event)
click to toggle source
# File lib/events_nearby/cli.rb, line 60 def show_details(event) puts "" puts "--- #{event.format_event} ---".green puts event.content puts "" separator puts "Would you like to open this event in your browser? #{'yes'.bold} or #{'no'.bold}?" separator input = gets.strip.downcase if ["y", "yes", "open"].include?(input) event.open_in_browser puts "" menu else menu end end