Class: BattingLeaders::CLI
- Inherits:
-
Object
- Object
- BattingLeaders::CLI
- Defined in:
- lib/batting_leaders/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #display_list ⇒ Object
- #goodbye ⇒ Object
- #list_players ⇒ Object
- #menu ⇒ Object
- #player_profile(player_url) ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 |
# File 'lib/batting_leaders/cli.rb', line 3 def call @sorted_leading_batters = BattingLeaders::Player.sorted_batters list_players end |
#display_list ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/batting_leaders/cli.rb', line 18 def display_list number_players = gets.strip.to_i puts "" if number_players == 10 || number_players == 20 || number_players == 30 || number_players == 40 puts "---Player--------------------batting ave---" @sorted_leading_batters[0,number_players].each.with_index(1) do |player, index| printf("%-3s", "#{index}:") printf("%-27s", "#{player.name}") puts "#{player.batting_ave}" end else puts "invalid input, please type (10, 20, 30, or 40)" puts "" display_list end puts "" end |
#goodbye ⇒ Object
72 73 74 75 |
# File 'lib/batting_leaders/cli.rb', line 72 def goodbye puts "Check again soon!" puts "" end |
#list_players ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/batting_leaders/cli.rb', line 9 def list_players puts "" puts "List of top MLB players today for batting average:" puts "" puts "Select a number of players displayed (10, 20, 30, or 40)" puts "" display_list end |
#menu ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/batting_leaders/cli.rb', line 36 def input = nil while input != "exit" puts "Enter the number of the player you'd like more info on, type list to see the list again, or type exit." puts "" input = gets.strip.downcase puts "" if (input.to_i > 0) && (input.to_i < 41) player_url = @sorted_leading_batters[input.to_i - 1].url player_profile(player_url) elsif input == "list" list_players elsif input == "exit" goodbye else puts "invalid input, please type again (1 .. 40), list, or exit" end end end |
#player_profile(player_url) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/batting_leaders/cli.rb', line 56 def player_profile(player_url) player = BattingLeaders::Player.find_player_by_url(player_url) puts "name: #{player.name}" puts "batting ave: #{player.batting_ave}" puts "number and position: #{player.other_details[:number_position]}" puts "team: #{player.other_details[:team]}" puts "HR (this season): #{player.other_details[:homerun]}" puts "RBI (this season): #{player.other_details[:rbi]}" puts "OBP (this season): #{player.other_details[:obp]}" puts "birth date: #{player.other_details[:birth_date]}" puts "experience: #{player.other_details[:experience]}" puts "college: #{player.other_details[:college]}" puts "Ht/Wt: #{player.other_details[:ht_wt]}" puts "" end |