Class: Report
- Inherits:
-
Object
- Object
- Report
- Defined in:
- lib/teuton/report/report.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#format ⇒ Object
Returns the value of attribute format.
-
#head ⇒ Object
Returns the value of attribute head.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
- #clone ⇒ Object
-
#close ⇒ Object
Calculate final values: * grade * max_weight * good_weight,d * fail_weight * fail_counter.
- #export(options) ⇒ Object
- #export_resume(options) ⇒ Object
-
#initialize(id = "00") ⇒ Report
constructor
A new instance of Report.
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
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/teuton/report/report.rb', line 6 def filename @filename end |
#format ⇒ Object
Returns the value of attribute format.
10 11 12 |
# File 'lib/teuton/report/report.rb', line 10 def format @format end |
#head ⇒ Object
Returns the value of attribute head.
7 8 9 |
# File 'lib/teuton/report/report.rb', line 7 def head @head end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
11 12 13 |
# File 'lib/teuton/report/report.rb', line 11 def history @history end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/teuton/report/report.rb', line 6 def id @id end |
#lines ⇒ Object
Returns the value of attribute lines.
8 9 10 |
# File 'lib/teuton/report/report.rb', line 8 def lines @lines end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
6 7 8 |
# File 'lib/teuton/report/report.rb', line 6 def output_dir @output_dir end |
#tail ⇒ Object
Returns the value of attribute tail.
9 10 11 |
# File 'lib/teuton/report/report.rb', line 9 def tail @tail end |
Instance Method Details
#clone ⇒ Object
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}=".to_sym report.send(attr_set, send(attr).clone) end report end |
#close ⇒ Object
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() filepath = File.join(@output_dir, @filename) Formatter.call(self, , 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() format = [:format] @format = "resume_#{format}".to_sym [:format] = @format filepath = File.join(@output_dir, @filename) Formatter.call(self, , filepath) filepath = File.join(@output_dir, "moodle") Formatter.call(self, {format: :moodle_csv}, filepath) end |