gcstats 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caches do
4
+ describe 'caches' do
5
+ subject { caches }
6
+
7
+ it { should have(40).items }
8
+
9
+ describe 'first cache' do
10
+ subject { caches.first }
11
+
12
+ it { should be_an_instance_of(Caches::Cache) }
13
+
14
+ its(:lat) { should == 39.712683 }
15
+ it { should respond_to(:latitude) }
16
+
17
+ its(:lon) { should == 21.637133 }
18
+ it { should respond_to(:longitude) }
19
+
20
+ its(:published) { should == Time.parse('Fri Jul 18 07:00:00 UTC 2003') }
21
+ it { should respond_to(:time) }
22
+
23
+ its(:code) { should == 'GCGJ59' }
24
+
25
+ its(:url) { should == 'http://www.geocaching.com/seek/cache_details.aspx?guid=da011f9e-40fc-4b67-9de4-b56e1836ddbf' }
26
+
27
+ its(:available?) { should be_true }
28
+
29
+ its(:archived?) { should be_false }
30
+
31
+ its(:name) { should == 'Meteora' }
32
+
33
+ its(:owner) { should == 'Pick' }
34
+
35
+ its(:placed_by) { should == 'Pick' }
36
+
37
+ its(:type) { should == 'Traditional Cache' }
38
+
39
+ its(:container) { should == 'Small' }
40
+ it { should respond_to(:size) }
41
+
42
+ its(:difficulty) { should == 1.0 }
43
+
44
+ its(:terrain) { should == 2.0 }
45
+
46
+ its(:country) { should == 'Greece' }
47
+
48
+ its(:state) { should be_empty }
49
+
50
+ its(:logs) { should have(1).item }
51
+
52
+ its(:find_dates) { should == [Date.parse('2009-09-01T19:00:00Z')] }
53
+
54
+ describe 'first log' do
55
+ subject { caches.first.logs.first }
56
+
57
+ it { should be_an_instance_of(Caches::Log) }
58
+
59
+ its(:date) { should == Date.parse('2009-09-01T19:00:00Z') }
60
+
61
+ its(:type) { should == 'Found it' }
62
+
63
+ its(:finder) { should == 'agorf' }
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ module Helpers
4
+ extend self
5
+ @caches = caches
6
+ @start_ts = Time.now
7
+ end
8
+
9
+ describe Helpers do
10
+ its(:total_finds) { should == 40 }
11
+
12
+ its(:total_archived) { should == 1 }
13
+
14
+ its(:days_cached) { should == 267 }
15
+
16
+ its(:finds_per_day) { should == 0.15 }
17
+
18
+ its(:most_finds_in_a_day) { should == 6 }
19
+
20
+ its(:most_finds_in_a_day_dates) { should == [Date.parse('2009-09-26')] }
21
+
22
+ its(:finds_by_date) do
23
+ should == Hash[
24
+ *[
25
+ '2010-05-17', 1,
26
+ '2009-10-18', 2,
27
+ '2009-09-26', 6,
28
+ '2009-11-01', 3,
29
+ '2009-10-24', 1,
30
+ '2010-03-18', 5,
31
+ '2009-09-01', 3,
32
+ '2009-10-29', 1,
33
+ '2010-01-12', 2,
34
+ '2009-09-02', 1,
35
+ '2009-08-25', 1,
36
+ '2009-11-26', 3,
37
+ '2009-12-27', 1,
38
+ '2009-08-23', 1,
39
+ '2009-09-27', 3,
40
+ '2010-03-14', 1,
41
+ '2009-10-11', 5
42
+ ].map {|e|
43
+ e.is_a?(String) ? Date.parse(e) : e
44
+ }.flatten
45
+ ]
46
+ end
47
+
48
+ its(:finds_by_day_of_week) { should == [1, 6, 1, 9, 0, 7, 16] }
49
+
50
+ its(:finds_by_year) { should == {2009 => 31, 2010 => 9} }
51
+
52
+ its(:finds_by_size) do
53
+ should == [
54
+ ['Small', 13],
55
+ ['Regular', 13],
56
+ ['Micro', 12],
57
+ ['Other', 1],
58
+ ['Not chosen', 1]
59
+ ]
60
+ end
61
+
62
+ its(:finds_by_type) do
63
+ should == [
64
+ ['Traditional Cache', 33],
65
+ ['Unknown Cache', 3],
66
+ ['Multi-cache', 3],
67
+ ['Event Cache', 1]
68
+ ]
69
+ end
70
+
71
+ its(:difficulty_terrain_combinations) do
72
+ should == [
73
+ [7, 1, 1, 0, 1, 0, 0, 0, 0],
74
+ [5, 3, 0, 0, 0, 0, 0, 0, 0],
75
+ [1, 1, 8, 3, 2, 1, 0, 0, 0],
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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 3, 0, 0, 0, -1],
96
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0],
97
+ [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, -1],
98
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
99
+ ]
100
+ end
101
+
102
+ its(:finds_by_country) { should == {'Greece' => 40} }
103
+
104
+ its(:finds_by_state) { should be_empty }
105
+
106
+ its(:finds_by_owner) do
107
+ should == [
108
+ ['yiannisp', 9],
109
+ ['teokar', 8],
110
+ ['tetras61', 7],
111
+ ['George & Christina', 4],
112
+ ['YanniG', 3],
113
+ ['GregoryGR', 2],
114
+ ['Mark-X', 1],
115
+ ['Hannera', 1],
116
+ ['MaximillianGraves', 1],
117
+ ['Pick', 1]
118
+ ]
119
+ end
120
+
121
+ its(:geocacher_name) { should == 'agorf' }
122
+
123
+ its(:finds_dates) do
124
+ should == [
125
+ '2010-05-17',
126
+ '2010-03-18',
127
+ '2010-03-14',
128
+ '2010-01-12',
129
+ '2009-12-27',
130
+ '2009-11-26',
131
+ '2009-11-01',
132
+ '2009-10-29',
133
+ '2009-10-24',
134
+ '2009-10-18',
135
+ '2009-10-11',
136
+ '2009-09-27',
137
+ '2009-09-26',
138
+ '2009-09-02',
139
+ '2009-09-01',
140
+ '2009-08-25',
141
+ '2009-08-23'
142
+ ].map {|e| Date.parse(e) }
143
+ end
144
+
145
+ it 'should return render time' do
146
+ start_ts = Helpers.instance_variable_get('@start_ts')
147
+ Time.should_receive(:now).and_return(start_ts + 10)
148
+ subject.render_time.should == 10.0
149
+ end
150
+
151
+ it 'should format percent with default precision 1' do
152
+ subject.format_percent(3, 9).should == '33.3%'
153
+ end
154
+
155
+ it 'should format percent with precision 0' do
156
+ subject.format_percent(3, 9, 0).should == '33%'
157
+ end
158
+
159
+ it 'should format percent with precision 2 (>1)' do
160
+ subject.format_percent(3, 9, 2).should == '33.33%'
161
+ end
162
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Template do
4
+ it 'should convert ERB to HTML' do
5
+ Template.new('My name is <%= @name %>', :name => 'Aggelos').result.should == 'My name is Aggelos'
6
+ end
7
+
8
+ it 'should not escape HTML by default' do
9
+ Template.new('Use <%= @tag %> for <%= @desc %>', :tag => '<b>', :desc => 'bold').result.should == 'Use <b> for bold'
10
+ end
11
+
12
+ it 'should escape HTML where h() helper is used' do
13
+ Template.new('Use <%=h @tag %> for <%= @desc %>', :tag => '<b>', :desc => 'bold').result.should == 'Use &lt;b&gt; for bold'
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ %w{caches helpers template}.each {|f| require "gcstats/#{f}" }
2
+
3
+ include GCStats
4
+
5
+ def xml_path
6
+ File.join(*%w{spec fixtures 3627915.gpx})
7
+ end
8
+
9
+ def xml_data
10
+ open(xml_path).read
11
+ end
12
+
13
+ def caches
14
+ Caches.from_xml(xml_data)
15
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcstats
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aggelos Orfanakos
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-20 00:00:00 +03:00
18
+ date: 2011-05-24 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,16 +42,20 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - README.md
45
- - config.ru
46
45
  - bin/gcstats
