Class: Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = "00") ⇒ Report

Returns a new instance of Report.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/teuton/report/report.rb', line 9

def initialize(id = "00")
  @id = id
  @filename = "case-#{@id}"
  @output_dir = Project.value[:output_basedir]
  @head = {}
  @lines = []
  @tail = {unique_fault: 0}
  # [String] with 1 char for every target in @lines
  # For example: "..F." means: good, good, fail and good
  @history = ""
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/teuton/report/report.rb', line 6

def filename
  @filename
end

#formatObject

Returns the value of attribute format.



6
7
8
# File 'lib/teuton/report/report.rb', line 6

def format
  @format
end

#headObject

Returns the value of attribute head.



6
7
8
# File 'lib/teuton/report/report.rb', line 6

def head
  @head
end

#historyObject (readonly)

Returns the value of attribute history.



7
8
9
# File 'lib/teuton/report/report.rb', line 7

def history
  @history
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/teuton/report/report.rb', line 6

def id
  @id
end

#linesObject

Returns the value of attribute lines.



6
7
8
# File 'lib/teuton/report/report.rb', line 6

def lines
  @lines
end

#output_dirObject

Returns the value of attribute output_dir.



6
7
8
# File 'lib/teuton/report/report.rb', line 6

def output_dir
  @output_dir
end

#tailObject

Returns the value of attribute tail.



6
7
8
# File 'lib/teuton/report/report.rb', line 6

def tail
  @tail
end

Instance Method Details

#cloneObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/teuton/report/report.rb', line 21

def clone
  report = Report.new
  attrs = %i[id filename output_dir head lines tail format]
  attrs.each do |attr|
    attr_set = :"#{attr}="
    report.send(attr_set, send(attr).clone)
  end

  report
end

#closeObject

Calculate final values:

  • grade

  • max_weight

  • good_weight,d

  • fail_weight

  • fail_counter



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
# File 'lib/teuton/report/report.rb', line 55

def close
  max = good = fails = fail_counter = 0
  @lines.each do |i|
    next unless i.instance_of? Hash

    max += i[:weight] if i[:weight].positive?
    if i[:check]
      good += i[:weight]
      @history += Settings.letter[:good]
    else
      fails += i[:weight]
      fail_counter += 1
      @history += Settings.letter[:bad]
    end
  end
  @tail[:max_weight] = max
  @tail[:good_weight] = good
  @tail[:fail_weight] = fails
  @tail[:fail_counter] = fail_counter

  i = good.to_f / max
  i = 0 if i.nan?
  @tail[:grade] = (100.0 * i).round
  @tail[:grade] = 0 if @tail[:unique_fault].positive?
end

#export(options) ⇒ Object



32
33
34
35
# File 'lib/teuton/report/report.rb', line 32

def export(options)
  filepath = File.join(@output_dir, @filename)
  Formatter.call(self, options, filepath)
end

#export_resume(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/teuton/report/report.rb', line 37

def export_resume(options)
  format = options[:format]
  @format = :"resume_#{format}"
  options[:format] = @format
  filepath = File.join(@output_dir, @filename)
  Formatter.call(self, options, filepath)

  filepath = File.join(@output_dir, "moodle")
  Formatter.call(self, {format: :moodle_csv}, filepath)
end