Class: Recheck::CountStats
- Inherits:
-
Object
- Object
- Recheck::CountStats
- Defined in:
- lib/recheck/count_stats.rb
Instance Attribute Summary collapse
-
#counts ⇒ Object
readonly
Returns the value of attribute counts.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Instance Method Summary collapse
- #<<(other) ⇒ Object
- #all_pass? ⇒ Boolean
- #all_zero? ⇒ Boolean
- #any_errors? ⇒ Boolean
- #increment(type) ⇒ Object
-
#initialize ⇒ CountStats
constructor
A new instance of CountStats.
- #reached_blanket_failure? ⇒ Boolean
- #summary ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize ⇒ CountStats
Returns a new instance of CountStats.
11 12 13 14 |
# File 'lib/recheck/count_stats.rb', line 11 def initialize @counts = RESULT_TYPES.map { [_1, 0] }.to_h @queries = 0 end |
Instance Attribute Details
#counts ⇒ Object (readonly)
Returns the value of attribute counts.
3 4 5 |
# File 'lib/recheck/count_stats.rb', line 3 def counts @counts end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
3 4 5 |
# File 'lib/recheck/count_stats.rb', line 3 def queries @queries end |
Instance Method Details
#<<(other) ⇒ Object
16 17 18 19 20 |
# File 'lib/recheck/count_stats.rb', line 16 def <<(other) @queries += other.queries @counts.merge!(other.counts) { |type, self_v, other_v| self_v + other_v } self end |
#all_pass? ⇒ Boolean
22 23 24 |
# File 'lib/recheck/count_stats.rb', line 22 def all_pass? @counts.slice(*Recheck::ERROR_TYPES).all? { |type, count| count.zero? } end |
#all_zero? ⇒ Boolean
26 27 28 |
# File 'lib/recheck/count_stats.rb', line 26 def all_zero? @counts.all? { |type, count| count.zero? } end |
#any_errors? ⇒ Boolean
30 31 32 |
# File 'lib/recheck/count_stats.rb', line 30 def any_errors? !all_pass? end |
#increment(type) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/recheck/count_stats.rb', line 34 def increment(type) if type == :queries @queries += 1 elsif !@counts.include? type raise ArgumentError, "Unkown type #{type}" else @counts[type] += 1 end end |
#reached_blanket_failure? ⇒ Boolean
44 45 46 |
# File 'lib/recheck/count_stats.rb', line 44 def reached_blanket_failure? pass == 0 && (fail == 20 || exception == 20) end |
#summary ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/recheck/count_stats.rb', line 48 def summary "#{queries} #{(queries == 1) ? "query" : "queries"}, " + ( [:pass, :fail] + [ :exception, :blanket, :no_query_methods, :no_queries, :no_check_methods, :no_checks ].filter { |type| @counts[type].nonzero? } ).map { |type| "#{@counts[type]} #{type}" }.join(", ") end |
#total ⇒ Object
62 63 64 |
# File 'lib/recheck/count_stats.rb', line 62 def total @counts.values.sum end |