Class: Redis::TimeSeries::Sample
- Inherits:
-
Object
- Object
- Redis::TimeSeries::Sample
- Defined in:
- lib/redis/time_series/sample.rb
Overview
A sample is an immutable value object that represents a single data point within a time series.
Instance Attribute Summary collapse
-
#time ⇒ Time
readonly
The sample’s timestamp.
-
#value ⇒ BigDecimal
readonly
The decimal value of the sample.
Instance Method Summary collapse
-
#initialize(timestamp, value) ⇒ Sample
constructor
private
Samples are returned by time series query methods, there’s no need to create one yourself.
-
#to_h ⇒ Hash
A hash representation of the sample.
-
#to_msec ⇒ Integer
The millisecond value of the sample’s timestamp.
Constructor Details
#initialize(timestamp, value) ⇒ Sample
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Samples are returned by time series query methods, there’s no need to create one yourself.
17 18 19 20 |
# File 'lib/redis/time_series/sample.rb', line 17 def initialize(, value) @time = Time.from_msec() @value = BigDecimal(value) end |
Instance Attribute Details
#time ⇒ Time (readonly)
Returns the sample’s timestamp.
9 10 11 |
# File 'lib/redis/time_series/sample.rb', line 9 def time @time end |
#value ⇒ BigDecimal (readonly)
Returns the decimal value of the sample.
11 12 13 |
# File 'lib/redis/time_series/sample.rb', line 11 def value @value end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the sample.
34 35 36 37 38 39 |
# File 'lib/redis/time_series/sample.rb', line 34 def to_h { timestamp: to_msec, value: value } end |
#to_msec ⇒ Integer
27 28 29 |
# File 'lib/redis/time_series/sample.rb', line 27 def to_msec time.ts_msec end |