Class: NbaInfo::CLI
- Inherits:
-
Object
- Object
- NbaInfo::CLI
- Defined in:
- lib/nba_info/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #instruct ⇒ Object
- #key ⇒ Object
- #schedule ⇒ Object
- #standings ⇒ Object
- #team ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nba_info/cli.rb', line 3 def call instruct input = gets.strip.downcase until input == "exit" case input when "commands" instruct input = gets.strip.downcase when "key" key input = gets.strip.downcase when "schedule" schedule input = gets.strip.downcase when "standings" standings input = gets.strip.downcase when "team" team input = gets.strip.downcase else puts "Not a valid command" input = gets.strip.downcase end end end |
#instruct ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nba_info/cli.rb', line 30 def instruct puts <<-DOC.gsub /^\s*/, '' Welcome to the NBA Info CLI gem! List of commands: commands - show these commands again key - show meanings of the stat abbreviations schedule - show todays schedule standings - show current standings team - get more info about a team exit - exit program DOC end |
#key ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/nba_info/cli.rb', line 90 def key puts <<-DOC.gsub /^\s*/, '' GB - games back PPG - points per game OPP PPG - opponents points per game L10 - last 10 Strk - current winning/losing streak DOC end |
#schedule ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/nba_info/cli.rb', line 43 def schedule sched = NbaInfo::Scraper.scrape_schedule puts "All times are Eastern Standard" sched.each do |game| puts "#{game[:away].ljust(4)} @ #{game[:home].ljust(4)} - #{game[:time]}/#{game[:tv]}" end "" end |
#standings ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/nba_info/cli.rb', line 52 def standings nba = NbaInfo::Team.add_stats puts <<-DOC.gsub /^\s*/, '' EASTERN CONFERENCE Team | Record | Win % | GB ------------------------------------------------ DOC nba[:east].each do |team| puts "#{team.name.ljust(23)}| #{team.record.ljust(9)}| #{team.win_pct.ljust(6)}| #{team.gb}" end puts <<-DOC.gsub /^\s*/, '' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WESTERN CONFERENCE Team | Record | Win % | GB ------------------------------------------------ DOC nba[:west].each do |team| puts "#{team.name.ljust(23)}| #{team.record.ljust(9)}| #{team.win_pct.ljust(6)}| #{team.gb}" end "" end |
#team ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/nba_info/cli.rb', line 74 def team nba = NbaInfo::Team.add_stats puts "Type the name of a team (omit the city from the search e.g. new york knicks would just be knicks)" input = gets.strip.capitalize if nba[:east].any?{|team| team.name.include?(input)} team = nba[:east].detect{|t| t.name.include?(input)} puts "#{team.name}(#{team.record}) -- PPG: #{team.ppg} -- OPP PPG: #{team.opp_ppg} -- Diff: #{team.diff} -- L10: #{team.l_ten} -- Strk: #{team.streak}" elsif nba[:west].any?{|team| team.name.include?(input)} team = nba[:west].detect{|t| t.name.include?(input)} puts "#{team.name}(#{team.record}) -- PPG: #{team.ppg} -- OPP PPG: #{team.opp_ppg} -- Diff: #{team.diff} -- L10: #{team.l_ten} -- Strk: #{team.streak}" else "Make sure you omitted the city and spelled the team name correctly" end "" end |