lib/tabs/resolution.rb in tabs-0.8.2 vs lib/tabs/resolution.rb in tabs-0.9.0
- old
+ new
@@ -1,9 +1,14 @@
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)
@@ -16,13 +21,24 @@
def normalize(resolution, timestamp)
resolution_klass(resolution).normalize(timestamp)
end
+ def all
+ @@resolution_classes.keys
+ end
+
private
def resolution_klass(resolution)
- "Tabs::Resolutions::#{resolution.to_s.classify}".constantize
+ @@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)