Class: Metrics::Instruments::Counter

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

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



4
5
6
# File 'lib/ruby-metrics/instruments/counter.rb', line 4

def initialize
  @value = 0
end

Instance Method Details

#as_json(*_) ⇒ Object



30
31
32
# File 'lib/ruby-metrics/instruments/counter.rb', line 30

def as_json(*_)
  @value
end

#clearObject



18
19
20
# File 'lib/ruby-metrics/instruments/counter.rb', line 18

def clear
  @value = 0
end

#dec(value = 1) ⇒ Object Also known as: decr



13
14
15
# File 'lib/ruby-metrics/instruments/counter.rb', line 13

def dec(value = 1)
  @value -= value
end

#inc(value = 1) ⇒ Object Also known as: incr



8
9
10
# File 'lib/ruby-metrics/instruments/counter.rb', line 8

def inc(value = 1)
  @value += value
end

#to_iObject



22
23
24
# File 'lib/ruby-metrics/instruments/counter.rb', line 22

def to_i
  @value.to_i
end

#to_json(*_) ⇒ Object



34
35
36
# File 'lib/ruby-metrics/instruments/counter.rb', line 34

def to_json(*_)
  as_json.to_json
end

#to_sObject



26
27
28
# File 'lib/ruby-metrics/instruments/counter.rb', line 26

def to_s
  @value.to_s
end