Class: LLT::Review::Common::Report
- Inherits:
-
Object
- Object
- LLT::Review::Common::Report
- Includes:
- Helpers::Reportable
- Defined in:
- lib/llt/review/common/report.rb,
lib/llt/review/common/report/generic.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Generic
Instance Attribute Summary collapse
-
#sentences ⇒ Object
readonly
Returns the value of attribute sentences.
Attributes included from Helpers::Reportable
#id, #right, #total, #unique, #wrong
Instance Method Summary collapse
- #collect_multithreaded ⇒ Object
- #collect_singlethreaded ⇒ Object
-
#initialize(id, sentences) ⇒ Report
constructor
A new instance of Report.
- #report ⇒ Object
- #xml_attributes ⇒ Object
Methods included from Helpers::Reportable
#add, #add_total, #add_wrong, #clone, #count_rights, #increment, #init_diff, #percentage, #sort, #sort!, #xml_tag
Constructor Details
#initialize(id, sentences) ⇒ Report
Returns a new instance of Report.
10 11 12 13 |
# File 'lib/llt/review/common/report.rb', line 10 def initialize(id, sentences) super(id) @sentences = sentences end |
Instance Attribute Details
#sentences ⇒ Object (readonly)
Returns the value of attribute sentences.
8 9 10 |
# File 'lib/llt/review/common/report.rb', line 8 def sentences @sentences end |
Instance Method Details
#collect_multithreaded ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/llt/review/common/report.rb', line 33 def collect_multithreaded slice_size = @sentences.size / 4 slice_size = 1 if slice_size.zero? threads = [] @sentences.each_slice(slice_size) do |slice| temp_container = Report.new(nil, {}) threads << Thread.new do slice.map { |_, s| s.report }.each do |rep| rep.each { |_, r| temp_container.add(r) } end temp_container end end temps = threads.flat_map { |t| t.join; t.value } temps.each { |temp| temp.each { |_, r| add(r) }} end |
#collect_singlethreaded ⇒ Object
27 28 29 30 31 |
# File 'lib/llt/review/common/report.rb', line 27 def collect_singlethreaded @sentences.map { |_, s| s.report }.each do |rep| rep.each { |_, r| add(r) } end end |
#report ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/llt/review/common/report.rb', line 15 def report @report ||= begin add_report_container if RUBY_ENGINE == 'jruby' collect_multithreaded else collect_singlethreaded end @container.each { |_, rep| rep.sort! } end end |
#xml_attributes ⇒ Object
50 51 52 |
# File 'lib/llt/review/common/report.rb', line 50 def xml_attributes { id: @id } end |