Module: LLT::Review::Helpers::Reportable
- Includes:
- Core::Structures::HashContainable
- Included in:
- Alignment::Report::Translation, Alignment::Report::Word, Common::Report, Common::Report::Generic, Treebank::Report::Datapoints, Treebank::Report::Lemma, Treebank::Report::Postag, Treebank::Report::Postag::Datapoint, Treebank::Report::Relation
- Defined in:
- lib/llt/review/helpers/reportable.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#unique ⇒ Object
readonly
Returns the value of attribute unique.
-
#wrong ⇒ Object
readonly
Returns the value of attribute wrong.
Instance Method Summary collapse
- #add(element) ⇒ Object
- #add_total(element) ⇒ Object
- #add_wrong(unique = nil) ⇒ Object
-
#clone ⇒ Object
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..
- #count_rights ⇒ Object
- #increment ⇒ Object
- #init_diff ⇒ Object
- #initialize(id, total = 1) ⇒ Object
- #percentage(category = :right) ⇒ Object
- #sort ⇒ Object
- #sort! ⇒ Object
- #xml_attributes ⇒ Object
- #xml_tag ⇒ Object
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/llt/review/helpers/reportable.rb', line 6 def id @id end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
6 7 8 |
# File 'lib/llt/review/helpers/reportable.rb', line 6 def right @right end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
6 7 8 |
# File 'lib/llt/review/helpers/reportable.rb', line 6 def total @total end |
#unique ⇒ Object (readonly)
Returns the value of attribute unique.
6 7 8 |
# File 'lib/llt/review/helpers/reportable.rb', line 6 def unique @unique end |
#wrong ⇒ Object (readonly)
Returns the value of attribute wrong.
6 7 8 |
# File 'lib/llt/review/helpers/reportable.rb', line 6 def wrong @wrong end |
Instance Method Details
#add(element) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
34 35 36 |
# File 'lib/llt/review/helpers/reportable.rb', line 34 def add_total(element) @total += element.total end |
#add_wrong(unique = nil) ⇒ Object
38 39 40 41 |
# File 'lib/llt/review/helpers/reportable.rb', line 38 def add_wrong(unique = nil) @wrong += 1 @unique += 1 if unique end |
#clone ⇒ Object
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.
78 79 80 81 82 |
# File 'lib/llt/review/helpers/reportable.rb', line 78 def clone cloned = super cloned.replace_with_clone(:container) cloned end |
#count_rights ⇒ Object
43 44 45 46 |
# File 'lib/llt/review/helpers/reportable.rb', line 43 def count_rights @right = @total - @wrong each_value(&:count_rights) end |
#increment ⇒ Object
48 49 50 |
# File 'lib/llt/review/helpers/reportable.rb', line 48 def increment @total += 1 end |
#init_diff ⇒ Object
13 14 15 16 17 |
# File 'lib/llt/review/helpers/reportable.rb', line 13 def init_diff @wrong = 0 @unique = 0 each { |_, el| el.init_diff } end |
#initialize(id, total = 1) ⇒ Object
8 9 10 11 |
# File 'lib/llt/review/helpers/reportable.rb', line 8 def initialize(id, total = 1) super(id) @total = total end |
#percentage(category = :right) ⇒ Object
19 20 21 |
# File 'lib/llt/review/helpers/reportable.rb', line 19 def percentage(category = :right) ((send(category).to_f / @total) * 100).round(2) end |
#sort ⇒ Object
60 61 62 63 64 65 66 67 |
# 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! ⇒ Object
69 70 71 72 |
# File 'lib/llt/review/helpers/reportable.rb', line 69 def sort! each { |_, el| el.sort! } @container = sort end |
#xml_attributes ⇒ Object
56 57 58 |
# 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 ⇒ Object
52 53 54 |
# File 'lib/llt/review/helpers/reportable.rb', line 52 def xml_tag self.class.name.scan(/::(\w+)$/)[0].first.downcase end |