Class: SuperSettings::TimePrecision
- Inherits:
-
Object
- Object
- SuperSettings::TimePrecision
- Defined in:
- lib/super_settings/time_precision.rb
Overview
Helper class for truncating timestamps to a specific precision. This is used by storage engines to ensure that timestamps are stored and compared with the same precision.
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
The time value with applied precision.
Instance Method Summary collapse
-
#initialize(time, precision = :microsecond) ⇒ TimePrecision
constructor
Create a new TimePrecision object.
-
#to_f ⇒ Float
Convert the time to a float.
Constructor Details
#initialize(time, precision = :microsecond) ⇒ TimePrecision
Create a new TimePrecision object.
15 16 17 18 19 |
# File 'lib/super_settings/time_precision.rb', line 15 def initialize(time, precision = :microsecond) raise ArgumentError.new("Invalid precision: #{precision}") unless valid_precision?(precision) @time = time_with_precision(time.to_f, precision) if time end |
Instance Attribute Details
#time ⇒ Object (readonly)
The time value with applied precision.
8 9 10 |
# File 'lib/super_settings/time_precision.rb', line 8 def time @time end |
Instance Method Details
#to_f ⇒ Float
Convert the time to a float.
24 25 26 |
# File 'lib/super_settings/time_precision.rb', line 24 def to_f @time.to_f end |