Class: Flipper::Cloud::Telemetry::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/cloud/telemetry/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, result, time = Time.now) ⇒ Metric

Returns a new instance of Metric.



7
8
9
10
11
# File 'lib/flipper/cloud/telemetry/metric.rb', line 7

def initialize(key, result, time = Time.now)
  @key = key
  @result = result
  @time = time.to_i / 60 * 60
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/flipper/cloud/telemetry/metric.rb', line 5

def key
  @key
end

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/flipper/cloud/telemetry/metric.rb', line 5

def result
  @result
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/flipper/cloud/telemetry/metric.rb', line 5

def time
  @time
end

Instance Method Details

#as_json(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flipper/cloud/telemetry/metric.rb', line 13

def as_json(options = {})
  data = {
    "key" => key.to_s,
    "time" => time,
    "result" => result,
  }

  if options[:with]
    data.merge!(options[:with])
  end

  data
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/flipper/cloud/telemetry/metric.rb', line 27

def eql?(other)
  self.class.eql?(other.class) &&
    @key == other.key && @time == other.time && @result == other.result
end

#hashObject



33
34
35
# File 'lib/flipper/cloud/telemetry/metric.rb', line 33

def hash
  [self.class, @key, @time, @result].hash
end