| tweaked DateTime.to_reporting_period - reportable - Fork of reportable required… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 226d0448e906b0ed7ab0466519799650f7753c54 | |
| parent 0501284c2f5ff5aef62c0fc312f9bbfde444239a | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Wed, 14 Jan 2009 17:12:27 +0800 | |
| tweaked DateTime.to_reporting_period | |
| Signed-off-by: Marco Otte-Witte <[email protected]> | |
| Diffstat: | |
| M lib/kvlr/core_extensions/date_time⦠| 5 +++++ | |
| M spec/classes/date_time_spec.rb | 11 +++++++++++ | |
| 2 files changed, 16 insertions(+), 0 deletions(-) | |
| --- | |
| diff --git a/lib/kvlr/core_extensions/date_time.rb b/lib/kvlr/core_extensions/d… | |
| @@ -8,6 +8,11 @@ module Kvlr #:nodoc: | |
| # 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 | |
| diff --git a/spec/classes/date_time_spec.rb b/spec/classes/date_time_spec.rb | |
| @@ -11,6 +11,17 @@ describe DateTime do | |
| 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 |