class BoxingSchedules::CLI
Public Instance Methods
fight_number(number, fight_detail)
click to toggle source
passes in fight number selected by the user and fight detail for selected fight. iterates through scheduled fight details method and selects index of fight matching number passed in.
# File lib/boxing-schedules/cli.rb, line 47 def fight_number(number, fight_detail) number_of_fights.select.with_index(1) do |fight, index| if index == number puts "" puts "Selected fight:" puts "--------------------------------------------------------------------------------------------".red puts "Fight ##{index}:".red puts "Selected details:" + " #{fight.send(fight_detail)}".gsub("More Details", "") puts "Fight Link:" +" #{fight.fight_url}".yellow puts "---------------------------------------------------------------------------------------------".red puts "" end end end
goodbye()
click to toggle source
# File lib/boxing-schedules/cli.rb, line 132 def goodbye puts "Goodbye from The Boxing Schedules CLI App!".blue puts "------------------------------------------".red end
invalid_input()
click to toggle source
# File lib/boxing-schedules/cli.rb, line 128 def invalid_input puts "Invalid input, that is not an option.".red end
number_of_fights()
click to toggle source
calls on all fight objects from Fight class
# File lib/boxing-schedules/cli.rb, line 24 def number_of_fights BoxingSchedules::Fight.all end
print_fight_details(fight_detail)
click to toggle source
prints out details for fights option chosen by user using metaprograming.
# File lib/boxing-schedules/cli.rb, line 85 def print_fight_details(fight_detail) number_of_fights.each_with_index do|fight, index| if index < number_of_fights.size puts "Fight".blue + "##{index+1} ".red + "#{fight.send(fight_detail)}" end end end
scheduled_fight_details()
click to toggle source
iterates through all fight instances of Fight.all and grabs the attributes to display each fight details to the user.
# File lib/boxing-schedules/cli.rb, line 30 def scheduled_fight_details number_of_fights.each_with_index do|fight, index| puts "----------------------------".red + "#{"BOXING SCHEDULES".blue}" + "------------------------------------------------".red puts "Fight ##{index+1}".red puts "Fight Channel & Location: #{fight.channel_location}" puts "Fight Time: #{fight.fight_time}" puts "Fighter Names: #{fight.fighter_names}" puts "All Fight Details: #{fight.fight_details.gsub("More Details", "")}" puts "Fight Link:" + "#{fight.fight_url}".yellow puts "--------------------------------------------------------------------------------------------".red end end
scheduled_fights_scraper()
click to toggle source
calls on Scraper class method
# File lib/boxing-schedules/cli.rb, line 19 def scheduled_fights_scraper BoxingSchedules::Scraper.scrape_scheduled_fights end
select_fight_number(selected_fight)
click to toggle source
determines if user chooses to view specific fight number.
# File lib/boxing-schedules/cli.rb, line 77 def select_fight_number(selected_fight) if view_fight_input == 'y' view_fight(selected_fight) end end
start()
click to toggle source
calls Scraper scrape scheduled fights method. gets user input and determines which option to display based on number input by the user.
# File lib/boxing-schedules/cli.rb, line 96 def start scheduled_fights_scraper user_input = nil while user_input != 'exit' main_menu user_input = gets.strip.downcase case user_input when '1' scheduled_fight_details select_fight_number('fight_details') when '2' print_fight_details('channel_location') select_fight_number('channel_location') when '3' print_fight_details('fight_time') select_fight_number('fight_time') when '4' print_fight_details('fighter_names') select_fight_number('fighter_names') when '5' print_fight_details('fight_url') select_fight_number('fight_url') when 'exit' goodbye when 'list' main_menu else invalid_input end end end
view_fight(fight_detail)
click to toggle source
gets user input for fight number selected.
# File lib/boxing-schedules/cli.rb, line 69 def view_fight(fight_detail) puts "Enter fight number to view specific fight: " fight_num_input = gets.strip.to_i fight_number(fight_num_input, fight_detail) end
view_fight_input()
click to toggle source
gets user input for viewing specific fight.
# File lib/boxing-schedules/cli.rb, line 63 def view_fight_input puts "Would you like to view a specific fight? (y/n)" input = gets.strip.downcase end