Class: Rorr::Score

Inherits:
Object
  • Object
show all
Extended by:
Base
Defined in:
lib/rorr/score.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Base

generate_file_base_path, read_template, templates_path

Class Attribute Details

.finish_timeObject (readonly)

Returns the value of attribute finish_time.



7
8
9
# File 'lib/rorr/score.rb', line 7

def finish_time
  @finish_time
end

.reportObject (readonly)

Returns the value of attribute report.



7
8
9
# File 'lib/rorr/score.rb', line 7

def report
  @report
end

.singleObject (readonly)

Returns the value of attribute single.



7
8
9
# File 'lib/rorr/score.rb', line 7

def single
  @single
end

.start_timeObject (readonly)

Returns the value of attribute start_time.



7
8
9
# File 'lib/rorr/score.rb', line 7

def start_time
  @start_time
end

.timeObject (readonly)

Returns the value of attribute time.



7
8
9
# File 'lib/rorr/score.rb', line 7

def time
  @time
end

.totalObject (readonly)

Returns the value of attribute total.



7
8
9
# File 'lib/rorr/score.rb', line 7

def total
  @total
end

Class Method Details

.add_correctObject



13
14
15
16
17
# File 'lib/rorr/score.rb', line 13

def add_correct
  total[:correct] += 1
  single[:correct] = ''
  single[:color] = 'green'
end

.add_reportObject



36
37
38
# File 'lib/rorr/score.rb', line 36

def add_report
  report << single
end

.add_retryObject



31
32
33
34
# File 'lib/rorr/score.rb', line 31

def add_retry
  total[:retry]  += 1
  single[:retry] += 1
end

.add_skipObject



25
26
27
28
29
# File 'lib/rorr/score.rb', line 25

def add_skip
  total[:skip]  += 1
  single[:skip] = ''
  single[:color] = 'light_blue'
end

.add_wrongObject



19
20
21
22
23
# File 'lib/rorr/score.rb', line 19

def add_wrong
  total[:wrong] += 1
  single[:correct] = ''
  single[:color] = 'red'
end

.correct_rateObject



44
45
46
# File 'lib/rorr/score.rb', line 44

def correct_rate
  ((total[:correct].to_f / total_count.to_f) * 100).round(2)
end

.export_reportObject



69
70
71
72
73
# File 'lib/rorr/score.rb', line 69

def export_report
  File.open(generate_file_base_path + '/Report', 'w') do |f|
    f.write read_template(templates_path + '/report.erb')
  end
end

.finishObject



60
61
62
63
# File 'lib/rorr/score.rb', line 60

def finish
  @finish_time = Time.now
  @time = (finish_time - start_time).round(2)
end

.format_timeObject



65
66
67
# File 'lib/rorr/score.rb', line 65

def format_time
  Time.at(Score.time).utc.strftime('%H:%M:%S')
end

.init(index) ⇒ Object



9
10
11
# File 'lib/rorr/score.rb', line 9

def init(index)
  @single = { question: "#{index}.", correct: '', skip: '', retry: 0, color: '' }
end

.skip_rateObject



52
53
54
# File 'lib/rorr/score.rb', line 52

def skip_rate
  ((total[:skip].to_f / total_count.to_f) * 100).round(2)
end

.startObject



56
57
58
# File 'lib/rorr/score.rb', line 56

def start
  @start_time = Time.now
end

.total_countObject



40
41
42
# File 'lib/rorr/score.rb', line 40

def total_count
  total[:correct] + total[:wrong] + total[:skip]
end

.wrong_rateObject



48
49
50
# File 'lib/rorr/score.rb', line 48

def wrong_rate
  ((total[:wrong].to_f / total_count.to_f) * 100).round(2)
end