Class: Concerns::CommandLineInterface

Inherits:
Object
  • Object
show all
Extended by:
SharedCLIMethods
Defined in:
lib/command_line_interface.rb

Instance Method Summary collapse

Instance Method Details

#choose_fight(event) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/command_line_interface.rb', line 69

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_cardObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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 = gets.strip

    if input.to_i.between?(1, Concerns::Events.all.size)
      list_fights(input.to_i)
    elsif input == "back"
      list_schedule
    elsif input == "exit"
      exit
    else
      invalid_command_response
      choose_fight_card
    end
end

#choose_to_view_scheduleObject



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

  input = gets.strip
  if input == "1"
    list_schedule
  elsif input == "exit"
    goodbye
    exit
  else
    invalid_command_response
    choose_to_view_schedule
  end
end

#goodbyeObject



96
97
98
# File 'lib/command_line_interface.rb', line 96

def goodbye
  puts "Goodbye"
end

#greetingObject



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_responseObject



100
101
102
# File 'lib/command_line_interface.rb', line 100

def invalid_command_response
  puts "Please enter a valid command."
end

#list_fights(input) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/command_line_interface.rb', line 59

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_scheduleObject



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

#runObject



4
5
6
7
8
# File 'lib/command_line_interface.rb', line 4

def run
  greeting
  choose_to_view_schedule
  goodbye
end