Class: OverwatchStats::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#statsObject

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_bastionObject



243
244
245
246
# File 'lib/cli.rb', line 243

def display_bastion
  x = OverwatchStats::Hero.bastion
  show_stats(x)
end

#display_dvaObject



248
249
250
251
# File 'lib/cli.rb', line 248

def display_dva
  x = OverwatchStats::Hero.dva
  show_stats(x)
end

#display_genjiObject



253
254
255
256
# File 'lib/cli.rb', line 253

def display_genji
  x = OverwatchStats::Hero.genji
  show_stats(x)
end

#display_hanzoObject



258
259
260
261
# File 'lib/cli.rb', line 258

def display_hanzo
  x = OverwatchStats::Hero.hanzo
  show_stats(x)
end

#display_junkratObject



263
264
265
266
# File 'lib/cli.rb', line 263

def display_junkrat
  x = OverwatchStats::Hero.junkrat
  show_stats(x)
end

#display_lucioObject



268
269
270
271
# File 'lib/cli.rb', line 268

def display_lucio
  x = OverwatchStats::Hero.lucio
  show_stats(x)
end

#display_mccreeObject



273
274
275
276
# File 'lib/cli.rb', line 273

def display_mccree
  x = OverwatchStats::Hero.mccree
  show_stats(x)
end

#display_meiObject



278
279
280
281
# File 'lib/cli.rb', line 278

def display_mei
  x = OverwatchStats::Hero.mei
  show_stats(x)
end

#display_pharahObject



283
284
285
286
# File 'lib/cli.rb', line 283

def display_pharah
  x = OverwatchStats::Hero.pharah
  show_stats(x)
end

#display_reaperObject



288
289
290
291
# File 'lib/cli.rb', line 288

def display_reaper
  x = OverwatchStats::Hero.reaper
  show_stats(x)
end

#display_reinhardtObject



293
294
295
296
# File 'lib/cli.rb', line 293

def display_reinhardt
  x = OverwatchStats::Hero.reinhardt
  show_stats(x)
end

#display_roadhogObject



298
299
300
301
# File 'lib/cli.rb', line 298

def display_roadhog
  x = OverwatchStats::Hero.roadhog
  show_stats(x)
end

#display_soldier76Object



303
304
305
306
# File 'lib/cli.rb', line 303

def display_soldier76
  x = OverwatchStats::Hero.soldier76
  show_stats(x)
end

#display_stats_alphabeticallyObject



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_herokdObject



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_medalpergameObject



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_popularityObject



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_winrateObject



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_symmetraObject



308
309
310
311
# File 'lib/cli.rb', line 308

def display_symmetra
  x = OverwatchStats::Hero.symmetra
  show_stats(x)
end

#display_torbjornObject



313
314
315
316
# File 'lib/cli.rb', line 313

def display_torbjorn
  x = OverwatchStats::Hero.torbjorn
  show_stats(x)
end

#display_tracerObject



318
319
320
321
# File 'lib/cli.rb', line 318

def display_tracer
  x = OverwatchStats::Hero.tracer
  show_stats(x)
end

#display_widowmakerObject



323
324
325
326
# File 'lib/cli.rb', line 323

def display_widowmaker
  x = OverwatchStats::Hero.widowmaker
  show_stats(x)
end

#display_winstonObject



328
329
330
331
# File 'lib/cli.rb', line 328

def display_winston
  x = OverwatchStats::Hero.winston
  show_stats(x)
end

#display_zaryaObject



333
334
335
336
# File 'lib/cli.rb', line 333

def display_zarya
  x = OverwatchStats::Hero.zarya
  show_stats(x)
end

#display_zenyattaObject



338
339
340
341
# File 'lib/cli.rb', line 338

def display_zenyatta
  x = OverwatchStats::Hero.zenyatta
  show_stats(x)
end

#greetingObject



11
12
13
14
# File 'lib/cli.rb', line 11

def greeting
  puts ""
  puts "                   Cheers Love! Welcome to OverwatchStats!"
end


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 menu
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
    menu
  elsif input == "popularity" || input == "pop"
    display_stats_popularity
    menu
  elsif input == "medalpergame" || input == "medal"
    display_stats_medalpergame
    menu
  elsif input == "kdratio" || input == "kd"
    display_stats_herokd
    menu
  elsif input == "alphabetically" || input == "alph"
    display_stats_alphabetically
    menu
  elsif input == "bastion"
    display_bastion
    menu
  elsif input == "d.va"
    display_dva
    menu
  elsif input == "genji"
    display_genji
    menu
  elsif input == "hanzo"
    display_hanzo
    menu
  elsif input == "junkrat"
    display_junkrat
    menu
  elsif input == "lucio"
    display_lucio
    menu
  elsif input == "mccree"
    display_mccree
    menu
  elsif input == "mei"
    display_mei
    menu
  elsif input == "mercy"
    display_mercy
    menu
  elsif input == "pharah"
    display_pharah
    menu
  elsif input == "reaper"
    display_reaper
    menu
  elsif input == "reinhardt"
    display_reinhardt
    menu
  elsif input == "roadhog"
    display_roadhog
    menu
  elsif input == "soldier76" || input == "soldier:76" || input == "soldier: 76"
    display_soldier76
    menu
  elsif input == "symmetra"
    display_symmetra
    menu
  elsif input == "torbjorn"
    display_torbjorn
    menu
  elsif input == "tracer"
    display_tracer
    menu
  elsif input == "widowmaker"
    display_widowmaker
    menu
  elsif input == "winston"
    display_winston
    menu
  elsif input == "zarya"
    display_zarya
    menu
  elsif input == "zenyatta"
    display_zenyatta
    menu
  elsif input == "exit"
    exit
  else
    puts "Please make a valid selection..."
    menu
  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

#startObject



5
6
7
8
9
# File 'lib/cli.rb', line 5

def start
  greeting
  display_stats_alphabetically
  menu
end