Class: Spectator::Measure

Inherits:
Object
  • Object
show all
Defined in:
lib/spectator/measure.rb

Overview

This immutable class represents a measurement sampled from a meter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, value) ⇒ Measure

A meter id and a value



7
8
9
10
# File 'lib/spectator/measure.rb', line 7

def initialize(id, value)
  @id = id
  @value = value.to_f
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/spectator/measure.rb', line 4

def id
  @id
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/spectator/measure.rb', line 4

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object

Compare this measurement against another one, taking into account nan values



19
20
21
22
# File 'lib/spectator/measure.rb', line 19

def ==(other)
  @id == other.id && (@value == other.value ||
      @value.nan? && other.value.nan?)
end

#to_sObject

A string representation of this measurement, for debugging purposes



13
14
15
# File 'lib/spectator/measure.rb', line 13

def to_s
  "Measure{id=#{@id}, value=#{@value}}"
end