Class: Flagstack::Telemetry::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/flagstack/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.



6
7
8
9
10
# File 'lib/flagstack/telemetry/metric.rb', line 6

def initialize(key, result, time = Time.now)
  @key = key.to_s
  @result = !!result
  @time = time.to_i / 60 * 60 # Round to minute
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/flagstack/telemetry/metric.rb', line 4

def key
  @key
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/flagstack/telemetry/metric.rb', line 4

def result
  @result
end

#timeObject (readonly)

Returns the value of attribute time.



4
5
6
# File 'lib/flagstack/telemetry/metric.rb', line 4

def time
  @time
end

Instance Method Details

#as_jsonObject



12
13
14
15
16
17
18
# File 'lib/flagstack/telemetry/metric.rb', line 12

def as_json
  {
    "key" => key,
    "time" => time,
    "result" => result
  }
end

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

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/flagstack/telemetry/metric.rb', line 20

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

#hashObject



28
29
30
# File 'lib/flagstack/telemetry/metric.rb', line 28

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