Sha256: e94bdb5fdaf59ea1c485d44160d0a92b80c9d0ef431e09cc70012a6d194bd167

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Tabs
  module Resolution
    extend self

    def register(resolution, klass)
      @@resolution_classes ||= {}
      @@resolution_classes[resolution] = klass
    end

    def serialize(resolution, timestamp)
      resolution_klass(resolution).serialize(timestamp)
    end

    def deserialize(resolution, str)
      resolution_klass(resolution).deserialize(str)
    end

    def from_seconds(resolution, s)
      resolution_klass(resolution).from_seconds(s)
    end

    def normalize(resolution, timestamp)
      resolution_klass(resolution).normalize(timestamp)
    end

    def all
      @@resolution_classes.keys
    end

    private

    def resolution_klass(resolution)
      @@resolution_classes[resolution]
    end

  end
end

Tabs::Resolution.register(:minute, Tabs::Resolutions::Minute)
Tabs::Resolution.register(:hour, Tabs::Resolutions::Hour)
Tabs::Resolution.register(:day, Tabs::Resolutions::Day)
Tabs::Resolution.register(:week, Tabs::Resolutions::Week)
Tabs::Resolution.register(:month, Tabs::Resolutions::Month)
Tabs::Resolution.register(:year, Tabs::Resolutions::Year)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tabs-0.9.0 lib/tabs/resolution.rb