Class: NeoScout::Counter
- Inherits:
-
Object
- Object
- NeoScout::Counter
- Defined in:
- lib/neoscout/tools.rb,
lib/neoscout/tools.rb,
lib/neoscout/json_schema.rb
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #incr(ok) ⇒ Object
- #incr_failed ⇒ Object
- #incr_ok ⇒ Object
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #num_failed ⇒ Object
- #num_ok ⇒ Object
- #num_total ⇒ Object
- #reset ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Counter
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
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_failed ⇒ Object
23 24 25 |
# File 'lib/neoscout/tools.rb', line 23 def incr_failed @total +=1 end |
#incr_ok ⇒ Object
18 19 20 21 |
# File 'lib/neoscout/tools.rb', line 18 def incr_ok @ok += 1 @total += 1 end |
#num_failed ⇒ Object
31 32 33 |
# File 'lib/neoscout/tools.rb', line 31 def num_failed @total - @ok end |
#num_ok ⇒ Object
27 28 29 |
# File 'lib/neoscout/tools.rb', line 27 def num_ok @ok end |
#num_total ⇒ Object
35 36 37 |
# File 'lib/neoscout/tools.rb', line 35 def num_total @total end |
#reset ⇒ Object
9 10 11 12 |
# File 'lib/neoscout/tools.rb', line 9 def reset @ok = 0 @total = 0 end |
#to_json ⇒ Object
5 6 7 |
# File 'lib/neoscout/json_schema.rb', line 5 def to_json { 'num_failed' => num_failed, 'num_total' => num_total } end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/neoscout/tools.rb', line 43 def to_s "(#{num_ok}/#{num_failed}/#{num_total})" end |