moved DEPTHS constant from Summary class to the

Date class and using it (mostly) everywhere
This commit is contained in:
2010-07-24 21:39:13 +03:00
parent 14d2bc1189
commit 0d3d5469c0
3 changed files with 6 additions and 6 deletions

View File

@@ -9,6 +9,8 @@ module Redistat
attr_accessor :sec
attr_accessor :usec
DEPTHS = [:year, :month, :day, :hour, :min, :sec, :usec]
def initialize(input)
if input.is_a?(::Time)
from_time(input)
@@ -36,7 +38,7 @@ module Redistat
def to_string(depth = nil)
depth ||= :sec
output = ""
[:year, :month, :day, :hour, :min, :sec, :usec].each_with_index do |current, i|
DEPTHS.each_with_index do |current, i|
break if self.send(current).nil?
if current != :usec
output << self.send(current).to_s.rjust((i <= 0) ? 4 : 2, '0')
@@ -57,7 +59,7 @@ module Redistat
private
def from_time(input)
[:year, :month, :day, :hour, :min, :sec, :usec].each do |k|
DEPTHS.each do |k|
send("#{k}=", input.send(k))
end
end

View File

@@ -3,13 +3,11 @@ module Redistat
include Database
extend Database
DEPTHS = [:year, :month, :day, :hour, :min, :sec, :usec]
def self.update_all(key, stats = {}, depth_limit = nil)
stats ||= {}
depth_limit ||= key.depth
return nil if stats.size == 0
DEPTHS.each do |depth|
Date::DEPTHS.each do |depth|
update(key, stats, depth)
break if depth == depth_limit
end

View File

@@ -5,7 +5,7 @@ describe Redistat::Date do
it "should initialize from Time object" do
now = Time.now
[Redistat::Date.new(now), now.to_rs].each do |rdate|
[:year, :month, :day, :hour, :min, :sec, :usec].each { |k| rdate.send(k).should == now.send(k) }
Redistat::Date::DEPTHS.each { |k| rdate.send(k).should == now.send(k) }
end
end