Introduction
Introduction Statistics Contact Development Disclaimer Help
moved DateTime#reporting_period to Date#to_reporting_period - reportable - Fork…
Log
Files
Refs
README
---
commit b15fdc0f574ec4fb68328b05d0176c890d21deda
parent 4599dc5418a0154fa7a355cca293ed4cf538f3a0
Author: Marco Otte-Witte <[email protected]>
Date: Wed, 14 Jan 2009 17:27:55 +0800
moved DateTime#reporting_period to Date#to_reporting_period
Signed-off-by: Marco Otte-Witte <[email protected]>
Diffstat:
A lib/kvlr/core_extensions/date.rb | 25 +++++++++++++++++++++++++
A spec/other/date_spec.rb | 27 +++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/lib/kvlr/core_extensions/date.rb b/lib/kvlr/core_extensions/date.rb
@@ -0,0 +1,25 @@
+module Kvlr #:nodoc:
+
+ module CoreExtensions #:nodoc:
+
+ module Date
+
+ ::Date.class_eval do
+
+ # Converts the DateTime into a Kvlr::ReportsAsSparkline::ReportingPeri…
+ def to_reporting_period(grouping)
+ if grouping.is_a?(Symbol)
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(grouping)
+ elsif !grouping.is_a?(Kvlr::ReportsAsSparkline::Grouping)
+ raise ArgumentError.new('grouping must be either an instance of Kv…
+ end
+ Kvlr::ReportsAsSparkline::ReportingPeriod.new(grouping, self)
+ end
+
+ end
+
+ end
+
+ end
+
+end
diff --git a/spec/other/date_spec.rb b/spec/other/date_spec.rb
@@ -0,0 +1,27 @@
+require File.join(File.dirname(__FILE__), '..', 'spec_helper')
+
+describe Date do
+
+ describe '#to_reporting_period' do
+
+ it 'should return a reporting period for the specified grouping and instan…
+ date_time = DateTime.now
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(:hour)
+
+ date_time.to_reporting_period(grouping).should == Kvlr::ReportsAsSparkli…
+ end
+
+ it 'should return a reporting period for the specified grouping and instan…
+ date_time = DateTime.now
+ grouping = Kvlr::ReportsAsSparkline::Grouping.new(:hour)
+
+ date_time.to_reporting_period(:hour).should == Kvlr::ReportsAsSparkline:…
+ end
+
+ it 'should raise an ArgumentError if the grouping is not specified as a sy…
+ lambda { DateTime.now.to_reporting_period(1) }.should raise_error(Argume…
+ end
+
+ end
+
+end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.