Class: Metrics::Instruments::Counter

Inherits:
Instrument show all
Defined in:
lib/ruby-metrics/instruments/counter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instrument

#tag, #tags

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(options = {})
  @value = 0
  @units = options[:units]
end

Instance Attribute Details

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

#clearObject



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_iObject



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_sObject



32
33
34
# File 'lib/ruby-metrics/instruments/counter.rb', line 32

def to_s
  @value.to_s
end