mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 05:16:39 +00:00
moved DEPTHS constant from Summary class to the
Date class and using it (mostly) everywhere
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user