Module: Influxer::TimestampQuoting
Overview
:nodoc:
Constant Summary collapse
- TIME_FACTORS =
{ 'ns' => 1_000_000_000, 'ms' => 1_000, 's' => 1 }.freeze
- DEFAULT_PRECISION =
'ns'
Instance Method Summary collapse
- #factorize_timestamp(val, factor) ⇒ Object
-
#quote_timestamp(val, client) ⇒ Object
Quote timestamp rubocop: disable Metrics/MethodLength, Metrics/AbcSize.
-
#quote_timestamp_with_suffix(val, precision) ⇒ Object
rubocop: enable Metrics/MethodLength, Metrics/AbcSize.
Instance Method Details
#factorize_timestamp(val, factor) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/influxer/metrics/quoting/timestamp.rb', line 43 def (val, factor) case val when Numeric (val.to_f * factor).to_i when String (Time.parse(val).to_r * factor).to_i when Date, DateTime (val.to_time.to_r * factor).to_i when Time (val.to_r * factor).to_i end end |
#quote_timestamp(val, client) ⇒ Object
Quote timestamp rubocop: disable Metrics/MethodLength, Metrics/AbcSize
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/influxer/metrics/quoting/timestamp.rb', line 15 def (val, client) if Influxer.config.time_duration_suffix_enabled precision = if TIME_FACTORS.keys.include?(client.time_precision) client.time_precision else DEFAULT_PRECISION end return (val, precision) end if !TIME_FACTORS.keys.include?(client.time_precision) && !val.is_a?(Numeric) warn( "Influxer doesn't automatically cast Time and String values " \ "to '#{client.time_precision}' precision. " \ "Please, convert to numeric value yourself" ) return val end (val, TIME_FACTORS.fetch(client.time_precision)) end |
#quote_timestamp_with_suffix(val, precision) ⇒ Object
rubocop: enable Metrics/MethodLength, Metrics/AbcSize
39 40 41 |
# File 'lib/influxer/metrics/quoting/timestamp.rb', line 39 def (val, precision) "#{(val, TIME_FACTORS.fetch(precision))}#{precision}" end |