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.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/teuton/report/report.rb', line 13

def initialize(id = "00")
  @id = id
  @filename = "case-#{@id}"
  # @output_dir = Application.instance.output_basedir
  @output_dir = Project.value[:output_basedir]
  @head = {}
  @lines = []
  @tail = {}
  # @history save 1 letter for every target.
  # For example: "..F." means: good, good, fail and good
  # I will use this in the future stats manager.
  @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.



10
11
12
# File 'lib/teuton/report/report.rb', line 10

def format
  @format
end

#headObject

Returns the value of attribute head.



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

def head
  @head
end

#historyObject (readonly)

Returns the value of attribute history.



11
12
13
# File 'lib/teuton/report/report.rb', line 11

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.



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

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.



9
10
11
# File 'lib/teuton/report/report.rb', line 9

def tail
  @tail
end

Instance Method Details

#cloneObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/teuton/report/report.rb', line 27

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



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

def close
  max = 0.0
  good = 0.0
  fail = 0.0
  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
      fail += i[:weight]
      fail_counter += 1
      @history += Settings.letter[:bad]
    end
  end
  @tail[:max_weight] = max
  @tail[:good_weight] = good
  @tail[:fail_weight] = fail
  @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



38
39
40
41
# File 'lib/teuton/report/report.rb', line 38

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

#export_resume(options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/teuton/report/report.rb', line 43

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