Sha256: a82bd1f0ef543b3e9d8f1f00d2859cde859fae4a696f90e990a2a9edea73c870

Contents?: true

Size: 681 Bytes

Versions: 2

Compression:

Stored size: 681 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 = dt + 1.send(resolution)) <= 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

2 entries across 2 versions & 1 rubygems

Version Path
tabs-0.9.0 lib/tabs/helpers.rb
tabs-0.8.2 lib/tabs/helpers.rb