Class: BoxingSchedules::CLI
- Inherits:
-
Object
- Object
- BoxingSchedules::CLI
- Defined in:
- lib/boxing-schedules/cli.rb
Instance Method Summary collapse
-
#fight_number(number, fight_detail) ⇒ Object
passes in fight number selected by the user and fight detail for selected fight.
- #goodbye ⇒ Object
- #invalid_input ⇒ Object
-
#main_menu ⇒ Object
displays main menu for fight options.
-
#number_of_fights ⇒ Object
calls on all fight objects from Fight class.
-
#print_fight_details(fight_detail) ⇒ Object
prints out details for fights option chosen by user using metaprograming.
-
#scheduled_fight_details ⇒ Object
iterates through all fight instances of Fight.all and grabs the attributes to display each fight details to the user.
-
#scheduled_fights_scraper ⇒ Object
calls on Scraper class method.
-
#select_fight_number(selected_fight) ⇒ Object
determines if user chooses to view specific fight number.
-
#start ⇒ Object
calls Scraper scrape scheduled fights method.
-
#view_fight(fight_detail) ⇒ Object
gets user input for fight number selected.
-
#view_fight_input ⇒ Object
gets user input for viewing specific fight.
Instance Method Details
#fight_number(number, fight_detail) ⇒ Object
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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
132 133 134 135 |
# File 'lib/boxing-schedules/cli.rb', line 132 def goodbye puts "Goodbye from The Boxing Schedules CLI App!".blue puts "------------------------------------------".red end |
#invalid_input ⇒ Object
128 129 130 |
# File 'lib/boxing-schedules/cli.rb', line 128 def invalid_input puts "Invalid input, that is not an option.".red end |
#main_menu ⇒ Object
displays main menu for fight options
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/boxing-schedules/cli.rb', line 4 def puts "\t\t -----------------------------".red puts "Hello, Welcome to #{"The Boxing Schedules CLI App".blue}" puts "\t\t -----------------------------".red puts "Which displayed option would you like to select(Type the number to select):" puts "1. All Fight Details" puts "2. Fight Channels & Locations" puts "3. Fight Times" puts "4. Fighter Names" puts "5. Fight Links" puts "Type 'exit' to quit." puts "Type 'list' to see options again." end |
#number_of_fights ⇒ Object
calls on all fight objects from Fight class
24 25 26 |
# File 'lib/boxing-schedules/cli.rb', line 24 def number_of_fights BoxingSchedules::Fight.all end |
#print_fight_details(fight_detail) ⇒ Object
prints out details for fights option chosen by user using metaprograming.
85 86 87 88 89 90 91 |
# 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 ⇒ Object
iterates through all fight instances of Fight.all and grabs the attributes to display each fight details to the user.
30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
calls on Scraper class method
19 20 21 |
# File 'lib/boxing-schedules/cli.rb', line 19 def scheduled_fights_scraper BoxingSchedules::Scraper.scrape_scheduled_fights end |
#select_fight_number(selected_fight) ⇒ Object
determines if user chooses to view specific fight number.
77 78 79 80 81 |
# 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 ⇒ Object
calls Scraper scrape scheduled fights method. gets user input and determines which option to display based on number input by the user.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/boxing-schedules/cli.rb', line 96 def start scheduled_fights_scraper user_input = nil while user_input != 'exit' 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' else invalid_input end end end |
#view_fight(fight_detail) ⇒ Object
gets user input for fight number selected.
69 70 71 72 73 |
# 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 ⇒ Object
gets user input for viewing specific fight.
63 64 65 66 |
# 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 |