Module: TabsTabs::Helpers

Extended by:
Helpers
Included in:
Helpers, Metrics::Counter, Metrics::Counter::Stats, Metrics::Task, Metrics::Value, Metrics::Value::Stats
Defined in:
lib/tabs_tabs/helpers.rb

Instance Method Summary collapse

Instance Method Details

#normalize_period(period, resolution) ⇒ Object



16
17
18
19
20
# File 'lib/tabs_tabs/helpers.rb', line 16

def normalize_period(period, resolution)
  period_start = TabsTabs::Resolution.normalize(resolution, period.first.utc)
  period_end = TabsTabs::Resolution.normalize(resolution, period.last.utc)
  (period_start..period_end)
end

#timestamp_range(period, resolution) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/tabs_tabs/helpers.rb', line 5

def timestamp_range(period, resolution)
  period = normalize_period(period, resolution)
  dt = period.first
  [].tap do |arr|
    arr << dt
    while (dt = TabsTabs::Resolution.add(resolution, dt, 1)) <= period.last
      arr << dt.utc
    end
  end
end

#to_numeric(v) ⇒ Object



22
23
24
# File 'lib/tabs_tabs/helpers.rb', line 22

def to_numeric(v)
  ((float = Float(v)) && (float % 1.0 == 0) ? float.to_i : float) rescue v
end