aloha_analyzer 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aloha_analyzer/user.rb +23 -54
- data/lib/aloha_analyzer/version.rb +1 -1
- data/spec/aloha_analyzer/user_spec.rb +93 -205
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19bcb240f0ee29c4f9f5f032068ba3ff9710b823
|
4
|
+
data.tar.gz: 3f5987f278c69bf7d92453c2fa319b1aa5bdfa60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7daaa3a619a0aa542ec8090fb9e12b5c4311224ad7dec47583eb9285e7323f4705d1c7e1a7f6c2e5b40b38674c508509d9b3793214b847d5385a9dd1e227efc
|
7
|
+
data.tar.gz: 2877ab35ed1f3c6b7a67279e38a3d3e2c5fd1a7857c984e4e2d95b94df42a72ab7b4efb1b4d548855f48d059445d6520e7e3180dab7f888d3684882c4502b936
|
data/lib/aloha_analyzer/user.rb
CHANGED
@@ -12,72 +12,41 @@ module AlohaAnalyzer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def analyze
|
15
|
-
|
16
|
-
user_language: Language.find_by_abbreviation(@language),
|
17
|
-
with_user_language: with_user_language,
|
18
|
-
without_user_language: without_user_language
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def with_user_language
|
25
|
-
@with_user_language ||= Hash.new.tap do |languages|
|
26
|
-
languages['count'] = 0
|
27
|
-
languages['languages'] = Hash.new
|
28
|
-
|
15
|
+
boilerplate_analysis.tap do |analysys|
|
29
16
|
@users.each do |user|
|
30
17
|
abbreviation = user['lang']
|
31
|
-
if
|
32
|
-
|
33
|
-
|
18
|
+
if abbreviation == @language
|
19
|
+
analysys[:user_language][:count] += 1
|
20
|
+
analysys[:user_language][:users].push user
|
34
21
|
else
|
35
|
-
|
36
|
-
|
37
|
-
'
|
38
|
-
'users' => [user]
|
39
|
-
}
|
40
|
-
end
|
41
|
-
languages['languages'][abbreviation]['percentage'] = ((100 / @users_count.to_f) * languages['languages'][abbreviation]['count']).round(2)
|
42
|
-
languages['count'] += 1
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def without_user_language
|
48
|
-
@without_user_language ||= Hash.new.tap do |languages|
|
49
|
-
languages['count'] = 0
|
50
|
-
languages['languages'] = Hash.new
|
51
|
-
|
52
|
-
@users.each do |user|
|
53
|
-
abbreviation = user['lang']
|
54
|
-
if abbreviation != @language
|
55
|
-
if languages['languages'][abbreviation]
|
56
|
-
languages['languages'][abbreviation]['count'] += 1
|
57
|
-
languages['languages'][abbreviation]['users'].push user
|
22
|
+
if analysys[:foreign_languages][abbreviation]
|
23
|
+
analysys[:foreign_languages][abbreviation][:count] += 1
|
24
|
+
analysys[:foreign_languages][abbreviation]['users'].push user
|
58
25
|
else
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
26
|
+
analysys[:foreign_languages][abbreviation] = {
|
27
|
+
:count => 1,
|
28
|
+
:language => Language.find_by_abbreviation(abbreviation),
|
29
|
+
:users => [user]
|
63
30
|
}
|
64
31
|
end
|
65
|
-
|
66
|
-
languages['count'] += 1
|
32
|
+
analysys[:foreign_languages_count] += 1
|
67
33
|
end
|
68
34
|
end
|
69
35
|
end
|
70
36
|
end
|
71
37
|
|
72
|
-
def users_total_without_user_language
|
73
|
-
@users_total_without_user_language ||= @users_count - user_language_count
|
74
|
-
end
|
75
38
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
39
|
+
private
|
40
|
+
|
41
|
+
def boilerplate_analysis
|
42
|
+
Hash.new.tap do |analysys|
|
43
|
+
analysys[:user_language] = {
|
44
|
+
count: 0,
|
45
|
+
language: Language.find_by_abbreviation(@language),
|
46
|
+
users: []
|
47
|
+
}
|
48
|
+
analysys[:foreign_languages_count] = 0
|
49
|
+
analysys[:foreign_languages] = Hash.new
|
81
50
|
end
|
82
51
|
end
|
83
52
|
|
@@ -49,19 +49,18 @@ describe AlohaAnalyzer::User do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'has no results with the user language' do
|
52
|
-
subject[:
|
53
|
-
subject[:with_user_language]['count'].should eq 0
|
52
|
+
subject[:user_language][:count].should eq 0
|
54
53
|
end
|
55
54
|
|
56
55
|
it 'has no results without the user language' do
|
57
|
-
subject[:
|
58
|
-
subject[:
|
56
|
+
subject[:foreign_languages].should eq({})
|
57
|
+
subject[:foreign_languages_count].should eq 0
|
59
58
|
end
|
60
59
|
|
61
60
|
it 'includes the user lanugage' do
|
62
|
-
subject[:user_language].should eq(
|
61
|
+
subject[:user_language][:language].should eq(
|
63
62
|
"abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"
|
64
|
-
|
63
|
+
)
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
@@ -82,246 +81,135 @@ describe AlohaAnalyzer::User do
|
|
82
81
|
|
83
82
|
it 'includes the user lanugage' do
|
84
83
|
subject[:user_language].should eq(
|
85
|
-
|
86
|
-
|
84
|
+
:count => 2,
|
85
|
+
:language => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"},
|
86
|
+
:users => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
|
87
|
+
)
|
87
88
|
end
|
88
89
|
|
89
|
-
it '
|
90
|
-
subject[:
|
91
|
-
'count' => 4,
|
92
|
-
'languages' => {
|
93
|
-
'en' => {
|
94
|
-
'percentage' => 50,
|
95
|
-
'count' => 2,
|
96
|
-
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"},
|
97
|
-
'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
|
98
|
-
},
|
99
|
-
'fr' => {
|
100
|
-
'percentage' => 25,
|
101
|
-
'count' => 1,
|
102
|
-
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, "countries"=>"France, Canada, Belgium, Switzerland"},
|
103
|
-
'users' => [{'id' => '2', 'lang' => 'fr'}]
|
104
|
-
},
|
105
|
-
'de' => {
|
106
|
-
'percentage' => 25,
|
107
|
-
'count' => 1,
|
108
|
-
'language' => {'abbreviation'=>'de', 'name'=>'German', 'population'=>5000000, "countries"=>"Germany, Austria, Switzerland, Belgium"},
|
109
|
-
'users' => [{'id' => '4', 'lang' => 'de'}]
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
90
|
+
it 'includs the foreign followers count' do
|
91
|
+
subject[:foreign_languages_count].should eq 2
|
113
92
|
end
|
114
93
|
|
115
|
-
it 'returns results
|
116
|
-
subject[:
|
117
|
-
'
|
118
|
-
|
119
|
-
'fr' =>
|
120
|
-
|
121
|
-
'count' => 1,
|
122
|
-
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
123
|
-
'users' => [{'id' => '2', 'lang' => 'fr'}]
|
94
|
+
it 'returns results based on the user language' do
|
95
|
+
subject[:foreign_languages].should == {
|
96
|
+
'fr' => {
|
97
|
+
count: 1,
|
98
|
+
language: {'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, "countries"=>"France, Canada, Belgium, Switzerland"},
|
99
|
+
users: [{'id' => '2', 'lang' => 'fr'}]
|
124
100
|
},
|
125
101
|
'de' => {
|
126
|
-
|
127
|
-
'
|
128
|
-
|
129
|
-
'users' => [{'id' => '4', 'lang' => 'de'}]
|
102
|
+
count: 1,
|
103
|
+
language: {'abbreviation'=>'de', 'name'=>'German', 'population'=>5000000, "countries"=>"Germany, Austria, Switzerland, Belgium"},
|
104
|
+
users: [{'id' => '4', 'lang' => 'de'}]
|
130
105
|
}
|
131
106
|
}
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'when only user langugages users' do
|
137
|
-
let(:users) {
|
138
|
-
[
|
139
|
-
{'id' => '1', 'lang' => 'en'},
|
140
|
-
{'id' => '2', 'lang' => 'en'}
|
141
|
-
]
|
142
|
-
}
|
143
|
-
|
144
|
-
it 'returns a hash' do
|
145
|
-
subject.should be_a Hash
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'includes the user lanugage' do
|
149
|
-
subject[:user_language].should eq(
|
150
|
-
"abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"
|
151
|
-
)
|
107
|
+
end
|
152
108
|
end
|
153
109
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
'
|
159
|
-
|
160
|
-
'count' => 2,
|
161
|
-
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries' => 'USA, Canada, UK, Ireland, Australia'},
|
162
|
-
'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '2', 'lang' => 'en'}]
|
163
|
-
}
|
164
|
-
}
|
110
|
+
context 'when only user langugages users' do
|
111
|
+
let(:users) {
|
112
|
+
[
|
113
|
+
{'id' => '1', 'lang' => 'en'},
|
114
|
+
{'id' => '2', 'lang' => 'en'}
|
115
|
+
]
|
165
116
|
}
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'returns results results based on the non user language' do
|
169
|
-
subject[:without_user_language]['languages'].should == {}
|
170
|
-
subject[:without_user_language]['count'].should eq 0
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context 'when no users language users' do
|
175
|
-
let(:users) {
|
176
|
-
[
|
177
|
-
{'id' => '1', 'lang' => 'de'},
|
178
|
-
{'id' => '2', 'lang' => 'fr'}
|
179
|
-
]
|
180
|
-
}
|
181
117
|
|
182
|
-
|
183
|
-
|
184
|
-
|
118
|
+
it 'returns a hash' do
|
119
|
+
subject.should be_a Hash
|
120
|
+
end
|
185
121
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
122
|
+
it 'includes the user lanugage' do
|
123
|
+
subject[:user_language][:language].should eq(
|
124
|
+
"abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"
|
125
|
+
)
|
126
|
+
end
|
191
127
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
'
|
197
|
-
'percentage' => 50,
|
198
|
-
'count' => 1,
|
199
|
-
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
200
|
-
'users' => [{'id' => '2', 'lang' => 'fr'}]
|
201
|
-
},
|
202
|
-
'de' => {
|
203
|
-
'percentage' => 50,
|
204
|
-
'count' => 1,
|
205
|
-
'language' => {'abbreviation'=>'de', 'name'=>'German', 'population'=>5000000, 'countries' => 'Germany, Austria, Switzerland, Belgium'},
|
206
|
-
'users' => [{'id' => '1', 'lang' => 'de'}]
|
207
|
-
}
|
128
|
+
it 'returns results based on the user language' do
|
129
|
+
subject[:user_language].should == {
|
130
|
+
:count => 2,
|
131
|
+
:language => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries' => 'USA, Canada, UK, Ireland, Australia'},
|
132
|
+
:users => [{'id' => '1', 'lang' => 'en'}, {'id' => '2', 'lang' => 'en'}]
|
208
133
|
}
|
209
|
-
|
210
|
-
end
|
134
|
+
end
|
211
135
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
'fr' => {
|
217
|
-
'percentage' => 50,
|
218
|
-
'count' => 1,
|
219
|
-
'language' => { 'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland' },
|
220
|
-
'users' => [{'id' => '2', 'lang' => 'fr'}]
|
221
|
-
},
|
222
|
-
'de' => {
|
223
|
-
'percentage' => 50,
|
224
|
-
'count' => 1,
|
225
|
-
'language' => {'abbreviation'=>'de', 'name'=>'German', 'population'=>5000000, 'countries' => 'Germany, Austria, Switzerland, Belgium' },
|
226
|
-
'users' => [{'id' => '1', 'lang' => 'de'}]
|
227
|
-
}
|
228
|
-
}
|
229
|
-
)
|
136
|
+
it 'returns results results based on the non user language' do
|
137
|
+
subject[:foreign_languages].should == {}
|
138
|
+
subject[:foreign_languages_count].should eq 0
|
139
|
+
end
|
230
140
|
end
|
231
|
-
end
|
232
141
|
|
233
|
-
|
234
|
-
context 'and some users british' do
|
142
|
+
context 'when no users language users' do
|
235
143
|
let(:users) {
|
236
144
|
[
|
237
|
-
{'id' => '1', 'lang' => '
|
238
|
-
{'id' => '2', 'lang' => 'fr'}
|
239
|
-
{'id' => '3', 'lang' => 'en-GB'}
|
145
|
+
{'id' => '1', 'lang' => 'de'},
|
146
|
+
{'id' => '2', 'lang' => 'fr'}
|
240
147
|
]
|
241
148
|
}
|
242
149
|
|
243
|
-
it '
|
244
|
-
subject
|
245
|
-
"abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"
|
246
|
-
)
|
150
|
+
it 'returns a hash' do
|
151
|
+
subject.should be_a Hash
|
247
152
|
end
|
248
153
|
|
249
|
-
it '
|
250
|
-
subject[:
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
'percentage' => 66.67,
|
255
|
-
'count' => 2,
|
256
|
-
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries' => 'USA, Canada, UK, Ireland, Australia' },
|
257
|
-
'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
|
258
|
-
},
|
259
|
-
'fr' => {
|
260
|
-
'percentage' => 33.33,
|
261
|
-
'count' => 1,
|
262
|
-
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
263
|
-
'users' => [{'id' => '2', 'lang' => 'fr'}]
|
264
|
-
}
|
265
|
-
}
|
154
|
+
it 'returns results based on the user language' do
|
155
|
+
subject[:user_language].should == {
|
156
|
+
:count => 0,
|
157
|
+
:language => {"abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"},
|
158
|
+
:users => []
|
266
159
|
}
|
160
|
+
end
|
267
161
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
162
|
+
it 'includes the correct foreign_languages_count' do
|
163
|
+
subject[:foreign_languages_count].should eq 2
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'returns results results based on the non user language' do
|
167
|
+
subject[:foreign_languages].should eq(
|
168
|
+
'fr' => {
|
169
|
+
:count => 1,
|
170
|
+
:language => { 'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland' },
|
171
|
+
:users => [{'id' => '2', 'lang' => 'fr'}]
|
172
|
+
},
|
173
|
+
'de' => {
|
174
|
+
:count => 1,
|
175
|
+
:language => {'abbreviation'=>'de', 'name'=>'German', 'population'=>5000000, 'countries' => 'Germany, Austria, Switzerland, Belgium' },
|
176
|
+
:users => [{'id' => '1', 'lang' => 'de'}]
|
276
177
|
}
|
277
|
-
|
278
|
-
)
|
178
|
+
)
|
279
179
|
end
|
280
180
|
end
|
281
181
|
|
282
|
-
context '
|
182
|
+
context 'when aliases' do
|
283
183
|
let(:users) {
|
284
184
|
[
|
285
|
-
{'id' => '1', 'lang' => '
|
286
|
-
{'id' => '2', 'lang' => '
|
287
|
-
{'id' => '3', 'lang' => 'en'}
|
288
|
-
{'id' => '4', 'lang' => 'zh-tw'}
|
185
|
+
{'id' => '1', 'lang' => 'en'},
|
186
|
+
{'id' => '2', 'lang' => 'fr'},
|
187
|
+
{'id' => '3', 'lang' => 'en-GB'}
|
289
188
|
]
|
290
189
|
}
|
291
190
|
|
292
|
-
it '
|
293
|
-
subject[:
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
'percentage' => 75,
|
298
|
-
'count' => 3,
|
299
|
-
'language' => {'abbreviation'=>'zh', 'name'=>'Chinese', 'population'=>20000, 'countries' => 'China, Hong-Kong, Macau' },
|
300
|
-
'users' => [{'id' => '1', 'lang' => 'zh'}, {'id' => '2', 'lang' => 'zh'}, {'id' => '4', 'lang' => 'zh'}]
|
301
|
-
},
|
302
|
-
'en' => {
|
303
|
-
'percentage' => 25,
|
304
|
-
'count' => 1,
|
305
|
-
'language'=>{'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries' => 'USA, Canada, UK, Ireland, Australia' },
|
306
|
-
'users' => [{'id' => '3', 'lang' => 'en'},]
|
307
|
-
}
|
308
|
-
}
|
191
|
+
it 'includes the user lanugage' do
|
192
|
+
subject[:user_language].should == {
|
193
|
+
:count => 2,
|
194
|
+
:language => { "abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia" },
|
195
|
+
:users => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
|
309
196
|
}
|
197
|
+
end
|
310
198
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
}
|
199
|
+
it 'includes the correct foreign_languages_count' do
|
200
|
+
subject[:foreign_languages_count].should eq 1
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'merges english and british' do
|
204
|
+
subject[:foreign_languages].should eq(
|
205
|
+
'fr' => {
|
206
|
+
:count => 1,
|
207
|
+
:language => {'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
208
|
+
:users => [{'id' => '2', 'lang' => 'fr'}]
|
320
209
|
}
|
321
|
-
|
210
|
+
)
|
322
211
|
end
|
323
212
|
end
|
324
213
|
end
|
325
214
|
end
|
326
215
|
end
|
327
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aloha_analyzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Aussaguel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|