Class: Concerns::CommandLineInterface
- Inherits:
-
Object
- Object
- Concerns::CommandLineInterface
- Extended by:
- SharedCLIMethods
- Defined in:
- lib/command_line_interface.rb
Instance Method Summary collapse
- #choose_fight(event) ⇒ Object
- #choose_fight_card ⇒ Object
- #choose_to_view_schedule ⇒ Object
- #goodbye ⇒ Object
- #greeting ⇒ Object
- #invalid_command_response ⇒ Object
- #list_fights(input) ⇒ Object
- #list_schedule ⇒ Object
- #run ⇒ Object
Instance Method Details
#choose_fight(event) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/command_line_interface.rb', line 68 def choose_fight(event) #Allows user to choose a specific fight and pulls stats on fighters in that fight puts "" puts "To see stats of the fighters, enter the number of their corresponding fight" input = nil while input != "exit" input = gets.strip if input.to_i <= event.event_fights.count specific_fight = event.event_fights[input.to_i - 1] puts "Name: #{specific_fight.red_name} #{specific_fight.blue_name}" puts "Record: #{specific_fight.red_record} #{specific_fight.blue_record}" puts "Height: #{specific_fight.red_height} #{specific_fight.blue_height}" puts "Weight: #{specific_fight.red_weight} #{specific_fight.blue_weight}" break elsif input.to_i <= 0 || input.to_i > event.event_fights.count invalid_command_response choose_fight(event) break end end end |
#choose_fight_card ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/command_line_interface.rb', line 42 def choose_fight_card #Scrapes all the fights from all of the events listed on the schedule and creates fight objects related to each event. Allows user to choose an event, if valid, it will list fights for that event Concerns::API.scrape_fights(Concerns::Events.all) input = nil while input != "exit" input = gets.strip if input.to_i > 0 && input.to_i <= Concerns::Events.all.size list_fights(input.to_i) else invalid_command_response end end end |
#choose_to_view_schedule ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/command_line_interface.rb', line 17 def choose_to_view_schedule #Takes user input and returns schedule if input == "1" input = nil while input != "exit" input = gets.strip if input == "1" list_schedule #breaks the loop so person only has to type 'exit' once to leave the program break elsif input != "exit" && input != "1" invalid_command_response end end end |
#goodbye ⇒ Object
93 94 95 |
# File 'lib/command_line_interface.rb', line 93 def goodbye puts "Goodbye" end |
#greeting ⇒ Object
10 11 12 13 14 15 |
# File 'lib/command_line_interface.rb', line 10 def greeting #greets the user and makes a call to the UFC API to request schedule data puts "Hello fight fan, welcome to your UFC gem! To view a list of upcoming UFC events enter '1'. To exit this gem at any time, enter 'exit'." puts "" Concerns::API.get_categories end |
#invalid_command_response ⇒ Object
97 98 99 |
# File 'lib/command_line_interface.rb', line 97 def invalid_command_response puts "Please enter a valid command." end |
#list_fights(input) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/command_line_interface.rb', line 58 def list_fights(input) #finds an event and lists the fights on that event and calls the choose_fight function find_event = Concerns::Events.all[input - 1] find_event.event_fights.each_with_index do |fight, index| puts "#{index +1 }. #{fight.red_name} vs. #{fight.blue_name} - #{fight.red_weight}" end choose_fight(find_event) end |
#list_schedule ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/command_line_interface.rb', line 33 def list_schedule #List current UFC events from API data and prompts user to learn more info on the events Concerns::Events.list_events puts "" puts "To learn more about who's fighting, enter the number of the fight card you'd like more info on." puts "" choose_fight_card end |
#run ⇒ Object
4 5 6 7 8 |
# File 'lib/command_line_interface.rb', line 4 def run greeting choose_to_view_schedule goodbye end |