added ReportingPeriod#previous - reportable - Fork of reportable required by WarVox, from hdm/reportable.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit b3c5f1a04b24429fe96a1b2eeb1dadc63214574d
(DIR) parent a9b9ce2570cd9c6a5a64b562efebcf5d7b549a27
(HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
Date: Mon, 19 Jan 2009 13:15:35 +0100
added ReportingPeriod#previous
Diffstat:
M lib/kvlr/reports_as_sparkline/repo… | 14 ++++++++++++++
M rdoc/classes/Kvlr/ReportsAsSparkli… | 2 +-
M rdoc/classes/Kvlr/ReportsAsSparkli… | 2 +-
M rdoc/classes/Kvlr/ReportsAsSparkli… | 24 ++++++++++++------------
M rdoc/classes/Kvlr/ReportsAsSparkli… | 38 +++++++++++++++++++++++++++++++
M rdoc/created.rid | 2 +-
M rdoc/files/lib/kvlr/reports_as_spa… | 2 +-
M rdoc/fr_method_index.html | 5 +++--
M spec/classes/reporting_period_spec… | 36 +++++++++++++++++++++++++++++++
9 files changed, 107 insertions(+), 18 deletions(-)
---
(DIR) diff --git a/lib/kvlr/reports_as_sparkline/reporting_period.rb b/lib/kvlr/reports_as_sparkline/reporting_period.rb
@@ -64,6 +64,20 @@ module Kvlr #:nodoc:
end
end
+ # Returns the previous reporting period (that is next hour/day/month/year)
+ def previous
+ return case @grouping.identifier
+ when :hour
+ self.class.new(@grouping, @date_time - 1.hour)
+ when :day
+ self.class.new(@grouping, @date_time - 1.day)
+ when :week
+ self.class.new(@grouping, @date_time - 1.week)
+ when :month
+ self.class.new(@grouping, @date_time - 1.month)
+ end
+ end
+
def ==(other) #:nodoc:
if other.class == Kvlr::ReportsAsSparkline::ReportingPeriod
return @date_time.to_s == other.date_time.to_s && @grouping.identifier.to_s == other.grouping.identifier.to_s
(DIR) diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/ClassMethods.html b/rdoc/classes/Kvlr/ReportsAsSparkline/ClassMethods.html
@@ -115,7 +115,7 @@
<p>
Generates a report on a model. That report can then be executed via the new
method <name>_report (see documentation of <a
-href="Report.html#M000010">Kvlr::ReportsAsSparkline::Report#run</a>).
+href="Report.html#M000011">Kvlr::ReportsAsSparkline::Report#run</a>).
</p>
<h4>Parameters</h4>
<ul>
(DIR) diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/CumulatedReport.html b/rdoc/classes/Kvlr/ReportsAsSparkline/CumulatedReport.html
@@ -139,7 +139,7 @@ href="Report.html">Kvlr::ReportsAsSparkline::Report</a>)
<div class="method-description">
<p>
Runs the report (see <a
-href="Report.html#M000010">Kvlr::ReportsAsSparkline::Report#run</a>)
+href="Report.html#M000011">Kvlr::ReportsAsSparkline::Report#run</a>)
</p>
<p><a class="source-toggle" href="#"
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
(DIR) diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/Report.html b/rdoc/classes/Kvlr/ReportsAsSparkline/Report.html
@@ -93,8 +93,8 @@ and calculations
<h3 class="section-bar">Methods</h3>
<div class="name-list">
- <a href="#M000009">new</a>
- <a href="#M000010">run</a>
+ <a href="#M000010">new</a>
+ <a href="#M000011">run</a>
</div>
</div>
@@ -154,11 +154,11 @@ and calculations
<div id="methods">
<h3 class="section-bar">Public Class methods</h3>
- <div id="method-M000009" class="method-detail">
- <a name="M000009"></a>
+ <div id="method-M000010" class="method-detail">
+ <a name="M000010"></a>
<div class="method-heading">
- <a href="#M000009" class="method-signature">
+ <a href="#M000010" class="method-signature">
<span class="method-name">new</span><span class="method-args">(klass, name, options = {})</span>
</a>
</div>
@@ -210,8 +210,8 @@ false)
</li>
</ul>
<p><a class="source-toggle" href="#"
- onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
- <div class="method-source-code" id="M000009-source">
+ onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
+ <div class="method-source-code" id="M000010-source">
<pre>
<span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report.rb, line 23</span>
23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
@@ -237,11 +237,11 @@ false)
<h3 class="section-bar">Public Instance methods</h3>
- <div id="method-M000010" class="method-detail">
- <a name="M000010"></a>
+ <div id="method-M000011" class="method-detail">
+ <a name="M000011"></a>
<div class="method-heading">
- <a href="#M000010" class="method-signature">
+ <a href="#M000011" class="method-signature">
<span class="method-name">run</span><span class="method-args">(options = {})</span>
</a>
</div>
@@ -272,8 +272,8 @@ false)
</li>
</ul>
<p><a class="source-toggle" href="#"
- onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
- <div class="method-source-code" id="M000010-source">
+ onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
+ <div class="method-source-code" id="M000011-source">
<pre>
<span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/report.rb, line 47</span>
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>(<span class="ruby-identifier">options</span> = {})
(DIR) diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html b/rdoc/classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html
@@ -98,6 +98,7 @@ together.
<a href="#M000007">first</a>
<a href="#M000006">new</a>
<a href="#M000008">next</a>
+ <a href="#M000009">previous</a>
</div>
</div>
@@ -264,6 +265,43 @@ hour/day/month/year)
</div>
</div>
+ <div id="method-M000009" class="method-detail">
+ <a name="M000009"></a>
+
+ <div class="method-heading">
+ <a href="#M000009" class="method-signature">
+ <span class="method-name">previous</span><span class="method-args">()</span>
+ </a>
+ </div>
+
+ <div class="method-description">
+ <p>
+Returns the <a href="ReportingPeriod.html#M000009">previous</a> reporting
+period (that is <a href="ReportingPeriod.html#M000008">next</a>
+hour/day/month/year)
+</p>
+ <p><a class="source-toggle" href="#"
+ onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
+ <div class="method-source-code" id="M000009-source">
+<pre>
+ <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/reporting_period.rb, line 68</span>
+68: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">previous</span>
+69: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@grouping</span>.<span class="ruby-identifier">identifier</span>
+70: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:hour</span>
+71: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">hour</span>)
+72: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:day</span>
+73: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">day</span>)
+74: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:week</span>
+75: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">week</span>)
+76: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:month</span>
+77: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">month</span>)
+78: <span class="ruby-keyword kw">end</span>
+79: <span class="ruby-keyword kw">end</span>
+</pre>
+ </div>
+ </div>
+ </div>
+
</div>
(DIR) diff --git a/rdoc/created.rid b/rdoc/created.rid
@@ -1 +1 @@
-Mon, 19 Jan 2009 13:09:50 +0100
+Mon, 19 Jan 2009 13:15:23 +0100
(DIR) diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/reporting_period_rb.html b/rdoc/files/lib/kvlr/reports_as_sparkline/reporting_period_rb.html
@@ -56,7 +56,7 @@
</tr>
<tr class="top-aligned-row">
<td><strong>Last Update:</strong></td>
- <td>Thu Jan 15 11:36:51 +0100 2009</td>
+ <td>Mon Jan 19 13:11:39 +0100 2009</td>
</tr>
</table>
</div>
(DIR) diff --git a/rdoc/fr_method_index.html b/rdoc/fr_method_index.html
@@ -24,11 +24,12 @@
<a href="classes/Kvlr/ReportsAsSparkline/Grouping.html#M000005">identifier (Kvlr::ReportsAsSparkline::Grouping)</a><br />
<a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html#M000006">new (Kvlr::ReportsAsSparkline::ReportingPeriod)</a><br />
<a href="classes/Kvlr/ReportsAsSparkline/Grouping.html#M000004">new (Kvlr::ReportsAsSparkline::Grouping)</a><br />
- <a href="classes/Kvlr/ReportsAsSparkline/Report.html#M000009">new (Kvlr::ReportsAsSparkline::Report)</a><br />
+ <a href="classes/Kvlr/ReportsAsSparkline/Report.html#M000010">new (Kvlr::ReportsAsSparkline::Report)</a><br />
<a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html#M000008">next (Kvlr::ReportsAsSparkline::ReportingPeriod)</a><br />
+ <a href="classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html#M000009">previous (Kvlr::ReportsAsSparkline::ReportingPeriod)</a><br />
<a href="classes/Kvlr/ReportsAsSparkline/ClassMethods.html#M000002">reports_as_sparkline (Kvlr::ReportsAsSparkline::ClassMethods)</a><br />
<a href="classes/Kvlr/ReportsAsSparkline/CumulatedReport.html#M000003">run (Kvlr::ReportsAsSparkline::CumulatedReport)</a><br />
- <a href="classes/Kvlr/ReportsAsSparkline/Report.html#M000010">run (Kvlr::ReportsAsSparkline::Report)</a><br />
+ <a href="classes/Kvlr/ReportsAsSparkline/Report.html#M000011">run (Kvlr::ReportsAsSparkline::Report)</a><br />
<a href="classes/Kvlr/ReportsAsSparkline/SparklineTagHelper.html#M000001">sparkline_tag (Kvlr::ReportsAsSparkline::SparklineTagHelper)</a><br />
</div>
</div>
(DIR) diff --git a/spec/classes/reporting_period_spec.rb b/spec/classes/reporting_period_spec.rb
@@ -127,6 +127,42 @@ describe Kvlr::ReportsAsSparkline::ReportingPeriod do
end
+ describe '#previous' do
+
+ it 'should return a reporting period with date and time one hour before the current period for grouping :hour' do
+ now = Time.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::ReportsAsSparkline::Grouping.new(:hour), now)
+ expected = now - 1.hour
+
+ reporting_period.previous.date_time.should == DateTime.new(expected.year, expected.month, expected.day, expected.hour)
+ end
+
+ it 'should return a reporting period with date one day before the current period for grouping :day' do
+ now = Time.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::ReportsAsSparkline::Grouping.new(:day), now)
+ expected = now - 1.day
+
+ reporting_period.previous.date_time.should == Date.new(expected.year, expected.month, expected.day)
+ end
+
+ it 'should return a reporting period with date one week before the current period for grouping :week' do
+ now = DateTime.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::ReportsAsSparkline::Grouping.new(:week), now)
+ expected = reporting_period.date_time - 1.week
+
+ reporting_period.previous.date_time.should == Date.new(expected.year, expected.month, expected.day)
+ end
+
+ it 'should return a reporting period with date of the first day in the month one month before the current period' do
+ now = Time.now
+ reporting_period = Kvlr::ReportsAsSparkline::ReportingPeriod.new(Kvlr::ReportsAsSparkline::Grouping.new(:month), now)
+ expected = reporting_period.date_time - 1.month
+
+ reporting_period.previous.date_time.should == Date.new(expected.year, expected.month, 1)
+ end
+
+ end
+
describe '#==' do
it 'should return true for 2 reporting periods with the same date_time and grouping' do