Class: HofStats::CLI
- Inherits:
-
Object
- Object
- HofStats::CLI
- Defined in:
- lib/hof_stats/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #goodbye ⇒ Object
- #list_individual_player(player) ⇒ Object
- #list_players ⇒ Object
- #menu ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 |
# File 'lib/hof_stats/cli.rb', line 3 def call list_players goodbye end |
#goodbye ⇒ Object
73 74 75 |
# File 'lib/hof_stats/cli.rb', line 73 def goodbye puts "Goodbye!" end |
#list_individual_player(player) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hof_stats/cli.rb', line 24 def list_individual_player(player) puts "Player Name: #{player.name}" if player.position == "" || player.position == "Manager" puts "No stats available for #{player.name}." else puts "Position: #{player.position}" if player.position.include? "Pitcher" puts "ERA: #{player.era}" puts "W/L %: #{player.wlpercent}" puts "Strikeouts: #{player.strikeouts}" else puts "Games: #{player.games}" puts "Hits: #{player.hits}" puts "Runs: #{player.runs}" puts "Homers: #{player.homers}" puts "Batting Average: #{player.batting_avg}" end end end |
#list_players ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hof_stats/cli.rb', line 9 def list_players HofStats::Scraper.new.make_player puts "MLB Hall of Famers" @players = HofStats::Player.all @players.each_with_index do |player, i| if player.votes == "" player.votes = "N/A" end if player.percent == "" player.percent = "N/A %" end puts "#{i+1}. #{player.name} - #{player.year} - #{player.votes} votes - #{player.percent}" end end |
#menu ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hof_stats/cli.rb', line 44 def input = nil puts "" puts "Enter the line number of a player to see more info." puts "Type 'exit' to exit." input = gets.strip.downcase if input == "exit" goodbye exit() elsif input.to_i < 1 || input.to_i > HofStats::Player.all.length puts "Please enter a valid line number." else player = HofStats::Player.all[input.to_i - 1] puts "***************************" list_individual_player(player) puts "***************************" puts "Would you like to see another player? (Y or N)" input = gets.strip.downcase if input == "y" end end end |