rugalytics 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
- v0.1.0. initial release
1
+ v0.0.2. only use graph points that fall within given report dates
2
+
3
+ v0.0.1. initial release
2
4
 
3
5
  v0.0.0. forked from Statwhore http://github.com/jnunemaker/statwhore
data/lib/rugalytics.rb CHANGED
@@ -10,7 +10,7 @@ require 'morph'
10
10
 
11
11
  # See README for usage documentation.
12
12
  module Rugalytics
13
- VERSION = "0.0.1"
13
+ VERSION = "0.0.2"
14
14
 
15
15
  FORMAT_PDF = '0' unless defined? FORMAT_PDF
16
16
  FORMAT_XML = '1' unless defined? FORMAT_XML
@@ -1,31 +1,39 @@
1
1
  module Rugalytics
2
2
  class Graph
3
3
 
4
- attr_reader :name, :points, :from, :to
4
+ attr_reader :name, :points, :points_by_day, :from, :to
5
5
 
6
- def initialize name, period, points
6
+ def initialize name, graph_period, points, report_start, report_end
7
7
  @name = name
8
- @period = period
9
- dates = @period.split('-')
10
- unless dates.empty?
11
- @from = Date.parse(dates[0].strip)
12
- @to = Date.parse(dates[1].strip)
13
- end
14
- @points = points
8
+ @from = report_start
9
+ @to = report_end
10
+ @points_by_day = create_points_by_day points, graph_period, report_start, report_end
11
+ @points = points_by_day.collect{|by_day| by_day[1]}
15
12
  end
16
13
 
17
14
  def sum_of_points
18
15
  points.sum
19
16
  end
20
17
 
21
- def points_by_day
22
- by_day = []
18
+ private
19
+
20
+ def create_points_by_day points, graph_period, report_start, report_end
21
+ with_dates_from_period(graph_period, []) do |date, index, list|
22
+ list << [date, points[index] ] if date >= report_start && date <= report_end
23
+ end
24
+ end
25
+
26
+ def with_dates_from_period period, list
27
+ dates = period.split('-')
28
+ from = Date.parse(dates[0].strip)
29
+ to = Date.parse(dates[1].strip)
30
+
23
31
  index = 0
24
32
  from.upto(to) do |date|
25
- by_day << [date, points[index] ]
33
+ yield date, index, list
26
34
  index = index.next
27
35
  end
28
- by_day
36
+ list
29
37
  end
30
38
  end
31
39
  end
@@ -23,7 +23,7 @@ module Rugalytics
23
23
  if is_writer = symbol.to_s[/=$/]
24
24
  morph_method_missing(symbol, *args)
25
25
 
26
- elsif symbol.to_s.match /(.*)_(total|by_day)/
26
+ elsif symbol.to_s.match(/(.*)_(total|by_day)/)
27
27
  graph = "#{$1}_graph".to_sym
28
28
 
29
29
  if respond_to?(graph)
@@ -43,8 +43,8 @@ module Rugalytics
43
43
  @base_url = lines[1]
44
44
  @report_name = lines[2].chomp(',')
45
45
  dates = lines[3].split(',')
46
- @start_date = dates[0]
47
- @end_date = dates[1]
46
+ @start_date = Date.parse(dates[0])
47
+ @end_date = Date.parse(dates[1])
48
48
  end
49
49
 
50
50
  def handle_graphs lines
@@ -55,7 +55,7 @@ module Rugalytics
55
55
  return if index == lines.size
56
56
  end
57
57
  index = index + 2
58
- period = lines[index]
58
+ graph_period = lines[index]
59
59
  index = index.next
60
60
  name = lines[index]
61
61
  index = index.next
@@ -66,7 +66,7 @@ module Rugalytics
66
66
  index = index.next
67
67
  end
68
68
 
69
- graph = Graph.new name, period, points
69
+ graph = Graph.new name, graph_period, points, start_date, end_date
70
70
  morph("#{name} graph", graph)
71
71
  end
72
72
  end
data/rugalytics.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
 
2
- # Gem::Specification for Rugalytics-0.0.1
2
+ # Gem::Specification for Rugalytics-0.0.2
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{rugalytics}
7
- s.version = "0.0.1"
7
+ s.version = "0.0.2"
8
8
 
9
9
  s.specification_version = 2 if s.respond_to? :specification_version=
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Rob McKinnon"]
13
- s.date = %q{2008-06-06}
13
+ s.date = %q{2008-06-07}
14
14
  s.description = %q{Rugalytics is a Ruby API for Google Analytics.}
15
15
  s.email = ["rob ~@nospam@~ rubyforge.org"]
