Class: Yogi::CheckErrors

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

Instance Method Summary collapse

Instance Method Details

#checkerObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/yogi.rb', line 175

def checker
  i = 0
  pre_diff_array = []
  post_diff_array = []
  buffer = File.open('.git/.ignoremefile.txt', 'r').read
  file_sample = JSON.parse(buffer)

  file_sample.each do |file_name|
    text =  File.open(file_name, "r"){ |file| file.read }#File.read(file_name)


    post_counted_comma = count_em(text,",")
    post_counted_semicolon = count_em(text,";")
    post_counted_l = count_em(text,"ll")
    post_counted_3 = count_em(text,"3")
    post_counted_s = count_em(text,/[s]$/)
    post_counted_bracket = count_em(text,"}")
    post_counted_px = count_em(text,"px")
    post_counted_sq_bracket = count_em(text,">")
    post_counted_equal = count_em(text,"==")
    post_counted_sdot = count_em(text,/s\./)
    post_counted_underscore = count_em(text,"_")

    json_file = File.read(".git/.ignoreme.json")
    variable_hash = JSON.parse(json_file)

    $pre_counted_comma = variable_hash[i][file_name]['pre_counted_comma']
    $pre_counted_semicolon = variable_hash[i][file_name]['pre_counted_semicolon']
    $pre_counted_l = variable_hash[i][file_name]['pre_counted_l']
    $pre_counted_3 = variable_hash[i][file_name]['pre_counted_3']
    $pre_counted_s = variable_hash[i][file_name]['pre_counted_s']
    $pre_counted_bracket = variable_hash[i][file_name]['pre_counted_bracket']
    $pre_counted_px = variable_hash[i][file_name]['pre_counted_px']
    $pre_counted_sq_bracket = variable_hash[i][file_name]['pre_counted_sq_bracket']
    $pre_counted_equal = variable_hash[i][file_name]['pre_counted_equal']
    $pre_counted_sdot = variable_hash[i][file_name]['pre_counted_sdot']
    $pre_counted_underscore = variable_hash[i][file_name]['pre_counted_underscore']

    $pre_diff_comma = variable_hash[i][file_name]['pre_diff_comma']
    $pre_diff_semicolon = variable_hash[i][file_name]['pre_diff_semicolon']
    $pre_diff_l = variable_hash[i][file_name]['pre_diff_l']
    $pre_diff_3 = variable_hash[i][file_name]['pre_diff_3']
    $pre_diff_s = variable_hash[i][file_name]['pre_diff_s']
    $pre_diff_bracket = variable_hash[i][file_name]['pre_diff_bracket']
    $pre_diff_px = variable_hash[i][file_name]['pre_diff_px']
    $pre_diff_sq_bracket = variable_hash[i][file_name]['pre_diff_sq_bracket']
    $pre_diff_equal = variable_hash[i][file_name]['pre_diff_equal']
    $pre_diff_sdot = variable_hash[i][file_name]['pre_diff_sdot']
    $pre_diff_underscore = variable_hash[i][file_name]['pre_diff_underscore']
    i += 1
    post_diff_comma = $pre_counted_comma - post_counted_comma
    post_diff_semicolon = $pre_counted_semicolon - post_counted_semicolon
    post_diff_l = $pre_counted_l - post_counted_l
    post_diff_3 = $pre_counted_3 - post_counted_3
    post_diff_s = $pre_counted_s - post_counted_s
    post_diff_bracket = $pre_counted_bracket - post_counted_bracket
    post_diff_px = $pre_counted_px - post_counted_px
    post_diff_sq_bracket = $pre_counted_sq_bracket - post_counted_sq_bracket
    post_diff_equal = $pre_counted_equal - post_counted_equal
    post_diff_sdot = $pre_counted_sdot - post_counted_sdot
    post_diff_underscore = $pre_counted_underscore - post_counted_underscore

    # total changes made in each file
    total_pre_diff = $pre_diff_comma + $pre_diff_semicolon + $pre_diff_l + $pre_diff_3 + $pre_diff_s + $pre_diff_bracket + $pre_diff_px + $pre_diff_sq_bracket + $pre_diff_equal + $pre_diff_sdot + $pre_diff_underscore

    # total changes not fixed
    total_post_diff = post_diff_comma + post_diff_semicolon + post_diff_l + post_diff_3 + post_diff_s + post_diff_bracket + post_diff_px + post_diff_sq_bracket + post_diff_equal + post_diff_sdot +post_diff_underscore

    pre_diff_array << total_pre_diff
    post_diff_array << total_post_diff
  end
  pre_diff = pre_diff_array.inject(0, :+)
  post_diff = post_diff_array.inject(0, :+)
  pre_diff = pre_diff.to_f
  post_diff = post_diff.to_f


  if pre_diff == 0
    puts 'there must have gone something wrong...no errors to begin with'
  else
  fixed_errors = pre_diff - post_diff
  fix = ((fixed_errors)/pre_diff)*100
  fix = fix.round(3)

    case fix
      when 0
        reply = "Don't just sit around #{$account}, get started to fix some stuff!"
        additional = 'You lazy $%##$#.'
      when 0..25
        reply = "Not a bad start but im sure you can do better!"
        additional = "#{$account}, you just getting started right?"
      when  25.000..50.000
        reply = "Well, well now we getting somewhere!"
        additional = 'Nearly half way...'
      when 50.000..75.000
        reply = "You see, not that hard...right?"
        additional = 'Nice just job, mate.'
      when 75.000..100.000
        reply = "Nearly there... you can do it!"
        additional = 'Just a few more...'
      when 100
        reply = "Wow I'm impressed...wanne go again?"
        additional = 'Either you cheated or you are a true master of syntax errors because...'
      else
      reply = "WTF"
    end

    case
      when Time.now.monday?
        if OS.mac?
          cmd = ("say 'happy monday #{$account}'")
          system cmd
        end
        additionalreply = "Ruby-Monday"
      when Time.now.tuesday?
        if OS.mac?
          cmd = ("say 'happy tuesday #{$account}'")
          system cmd
        end
        additionalreply = "Ruby-Tuesday"
      when Time.now.wednesday?
        if OS.mac?
          cmd = ("say 'happy wednesday #{$account}'")
          system cmd
        end
        additionalreply = "Ruby-Wednesday"
      when Time.now.thursday?
        if OS.mac?
          cmd = ("say 'happy thursday #{$account}'")
          system cmd
        end
        additionalreply = "Ruby-Thursday"
      when Time.now.friday?
        if OS.mac?
          cmd = ("say 'Yeeaah...happy friday #{$account}'")
          system cmd
        end
        additionalreply = "Thank god it's Ruby-Friday"
      when Time.now.saturday?
        if OS.mac?
          cmd = ("say 'Ruby-Ruby-Weekend #{$account}'")
          system cmd
        end
        additionalreply = "Practicing on saturday....very good #{$account}"
      when Time.now.sunday?
        if OS.mac?
          cmd = ("say 'Just another sunday?'")
          system cmd
        end
        additionalreply = "#{$account}, do you never rest?"
      else
        if OS.mac?
          cmd = ("say 'WTF'")
          system cmd
        end
      reply = "WTF"
    end

  puts "================================="
  puts "#{additionalreply}"
  puts "#{reply}"
  puts "#{$account}, you fixed #{fix}% of all the errors. "
  puts "#{additional}"
  puts "#{$account}, you fixed #{fixed_errors.to_i} errors, #{post_diff.to_i} more to go."
  puts "================================="
    if  OS.mac?
      file = File.join(__dir__, 'sound', 'oh-yeah.mp3')
      escfile = Shellwords.escape(file)
      cmd = "afplay #{escfile}"
      system cmd
    # elsif  OS.linux?
    #   file = File.join(__dir__, 'sound', 'oh-yeah.mp3')
    #   escfile = Shellwords.escape(file)
    #   cmd = "aplay #{escfile}"
    #   system cmd

    end
  end
end

#count_em(text, substring) ⇒ Object



171
172
173
# File 'lib/yogi.rb', line 171

def count_em(text, substring)
  text.scan(/(?=#{substring})/).count
end