47
- - lib/gcstats/version.rb
48
- - lib/gcstats/gcstats.css
49
46
  - lib/gcstats/helpers.rb
50
- - lib/gcstats/mapping.rb
51
- - lib/gcstats/gcstats.js
52
- - lib/gcstats/template.rb
53
- - lib/gcstats/gcstats.rhtml
54
47
  - lib/gcstats/server.rb
48
+ - lib/gcstats/template.rb
49
+ - lib/gcstats/caches.rb
50
+ - lib/gcstats/version.rb
51
+ - data/gcstats/gcstats.rhtml
52
+ - data/gcstats/gcstats.css
53
+ - data/gcstats/gcstats.js
54
+ - spec/fixtures/3627915.gpx
55
+ - spec/spec_helper.rb
56
+ - spec/lib/helpers_spec.rb
57
+ - spec/lib/caches_spec.rb
58
+ - spec/lib/template_spec.rb
55
59
  has_rdoc: true
56
60
  homepage: http://github.com/agorf/gcstats
57
61
  licenses: []
@@ -82,9 +86,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
86
  requirements: []
83
87
 
84
88
  rubyforge_project:
85
- rubygems_version: 1.3.7
89
+ rubygems_version: 1.6.2
86
90
  signing_key:
87
91
  specification_version: 3
88
92
  summary: Simple and clean statistics of your Geocaching activity
89
- test_files: []
90
-
93
+ test_files:
94
+ - spec/fixtures/3627915.gpx
95
+ - spec/spec_helper.rb
96
+ - spec/lib/helpers_spec.rb
97
+ - spec/lib/caches_spec.rb
98
+ - spec/lib/template_spec.rb
data/config.ru DELETED
@@ -1,6 +0,0 @@
1
- libdir = File.join(File.dirname(__FILE__), 'lib')
2
- $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
-
4
- require 'gcstats/server'
5
-
6
- run Sinatra::Application