Class: NeoScout::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/neoscout/tools.rb,
lib/neoscout/tools.rb,
lib/neoscout/json_schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



5
6
7
# File 'lib/neoscout/tools.rb', line 5

def initialize
  reset
end

Class Method Details

.new_multi_keyed(*list) ⇒ Object



136
137
138
# File 'lib/neoscout/tools.rb', line 136

def self.new_multi_keyed(*list)
  HashWithDefault.new_multi_keyed(*list) { |key| Counter.new }
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/neoscout/tools.rb', line 39

def empty?
  @total == 0
end

#incr(ok) ⇒ Object



14
15
16
# File 'lib/neoscout/tools.rb', line 14

def incr(ok)
  if ok then incr_ok else incr_failed end
end

#incr_failedObject



23
24
25
# File 'lib/neoscout/tools.rb', line 23

def incr_failed
  @total +=1
end

#incr_okObject



18
19
20
21
# File 'lib/neoscout/tools.rb', line 18

def incr_ok
  @ok    += 1
  @total += 1
end

#num_failedObject



31
32
33
# File 'lib/neoscout/tools.rb', line 31

def num_failed
  @total - @ok
end

#num_okObject



27
28
29
# File 'lib/neoscout/tools.rb', line 27

def num_ok
  @ok
end

#num_totalObject



35
36
37
# File 'lib/neoscout/tools.rb', line 35

def num_total
  @total
end

#resetObject



9
10
11
12
# File 'lib/neoscout/tools.rb', line 9

def reset
  @ok    = 0
  @total = 0
end

#to_jsonObject



5
6
7
# File 'lib/neoscout/json_schema.rb', line 5

def to_json
  { 'num_failed' => num_failed, 'num_total' => num_total }
end

#to_sObject



43
44
45
# File 'lib/neoscout/tools.rb', line 43

def to_s
  "(#{num_ok}/#{num_failed}/#{num_total})"
end