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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/command_line_interface.rb', line 79 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, or enter 'back' to go back to the schedule" input = gets.strip #14.between?(10,20) # true if input.to_i.between?(1, 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}" choose_fight(event) elsif input == "exit" goodbye exit elsif input == "back" list_schedule else invalid_command_response choose_fight(event) end end |
#choose_fight_card ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/command_line_interface.rb', line 43 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) #Verify fights have been created if Concerns::EventFight.all.size == 0 goodbye exit end input = gets.strip if input.to_i.between?(1, Concerns::Events.all.size) system "clear" list_fights(input.to_i) elsif input == "back" list_schedule elsif input == "exit" goodbye exit else invalid_command_response choose_fight_card end end |
#choose_to_view_schedule ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/command_line_interface.rb', line 17 def choose_to_view_schedule #Takes user input and returns schedule if input == "1" input = nil input = gets.strip if input == "1" system "clear" list_schedule elsif input == "exit" goodbye exit else invalid_command_response choose_to_view_schedule end end |
#goodbye ⇒ Object
106 107 108 |
# File 'lib/command_line_interface.rb', line 106 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'. To go back to the previous menu, enter 'back'." puts "" Concerns::API.get_categories end |
#invalid_command_response ⇒ Object
110 111 112 |
# File 'lib/command_line_interface.rb', line 110 def invalid_command_response puts "Please enter a valid command." end |
#list_fights(input) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/command_line_interface.rb', line 69 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
34 35 36 37 38 39 40 41 |
# File 'lib/command_line_interface.rb', line 34 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 |