stats_combiner 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/stats_combiner/filterer.rb +35 -30
- data/spec/stats_combiner_spec.rb +25 -3
- data/stats_combiner.gemspec +3 -3
- metadata +3 -20
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -66,40 +66,45 @@ module StatsCombiner
|
|
66
66
|
:prefix => nil
|
67
67
|
}.merge!(datum)
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if (filter[:rule][:prefix] && filter[:rule][:title_regex]) && datum[:title].match(filter[:rule][:title_regex])
|
74
|
-
datum[:prefix] = filter[:rule][:prefix]
|
75
|
-
end
|
76
|
-
|
77
|
-
# modify path => '?q=new_suffix'
|
78
|
-
# append to path with regex replacement variables => '\1&new_suffix'
|
79
|
-
if (filter[:rule][:suffix] && filter[:rule][:path_regex]) && datum[:path].match(filter[:rule][:path_regex])
|
80
|
-
datum[:path].gsub!(filter[:rule][:path_regex],filter[:rule][:suffix])
|
81
|
-
end
|
69
|
+
filters.each do |filter|
|
70
|
+
|
71
|
+
#skip filters if datum has already been nil'd
|
72
|
+
if not (datum[:title].nil? || datum[:path].nil?)
|
82
73
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
74
|
+
# set prefixes where they match title regexes
|
75
|
+
# /\| TPMDC/ => http://tpmdc
|
76
|
+
if (filter[:rule][:prefix] && filter[:rule][:title_regex]) && datum[:title].match(filter[:rule][:title_regex])
|
77
|
+
datum[:prefix] = filter[:rule][:prefix]
|
78
|
+
end
|
79
|
+
|
80
|
+
# modify path => '?q=new_suffix'
|
81
|
+
# append to path with regex replacement variables => '\1&new_suffix'
|
82
|
+
if (filter[:rule][:suffix] && filter[:rule][:path_regex]) && datum[:path].match(filter[:rule][:path_regex])
|
83
|
+
datum[:path].gsub!(filter[:rule][:path_regex],filter[:rule][:suffix])
|
84
|
+
end
|
85
|
+
|
86
|
+
# apply title mods
|
87
|
+
# modify_title => true /==>
|
88
|
+
# modify_title => "DC Central"
|
89
|
+
# title_regex => /| TPMDC/, modify_title => '\1 Central' ==> TPMDC Central
|
90
|
+
if filter[:rule][:modify_title]
|
91
|
+
filter[:rule][:modify_title] = '' unless filter[:rule][:modify_title].is_a?(String)
|
92
|
+
datum[:title].gsub!(filter[:rule][:title_regex], filter[:rule][:modify_title])
|
93
|
+
datum[:title].strip!
|
94
|
+
end
|
95
|
+
|
96
|
+
# apply excludes.
|
97
|
+
# this should take out the whole record if it matches a path or title regex
|
98
|
+
if filter[:rule][:exclude] && ((filter[:rule][:path_regex].is_a?(Regexp) && datum[:path].match(filter[:rule][:path_regex])) || (filter[:rule][:title_regex].is_a?(Regexp) && datum[:title].match(filter[:rule][:title_regex])))
|
99
|
+
# nil out datum.
|
100
|
+
# StatsCombiner::Combiner will sweep away the nils later
|
101
|
+
datum[:title] = datum[:path] = datum[:prefix] = nil
|
102
|
+
end
|
92
103
|
|
93
|
-
|
94
|
-
|
95
|
-
if filter[:rule][:exclude] && ((filter[:rule][:path_regex].is_a?(Regexp) && datum[:path].match(filter[:rule][:path_regex])) || (filter[:rule][:title_regex].is_a?(Regexp) && datum[:title].match(filter[:rule][:title_regex])))
|
96
|
-
# nil out datum.
|
97
|
-
# StatsCombiner::Combiner will sweep away the nils later
|
98
|
-
datum[:title] = datum[:path] = datum[:prefix] = nil
|
104
|
+
end
|
105
|
+
|
99
106
|
end
|
100
107
|
|
101
|
-
end
|
102
|
-
|
103
108
|
datum
|
104
109
|
|
105
110
|
end
|
data/spec/stats_combiner_spec.rb
CHANGED
@@ -179,9 +179,11 @@ describe "basic Filterer filtering" do
|
|
179
179
|
result = StatsCombiner::Filterer.apply_filters!(@f.filters,datum)
|
180
180
|
result[:title].should be_nil
|
181
181
|
result[:path].should be_nil
|
182
|
-
|
183
|
-
|
184
|
-
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should not nil out data when path or title regexes are unmatched' do
|
186
|
+
|
185
187
|
#now, let's look for invalid data. run a regex against a nonmatch
|
186
188
|
@f.add :path_regex => /(\/$|\/index.php$)/, :exclude => true
|
187
189
|
|
@@ -204,6 +206,26 @@ describe "basic Filterer filtering" do
|
|
204
206
|
|
205
207
|
end
|
206
208
|
|
209
|
+
it 'should handle multiple exclude rules by avoiding putting nils through filters twice' do
|
210
|
+
|
211
|
+
@f.add :path_regex => /(\/$|\/index.php$)/, :exclude => true
|
212
|
+
@f.add :path_regex => /talk\/blogs/, :exclude => true
|
213
|
+
|
214
|
+
datum_1 = {:visitors=>3090, :created_at=>nil, :path=>"/", :id=>1, :title=>"Talking Points Memo | Breaking News and Analysis"}
|
215
|
+
|
216
|
+
result_1 = StatsCombiner::Filterer.apply_filters!(@f.filters,datum_1)
|
217
|
+
result_1[:title].should be_nil
|
218
|
+
result_1[:path].should be_nil
|
219
|
+
|
220
|
+
|
221
|
+
datum_2 = {:visitors=>6, :created_at=>nil, :path=>"/talk/blogs/a/m/americandad/2010/03/an-open-letter-to-conservative.php/", :id=>31, :title=>"An open letter to conservatives | AmericanDad's Blog"}
|
222
|
+
|
223
|
+
result_2 = StatsCombiner::Filterer.apply_filters!(@f.filters,datum_2)
|
224
|
+
result_2[:title].should be_nil
|
225
|
+
result_2[:path].should be_nil
|
226
|
+
|
227
|
+
end
|
228
|
+
|
207
229
|
end
|
208
230
|
|
209
231
|
# best way to do this (without prying open the Class) might be
|
data/stats_combiner.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stats_combiner}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Al Shaw"]
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.homepage = %q{http://github.com/tpm/stats_combiner}
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
34
|
+
s.rubygems_version = %q{1.3.6}
|
35
35
|
s.summary = %q{StatsCombiner creates most-viewed story widgets from the Chartbeat API}
|
36
36
|
s.test_files = [
|
37
37
|
"spec/spec_helper.rb",
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
43
|
s.specification_version = 3
|
44
44
|
|
45
|
-
if Gem::Version.new(Gem::
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
46
|
s.add_runtime_dependency(%q<chartbeat>, [">= 0"])
|
47
47
|
s.add_runtime_dependency(%q<sequel>, [">= 0"])
|
48
48
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stats_combiner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Al Shaw
|
@@ -22,11 +21,9 @@ dependencies:
|
|
22
21
|
name: chartbeat
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
27
|
segments:
|
31
28
|
- 0
|
32
29
|
version: "0"
|
@@ -36,11 +33,9 @@ dependencies:
|
|
36
33
|
name: sequel
|
37
34
|
prerelease: false
|
38
35
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
36
|
requirements:
|
41
37
|
- - ">="
|
42
38
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
39
|
segments:
|
45
40
|
- 0
|
46
41
|
version: "0"
|
@@ -50,11 +45,9 @@ dependencies:
|
|
50
45
|
name: rspec
|
51
46
|
prerelease: false
|
52
47
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
48
|
requirements:
|
55
49
|
- - ">="
|
56
50
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
51
|
segments:
|
59
52
|
- 0
|
60
53
|
version: "0"
|
@@ -64,11 +57,9 @@ dependencies:
|
|
64
57
|
name: fakeweb
|
65
58
|
prerelease: false
|
66
59
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
60
|
requirements:
|
69
61
|
- - ">="
|
70
62
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
63
|
segments:
|
73
64
|
- 0
|
74
65
|
version: "0"
|
@@ -78,11 +69,9 @@ dependencies:
|
|
78
69
|
name: timecop
|
79
70
|
prerelease: false
|
80
71
|
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
hash: 3
|
86
75
|
segments:
|
87
76
|
- 0
|
88
77
|
version: "0"
|
@@ -92,11 +81,9 @@ dependencies:
|
|
92
81
|
name: hpricot
|
93
82
|
prerelease: false
|
94
83
|
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
84
|
requirements:
|
97
85
|
- - ">="
|
98
86
|
- !ruby/object:Gem::Version
|
99
|
-
hash: 3
|
100
87
|
segments:
|
101
88
|
- 0
|
102
89
|
version: "0"
|
@@ -132,27 +119,23 @@ rdoc_options:
|
|
132
119
|
require_paths:
|
133
120
|
- lib
|
134
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
-
none: false
|
136
122
|
requirements:
|
137
123
|
- - ">="
|
138
124
|
- !ruby/object:Gem::Version
|
139
|
-
hash: 3
|
140
125
|
segments:
|
141
126
|
- 0
|
142
127
|
version: "0"
|
143
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
-
none: false
|
145
129
|
requirements:
|
146
130
|
- - ">="
|
147
131
|
- !ruby/object:Gem::Version
|
148
|
-
hash: 3
|
149
132
|
segments:
|
150
133
|
- 0
|
151
134
|
version: "0"
|
152
135
|
requirements: []
|
153
136
|
|
154
137
|
rubyforge_project:
|
155
|
-
rubygems_version: 1.3.
|
138
|
+
rubygems_version: 1.3.6
|
156
139
|
signing_key:
|
157
140
|
specification_version: 3
|
158
141
|
summary: StatsCombiner creates most-viewed story widgets from the Chartbeat API
|