16
16
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
@@ -10,34 +10,38 @@ describe Rugalytics::Graph do
10
10
  @points = [5360, 3330, 4330]
11
11
  end
12
12
 
13
- it "should create fields for attributes and values" do
14
- graph = Rugalytics::Graph.new @name, @period, @points
15
-
16
- graph.from.should == Date.parse('2008-05-01')
17
- graph.to.should == Date.parse('2008-05-03')
13
+ def graph_correct_for report_start, report_end, expected_points
14
+ graph = Rugalytics::Graph.new @name, @period, @points, report_start, report_end
15
+ graph.from.should == report_start
16
+ graph.to.should == report_end
17
+ graph.points.should == expected_points
18
+ graph
19
+ end
18
20
 
19
- graph.points.should == @points
21
+ it "should set given points on graph" do
22
+ graph_correct_for Date.parse('2008-05-01'), Date.parse('2008-05-03'), @points
20
23
  end
21
24
 
22
- end
25
+ it "should set appropriate point on graph when report start and end is the same date" do
26
+ graph_correct_for Date.parse('2008-05-01'), Date.parse('2008-05-01'), [@points[0]]
27
+ end
23
28
 
24
- describe 'when counting total of points' do
25
- it 'should sum points in graph' do
26
- graph = Rugalytics::Graph.new '','',[5360, 3330, 4330]
27
- graph.sum_of_points.should == 5360 + 3330 + 4330
29
+ it "should set appropriate points on graph when report start and end is a subset of the graph period" do
30
+ graph_correct_for Date.parse('2008-05-02'), Date.parse('2008-05-03'), [@points[1],@points[2]]
28
31
  end
29
- end
30
32
 
31
- describe 'when counting total of points' do
32
- it 'should sum points in graph' do
33
- graph = Rugalytics::Graph.new '','',[5360, 3330, 4330]
34
- from = Date.parse('1 May 2003')
35
- mid = Date.parse('2 May 2003')
36
- to = Date.parse('3 May 2003')
37
- graph.stub!(:from).and_return from
38
- graph.stub!(:to).and_return to
33
+ it 'should set points by day' do
34
+ from = Date.parse('1 May 2008')
35
+ to = Date.parse('3 May 2008')
36
+ mid = Date.parse('2 May 2008')
37
+ graph = graph_correct_for from, to, @points
39
38
  graph.points_by_day.should == [[from,5360],[mid,3330],[to,4330]]
40
39
  end
40
+
41
+ it 'should return sum of points' do
42
+ graph = graph_correct_for Date.parse('2008-05-01'), Date.parse('2008-05-03'), @points
43
+ graph.sum_of_points.should == 5360 + 3330 + 4330
44
+ end
41
45
  end
42
46
 
43
47
  end
@@ -23,11 +23,11 @@ Top Content,
23
23
  end
24
24
 
25
25
  it "should set start date from fourth line of text" do
26
- @report.start_date.should == '26 May 2008'
26
+ @report.start_date.should == Date.parse('26 May 2008')
27
27
  end
28
28
 
29
29
  it "should set end date from fourth line of text" do
30
- @report.end_date.should == '31 May 2008'
30
+ @report.end_date.should == Date.parse('31 May 2008')
31
31
  end
32
32
  end
33
33
 
@@ -105,10 +105,12 @@ Visitors Overview,
105
105
  before :all do
106
106
  @period = %Q|1 May 2008 - 31 May 2008|
107
107
  @name = %Q|Page Views|
108
+ @start = %Q|26 May 2008|
109
+ @end = %Q|31 May 2008|
108
110
  @csv = %Q|# ----------------------------------------
109
111
  theyworkforyou.co.nz
110
112
  Top Content,
111
- 26 May 2008,31 May 2008
113
+ #{@start},#{@end}
112
114
  # ----------------------------------------
113
115
 
114
116
  # ----------------------------------------
@@ -122,7 +124,7 @@ Top Content,
122
124
 
123
125
  it 'should create graph with data under "Graph"' do
124
126
  graph = mock('graph')
125
- Rugalytics::Graph.should_receive(:new).with(@name, @period, [5360, 433]).and_return graph
127
+ Rugalytics::Graph.should_receive(:new).with(@name, @period, [5360, 433], Date.parse(@start), Date.parse(@end)).and_return graph
126
128
 
127
129
  report = Rugalytics::Report.new(@csv)
128
130
  report.page_views_graph.should == graph
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugalytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob McKinnon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-06 00:00:00 +01:00
12
+ date: 2008-06-07 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency