module LLT::Review::Helpers::Reportable
Attributes
id[R]
right[R]
total[R]
unique[R]
wrong[R]
Public Class Methods
new(id, total = 1)
click to toggle source
Calls superclass method
# File lib/llt/review/helpers/reportable.rb, line 8 def initialize(id, total = 1) super(id) @total = total end
Public Instance Methods
add(element)
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 23 def add(element) if el = @container[element.id] el.add_total(element) element.container.each do |_, nested_el| el.add(nested_el) end else @container[element.id] = element end end
add_total(element)
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 34 def add_total(element) @total += element.total end
add_wrong(unique = nil)
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 38 def add_wrong(unique = nil) @wrong += 1 @unique += 1 if unique end
clone()
click to toggle source
This could be implemented with a block as well (which holds whatever code needs to be performed on the cloned instance, but probably not a good idea as this called very often - make it as lean as possibe.
Calls superclass method
# File lib/llt/review/helpers/reportable.rb, line 78 def clone cloned = super cloned.replace_with_clone(:container) cloned end
count_rights()
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 43 def count_rights @right = @total - @wrong each_value(&:count_rights) end
increment()
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 48 def increment @total += 1 end
init_diff()
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 13 def init_diff @wrong = 0 @unique = 0 each { |_, el| el.init_diff } end
percentage(category = :right)
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 19 def percentage(category = :right) ((send(category).to_f / @total) * 100).round(2) end
sort()
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 60 def sort Hash[ @container.sort do |(a_id, a_r), (b_id, b_r)| comp = b_r.total <=> a_r.total comp.zero? ? a_id <=> b_id : comp end ] end
sort!()
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 69 def sort! each { |_, el| el.sort! } @container = sort end
xml_attributes()
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 56 def xml_attributes { name: @id, total: @total, right: @right, wrong: @wrong, unique: @unique } end
xml_tag()
click to toggle source
# File lib/llt/review/helpers/reportable.rb, line 52 def xml_tag self.class.name.scan(/::(\w+)$/)[0].first.downcase end