Class: OverwatchStats::CLI
- Inherits:
-
Object
- Object
- OverwatchStats::CLI
- Defined in:
- lib/cli.rb
Instance Attribute Summary collapse
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
- #check_width(string, index = 1, column_width = 13) ⇒ Object
- #display_bastion ⇒ Object
- #display_dva ⇒ Object
- #display_genji ⇒ Object
- #display_hanzo ⇒ Object
- #display_junkrat ⇒ Object
- #display_lucio ⇒ Object
- #display_mccree ⇒ Object
- #display_mei ⇒ Object
- #display_pharah ⇒ Object
- #display_reaper ⇒ Object
- #display_reinhardt ⇒ Object
- #display_roadhog ⇒ Object
- #display_soldier76 ⇒ Object
- #display_stats_alphabetically ⇒ Object
- #display_stats_herokd ⇒ Object
- #display_stats_medalpergame ⇒ Object
- #display_stats_popularity ⇒ Object
- #display_stats_winrate ⇒ Object
- #display_symmetra ⇒ Object
- #display_torbjorn ⇒ Object
- #display_tracer ⇒ Object
- #display_widowmaker ⇒ Object
- #display_winston ⇒ Object
- #display_zarya ⇒ Object
- #display_zenyatta ⇒ Object
- #greeting ⇒ Object
- #menu ⇒ Object
- #show_stats(x) ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#stats ⇒ Object
Returns the value of attribute stats.
3 4 5 |
# File 'lib/cli.rb', line 3 def stats @stats end |
Instance Method Details
#check_width(string, index = 1, column_width = 13) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/cli.rb', line 200 def check_width(string, index = 1, column_width = 13) if index < 10 && string.size <= column_width add_space = column_width - string.size - 1 add_space.times do string = string + " " end string elsif index > 9 && string.size <= column_width add_space = column_width - string.size - 2 add_space.times do string = string + " " end end string end |
#display_bastion ⇒ Object
243 244 245 246 |
# File 'lib/cli.rb', line 243 def display_bastion x = OverwatchStats::Hero.bastion show_stats(x) end |
#display_dva ⇒ Object
248 249 250 251 |
# File 'lib/cli.rb', line 248 def display_dva x = OverwatchStats::Hero.dva show_stats(x) end |
#display_genji ⇒ Object
253 254 255 256 |
# File 'lib/cli.rb', line 253 def display_genji x = OverwatchStats::Hero.genji show_stats(x) end |
#display_hanzo ⇒ Object
258 259 260 261 |
# File 'lib/cli.rb', line 258 def display_hanzo x = OverwatchStats::Hero.hanzo show_stats(x) end |
#display_junkrat ⇒ Object
263 264 265 266 |
# File 'lib/cli.rb', line 263 def display_junkrat x = OverwatchStats::Hero.junkrat show_stats(x) end |
#display_lucio ⇒ Object
268 269 270 271 |
# File 'lib/cli.rb', line 268 def display_lucio x = OverwatchStats::Hero.lucio show_stats(x) end |
#display_mccree ⇒ Object
273 274 275 276 |
# File 'lib/cli.rb', line 273 def display_mccree x = OverwatchStats::Hero.mccree show_stats(x) end |
#display_mei ⇒ Object
278 279 280 281 |
# File 'lib/cli.rb', line 278 def display_mei x = OverwatchStats::Hero.mei show_stats(x) end |
#display_pharah ⇒ Object
283 284 285 286 |
# File 'lib/cli.rb', line 283 def display_pharah x = OverwatchStats::Hero.pharah show_stats(x) end |
#display_reaper ⇒ Object
288 289 290 291 |
# File 'lib/cli.rb', line 288 def display_reaper x = OverwatchStats::Hero.reaper show_stats(x) end |
#display_reinhardt ⇒ Object
293 294 295 296 |
# File 'lib/cli.rb', line 293 def display_reinhardt x = OverwatchStats::Hero.reinhardt show_stats(x) end |
#display_roadhog ⇒ Object
298 299 300 301 |
# File 'lib/cli.rb', line 298 def display_roadhog x = OverwatchStats::Hero.roadhog show_stats(x) end |
#display_soldier76 ⇒ Object
303 304 305 306 |
# File 'lib/cli.rb', line 303 def display_soldier76 x = OverwatchStats::Hero.soldier76 show_stats(x) end |
#display_stats_alphabetically ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/cli.rb', line 109 def display_stats_alphabetically stats = OverwatchStats::StatScraper.current byalph = stats.sort_by {|hash| hash[:heroname]} puts "" puts " Stats Sorted Alphabetically" puts "===================================================================================" puts "|| HERO || TYPE || WINRATE || POPULARITY || MEDALS/GM || K/D Ratio ||" byalph.each.with_index(1) do |herostats, index| show_heroname = check_width(herostats[:heroname], index) show_herotype = check_width(herostats[:herotype], 1 , 8) show_winrate = check_width(herostats[:winrate], 1 , 7) show_popularity = check_width(herostats[:popularity], 1 , 8) show_medalpergame = check_width(herostats[:medalpergame], 1 , 8) show_herokd = check_width(herostats[:herokd], 1 , 8) puts "|| #{index}. #{show_heroname} || #{show_herotype} || #{show_winrate} || #{show_popularity} || #{show_medalpergame} || #{show_herokd} ||" end puts "===================================================================================" end |
#display_stats_herokd ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/cli.rb', line 182 def display_stats_herokd stats = OverwatchStats::StatScraper.current byherokd = stats.sort_by {|hash| hash[:herokd].to_f}.reverse puts " Stats Sorted by Herokd" puts "===================================================================================" puts "|| HERO || TYPE || WINRATE || POPULARITY || MEDALS/GM || K/D Ratio ||" byherokd.each.with_index(1) do |herostats, index| show_heroname = check_width(herostats[:heroname], index) show_herotype = check_width(herostats[:herotype], 1 , 8) show_winrate = check_width(herostats[:winrate], 1 , 7) show_popularity = check_width(herostats[:popularity], 1 , 8) show_medalpergame = check_width(herostats[:medalpergame], 1 , 8) show_herokd = check_width(herostats[:herokd], 1 , 8) puts "|| #{index}. #{show_heroname} || #{show_herotype} || #{show_winrate} || #{show_popularity} || #{show_medalpergame} || #{show_herokd} ||" end puts "===================================================================================" end |
#display_stats_medalpergame ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/cli.rb', line 164 def display_stats_medalpergame stats = OverwatchStats::StatScraper.current bymedalpergame = stats.sort_by {|hash| hash[:medalpergame].to_f}.reverse puts " Stats Sorted by Medal/Game" puts "===================================================================================" puts "|| HERO || TYPE || WINRATE || POPULARITY || MEDALS/GM || K/D Ratio ||" bymedalpergame.each.with_index(1) do |herostats, index| show_heroname = check_width(herostats[:heroname], index) show_herotype = check_width(herostats[:herotype], 1 , 8) show_winrate = check_width(herostats[:winrate], 1 , 7) show_popularity = check_width(herostats[:popularity], 1 , 8) show_medalpergame = check_width(herostats[:medalpergame], 1 , 8) show_herokd = check_width(herostats[:herokd], 1 , 8) puts "|| #{index}. #{show_heroname} || #{show_herotype} || #{show_winrate} || #{show_popularity} || #{show_medalpergame} || #{show_herokd} ||" end puts "===================================================================================" end |
#display_stats_popularity ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/cli.rb', line 146 def display_stats_popularity stats = OverwatchStats::StatScraper.current bypopularity = stats.sort_by {|hash| hash[:popularity]}.reverse puts " Stats Sorted by Popularity" puts "===================================================================================" puts "|| HERO || TYPE || WINRATE || POPULARITY || MEDALS/GM || K/D Ratio ||" bypopularity.each.with_index(1) do |herostats, index| show_heroname = check_width(herostats[:heroname], index) show_herotype = check_width(herostats[:herotype], 1 , 8) show_winrate = check_width(herostats[:winrate], 1 , 7) show_popularity = check_width(herostats[:popularity], 1 , 8) show_medalpergame = check_width(herostats[:medalpergame], 1 , 8) show_herokd = check_width(herostats[:herokd], 1 , 8) puts "|| #{index}. #{show_heroname} || #{show_herotype} || #{show_winrate} || #{show_popularity} || #{show_medalpergame} || #{show_herokd} ||" end puts "===================================================================================" end |
#display_stats_winrate ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cli.rb', line 128 def display_stats_winrate stats = OverwatchStats::StatScraper.current bywinrate = stats.sort_by {|hash| hash[:winrate]}.reverse puts " Stats Sorted by Winrate" puts "===================================================================================" puts "|| HERO || TYPE || WINRATE || POPULARITY || MEDALS/GM || K/D Ratio ||" bywinrate.each.with_index(1) do |herostats, index| show_heroname = check_width(herostats[:heroname], index) show_herotype = check_width(herostats[:herotype], 1 , 8) show_winrate = check_width(herostats[:winrate], 1 , 7) show_popularity = check_width(herostats[:popularity], 1 , 8) show_medalpergame = check_width(herostats[:medalpergame], 1 , 8) show_herokd = check_width(herostats[:herokd], 1 , 8) puts "|| #{index}. #{show_heroname} || #{show_herotype} || #{show_winrate} || #{show_popularity} || #{show_medalpergame} || #{show_herokd} ||" end puts "===================================================================================" end |
#display_symmetra ⇒ Object
308 309 310 311 |
# File 'lib/cli.rb', line 308 def display_symmetra x = OverwatchStats::Hero.symmetra show_stats(x) end |
#display_torbjorn ⇒ Object
313 314 315 316 |
# File 'lib/cli.rb', line 313 def display_torbjorn x = OverwatchStats::Hero.torbjorn show_stats(x) end |
#display_tracer ⇒ Object
318 319 320 321 |
# File 'lib/cli.rb', line 318 def display_tracer x = OverwatchStats::Hero.tracer show_stats(x) end |
#display_widowmaker ⇒ Object
323 324 325 326 |
# File 'lib/cli.rb', line 323 def display_widowmaker x = OverwatchStats::Hero.widowmaker show_stats(x) end |
#display_winston ⇒ Object
328 329 330 331 |
# File 'lib/cli.rb', line 328 def display_winston x = OverwatchStats::Hero.winston show_stats(x) end |
#display_zarya ⇒ Object
333 334 335 336 |
# File 'lib/cli.rb', line 333 def display_zarya x = OverwatchStats::Hero.zarya show_stats(x) end |
#display_zenyatta ⇒ Object
338 339 340 341 |
# File 'lib/cli.rb', line 338 def display_zenyatta x = OverwatchStats::Hero.zenyatta show_stats(x) end |
#greeting ⇒ Object
11 12 13 14 |
# File 'lib/cli.rb', line 11 def greeting puts "" puts " Cheers Love! Welcome to OverwatchStats!" end |
#menu ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/cli.rb', line 16 def puts "Type the following to change sorting rules: '(win)rate' '(pop)ularity' 'medal(game)' '(kd)ratio' or '(alph)abetically'." puts "Type the name of one of the above heroes to see more about that hero." puts "Type 'exit' to exit." input = gets.strip.downcase if input == "winrate" || input == "win" display_stats_winrate elsif input == "popularity" || input == "pop" display_stats_popularity elsif input == "medalpergame" || input == "medal" display_stats_medalpergame elsif input == "kdratio" || input == "kd" display_stats_herokd elsif input == "alphabetically" || input == "alph" display_stats_alphabetically elsif input == "bastion" display_bastion elsif input == "d.va" display_dva elsif input == "genji" display_genji elsif input == "hanzo" display_hanzo elsif input == "junkrat" display_junkrat elsif input == "lucio" display_lucio elsif input == "mccree" display_mccree elsif input == "mei" display_mei elsif input == "mercy" display_mercy elsif input == "pharah" display_pharah elsif input == "reaper" display_reaper elsif input == "reinhardt" display_reinhardt elsif input == "roadhog" display_roadhog elsif input == "soldier76" || input == "soldier:76" || input == "soldier: 76" display_soldier76 elsif input == "symmetra" display_symmetra elsif input == "torbjorn" display_torbjorn elsif input == "tracer" display_tracer elsif input == "widowmaker" display_widowmaker elsif input == "winston" display_winston elsif input == "zarya" display_zarya elsif input == "zenyatta" display_zenyatta elsif input == "exit" exit else puts "Please make a valid selection..." end end |
#show_stats(x) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/cli.rb', line 343 def show_stats(x) puts "Name: #{x.name}" puts "" puts "Role: #{x.role}" puts "Max HP: #{x.hp}" unless x.hp == nil puts "Ammo: #{x.ammo}" unless x.ammo == nil puts "" puts "Lore: #{x.lore}" puts "" puts "" puts "**Abilities**" puts "------------------------" x.abilities.each do |ability| puts "Ability: #{ability[:ability_name]}" puts "Description: " + "#{ability[:ability_description]}" puts "" end end |
#start ⇒ Object
5 6 7 8 9 |
# File 'lib/cli.rb', line 5 def start greeting display_stats_alphabetically end |