Class: NbaDraft2017::Cli
- Inherits:
-
Object
- Object
- NbaDraft2017::Cli
- Defined in:
- lib/nba_draft_2017/cli.rb
Constant Summary collapse
- @@key_stats =
['ppg', 'rpg', 'apg', 'tpg', 'spg', 'bpg', 'mpg', 'fg', 'three', 'ft']
Instance Method Summary collapse
- #add_attributes_to_players ⇒ Object
- #call ⇒ Object
- #compare_stats ⇒ Object
- #dotted_line ⇒ Object
- #error ⇒ Object
- #find_and_list_player ⇒ Object
- #good_bye ⇒ Object
- #list_controls ⇒ Object
- #list_draft ⇒ Object
- #list_draft_picks_by_former_team ⇒ Object
- #list_draft_picks_by_nba_team ⇒ Object
- #list_player_details(player) ⇒ Object
- #list_round_1 ⇒ Object
- #list_round_2 ⇒ Object
- #make_players ⇒ Object
- #menu ⇒ Object
- #more_info_on_player?(team) ⇒ Boolean
Instance Method Details
#add_attributes_to_players ⇒ Object
57 58 59 60 61 |
# File 'lib/nba_draft_2017/cli.rb', line 57 def add_attributes_to_players NbaDraft2017::Player.all.each do |player| add_attributes_to_player(player.name) end end |
#call ⇒ Object
5 6 7 8 9 |
# File 'lib/nba_draft_2017/cli.rb', line 5 def call puts 'Welcome to the 2017 NBA Draft!' make_players end |
#compare_stats ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/nba_draft_2017/cli.rb', line 153 def compare_stats puts "This might take a minute for first comaprison.".bold.colorize(:green) puts "To proceed enter a stat category from #{@@key_stats} or 'menu' to return to menu" stat_category = gets.downcase.strip if @@key_stats.include?(stat_category) puts "Enter a number to see players that have a higher average for #{stat_category.colorize(:green)} and make sure to enter a decimal for fg%, three%, and ft%" stat_num = gets.strip if stat_num.to_f.between?(0.001,40) NbaDraft2017::Player.stat_greater_than(stat_category, stat_num) elsif stat_num == 'menu' || stat_num == 'exit' else error end elsif stat_category == 'menu' || stat_category == 'exit' else error end end |
#dotted_line ⇒ Object
49 50 51 |
# File 'lib/nba_draft_2017/cli.rb', line 49 def dotted_line puts "------------------------------------------------------------".bold.colorize(:red) end |
#error ⇒ Object
228 229 230 231 |
# File 'lib/nba_draft_2017/cli.rb', line 228 def error puts "I didn't understand that! Please try agian or type 'exit'.".colorize(:red).bold puts "------------------------------------------------------------".colorize(:green).bold end |
#find_and_list_player ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/nba_draft_2017/cli.rb', line 106 def find_and_list_player puts "Please enter player draft pick number or player name." lookup = gets.strip if lookup.to_i.between?(1, NbaDraft2017::Player.all.size) player = NbaDraft2017::Player.find_player_by_pick(lookup) list_player_details(player) elsif player ||= NbaDraft2017::Player.find_player_by_name(lookup) list_player_details(player) else error end player end |
#good_bye ⇒ Object
233 234 235 |
# File 'lib/nba_draft_2017/cli.rb', line 233 def good_bye puts "Thanks for checking out the 2017 NBA Draft! Good Luck!" end |
#list_controls ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nba_draft_2017/cli.rb', line 91 def list_controls draft = "'draft'" round_1 = "'rd1'" round_2 = "'rd2'" player = "'player'" nba_team = "'nba'" former_team = "'former'" puts "Enter #{draft.colorize(:green)}, #{round_1.colorize(:green)} or #{round_2.colorize(:green)} to see list of draft picks." puts "Enter #{player.colorize(:green)} to see player details and stats" puts "Enter #{nba_team.colorize(:green)} to show players drafted by a NBA team" puts "Enter #{former_team.colorize(:green)} to show players drated out of colleges or clubs" puts "Enter " + "'compare stats'".colorize(:green) + " to see player with stat average above number specified by user" puts "To quit, type" + " 'exit'".colorize(:green) end |
#list_draft ⇒ Object
11 12 13 14 |
# File 'lib/nba_draft_2017/cli.rb', line 11 def list_draft list_round_1 list_round_2 end |
#list_draft_picks_by_former_team ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/nba_draft_2017/cli.rb', line 188 def list_draft_picks_by_former_team puts NbaDraft2017::Player.former_teams.sort puts 'Enter a School or Country name exactly as shown in list above:'.colorize(:green) former_team = gets.strip.downcase if NbaDraft2017::Player.former_teams.include?(former_team) NbaDraft2017::Player.players_by_former_team(former_team) more_info_on_player?(former_team) else error end end |
#list_draft_picks_by_nba_team ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/nba_draft_2017/cli.rb', line 174 def list_draft_picks_by_nba_team puts NbaDraft2017::Player.nba_teams.sort puts 'Enter an NBA team (name only) as in list above:'.colorize(:green) nba_team = gets.strip.downcase if NbaDraft2017::Player.nba_teams.include?(nba_team) NbaDraft2017::Player.players_by_nba_team(nba_team) more_info_on_player?(nba_team) else error end end |
#list_player_details(player) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/nba_draft_2017/cli.rb', line 121 def list_player_details(player) if NbaDraft2017::Player.all_attributes player else player = NbaDraft2017::Player.add_attributes_to_player(player) end puts "#{player.name.upcase.bold.underline}".colorize(:green).bold puts " Round:".bold.colorize(:red) +" #{player.round}" + " Pick:".bold.colorize(:red) +" #{player.pick}" puts " Drafted By:".bold.colorize(:red) +" #{player.nba_team}" puts " From:".bold.colorize(:red) +" #{player.former_team}" puts " Position:".bold.colorize(:red) +" #{player.position}" puts " Drafted As:".bold.colorize(:red) +" #{player.former_status}" puts " Age:".bold.colorize(:red) +" #{player.age}" puts " Height:".bold.colorize(:red) +" #{player.height}" puts " Weight:".bold.colorize(:red) +" #{player.weight}" puts " STATS".colorize(:green).bold if player.key_stats if player.key_stats puts " PPG:".bold.colorize(:red) + " #{player.ppg}" if player.ppg puts " RPG:".bold.colorize(:red) + " #{player.rpg}" if player.rpg puts " APG:".bold.colorize(:red) + " #{player.apg}" if player.apg puts " FG:".bold.colorize(:red) + " #{(player.fg * 100).round(2)}%" if player.fg puts " 3PT:".bold.colorize(:red) + " #{(player.three * 100).round(2)}%" if player.three puts " FT:".bold.colorize(:red) + " #{(player.ft * 100).round(2)}%" if player.ft puts " TPG:".bold.colorize(:red) + " #{player.tpg}" if player.tpg puts " SPG:".bold.colorize(:red) + " #{player.spg}" if player.spg puts " BPG:".bold.colorize(:red) + " #{player.bpg}" if player.bpg puts " MPG:".bold.colorize(:red) + " #{player.mpg}" if player.mpg end end |
#list_round_1 ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nba_draft_2017/cli.rb', line 16 def list_round_1 dotted_line puts "Round 1".colorize(:blue).bold dotted_line i = 0 while i < 30 player = NbaDraft2017::Player.all[i] if i < 9 puts "#{i + 1}. #{player.name.colorize(:green).bold} #{player.position.colorize(:red)} from #{player.former_team.colorize(:blue).bold} drafted by #{player.nba_team.colorize(:green).bold}" else puts "#{i + 1}. #{player.name.colorize(:green).bold} #{player.position.colorize(:red)} from #{player.former_team.colorize(:blue).bold} drafted by #{player.nba_team.colorize(:green).bold}" end i += 1 end dotted_line end |
#list_round_2 ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nba_draft_2017/cli.rb', line 35 def list_round_2 puts "Round 2".colorize(:blue).bold dotted_line i = 30 while i < 60 player = NbaDraft2017::Player.all[i] puts "#{i + 1}. #{player.name.colorize(:green).bold} #{player.position.colorize(:red)} from #{player.former_team.colorize(:blue).bold} drafted by #{player.nba_team.colorize(:green).bold}" i += 1 end dotted_line end |
#make_players ⇒ Object
53 54 55 |
# File 'lib/nba_draft_2017/cli.rb', line 53 def make_players NbaDraft2017::Scraper.scrape_draft end |
#menu ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/nba_draft_2017/cli.rb', line 63 def input = nil while input != 'exit' list_controls input = gets.strip.downcase if input == 'draft' list_draft elsif input == 'rd1' || input == 'rd 1' list_round_1 elsif input == 'rd2' || input == 'rd 2' list_round_2 elsif input == 'player' || input == 'players' find_and_list_player elsif input == 'nba team' || input == 'nba' list_draft_picks_by_nba_team elsif input == 'former team' || input == 'former' list_draft_picks_by_former_team elsif input == 'compare stats' compare_stats elsif input == 'exit' good_bye else error end end end |
#more_info_on_player?(team) ⇒ Boolean
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/nba_draft_2017/cli.rb', line 202 def more_info_on_player?(team) request = nil while request != 'n' && request != 'exit' puts "Would you like more info on any of the players? 'y' or 'n'?" request = gets.downcase.strip if request =='y' player = find_and_list_player if player.nba_team.downcase != team.downcase && player.former_team.downcase != team.downcase dotted_line puts "That player isn't on or from #{team} though!!!".upcase.bold.colorize(:red) dotted_line end elsif request == 'n' || request == 'exit' break else error end end end |