Class: Metrics::Instruments::Counter
- Inherits:
-
Instrument
- Object
- Instrument
- Metrics::Instruments::Counter
- Defined in:
- lib/ruby-metrics/instruments/counter.rb
Instance Attribute Summary collapse
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Instance Method Summary collapse
- #as_json(*_) ⇒ Object
- #clear ⇒ Object
- #dec(value = 1) ⇒ Object (also: #decr)
- #inc(value = 1) ⇒ Object (also: #incr)
-
#initialize(options = {}) ⇒ Counter
constructor
A new instance of Counter.
- #to_i ⇒ Object
- #to_json(*_) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Instrument
Constructor Details
#initialize(options = {}) ⇒ Counter
Returns a new instance of Counter.
9 10 11 12 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 9 def initialize( = {}) @value = 0 @units = [:units] end |
Instance Attribute Details
#units ⇒ Object (readonly)
Returns the value of attribute units.
7 8 9 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 7 def units @units end |
Instance Method Details
#as_json(*_) ⇒ Object
36 37 38 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 36 def as_json(*_) @value end |
#clear ⇒ Object
24 25 26 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 24 def clear @value = 0 end |
#dec(value = 1) ⇒ Object Also known as: decr
19 20 21 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 19 def dec(value = 1) @value -= value end |
#inc(value = 1) ⇒ Object Also known as: incr
14 15 16 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 14 def inc(value = 1) @value += value end |
#to_i ⇒ Object
28 29 30 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 28 def to_i @value.to_i end |
#to_json(*_) ⇒ Object
40 41 42 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 40 def to_json(*_) as_json.to_json end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/ruby-metrics/instruments/counter.rb', line 32 def to_s @value.to_s end |