Class: Recheck::CountStats

Inherits:
Object
  • Object
show all
Defined in:
lib/recheck/count_stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCountStats

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

#countsObject (readonly)

Returns the value of attribute counts.



3
4
5
# File 'lib/recheck/count_stats.rb', line 3

def counts
  @counts
end

#queriesObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


44
45
46
# File 'lib/recheck/count_stats.rb', line 44

def reached_blanket_failure?
  pass == 0 && (fail == 20 || exception == 20)
end

#summaryObject



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

#totalObject



62
63
64
# File 'lib/recheck/count_stats.rb', line 62

def total
  @counts.values.sum
end