Class: Unleash::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetrics

Returns a new instance of Metrics.



6
7
8
# File 'lib/unleash/metrics.rb', line 6

def initialize
  self.features = {}
end

Instance Attribute Details

#featuresObject

Returns the value of attribute features.



4
5
6
# File 'lib/unleash/metrics.rb', line 4

def features
  @features
end

Instance Method Details

#increment(feature, choice) ⇒ Object



14
15
16
17
18
19
# File 'lib/unleash/metrics.rb', line 14

def increment(feature, choice)
  raise "InvalidArgument choice must be :yes or :no" unless [:yes, :no].include? choice

  self.features[feature] = {yes: 0, no: 0} unless self.features.include? feature
  self.features[feature][choice] += 1
end

#resetObject



21
22
23
# File 'lib/unleash/metrics.rb', line 21

def reset
  self.features = {}
end

#to_sObject



10
11
12
# File 'lib/unleash/metrics.rb', line 10

def to_s
  self.features.to_json
end