Sha256: 8cbd58e2ebdfc71fe96c45404564f90b3650a5014893531290b34f4b6e73e18d

Contents?: true

Size: 697 Bytes

Versions: 3

Compression:

Stored size: 697 Bytes

Contents

module Tabs
  module Helpers
    extend self

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

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

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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tabs-1.0.1 lib/tabs/helpers.rb
tabs-1.0.0 lib/tabs/helpers.rb
tabs-0.9.1 lib/tabs/helpers.rb