aloha_analyzer 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dad41187162d0ded37fd3f579d68a530e64f126f
4
- data.tar.gz: 93f7d00cd83a16c4e00ef282552ecd768572a92e
3
+ metadata.gz: 19bcb240f0ee29c4f9f5f032068ba3ff9710b823
4
+ data.tar.gz: 3f5987f278c69bf7d92453c2fa319b1aa5bdfa60
5
5
  SHA512:
6
- metadata.gz: 09d4452b31e1954e5e1b120d8f21109d287ef7840d093e64b703cc16536aa4d0cbe5cd398f5be201ecc19f2de4aac45b58fae94f8bb2ea19f01db98ca9aaaa28
7
- data.tar.gz: 1fce07d0a3188d3dc90839b938c9ccd4eaca4fa028e3478581a61d0c08bd6700b8ee1a4657c7657967f249a7e52bfb22dc453f649e7458bde2b10622468f81bb
6
+ metadata.gz: d7daaa3a619a0aa542ec8090fb9e12b5c4311224ad7dec47583eb9285e7323f4705d1c7e1a7f6c2e5b40b38674c508509d9b3793214b847d5385a9dd1e227efc
7
+ data.tar.gz: 2877ab35ed1f3c6b7a67279e38a3d3e2c5fd1a7857c984e4e2d95b94df42a72ab7b4efb1b4d548855f48d059445d6520e7e3180dab7f888d3684882c4502b936
@@ -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 languages['languages'][abbreviation]
32
- languages['languages'][abbreviation]['count'] += 1
33
- languages['languages'][abbreviation]['users'].push user
18
+ if abbreviation == @language
19
+ analysys[:user_language][:count] += 1
20
+ analysys[:user_language][:users].push user
34
21
  else
35
- languages['languages'][abbreviation] = {
36
- 'count' => 1,
37
- 'language' => Language.find_by_abbreviation(abbreviation),
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
- languages['languages'][abbreviation] = {
60
- 'count' => 1,
61
- 'language' => Language.find_by_abbreviation(abbreviation),
62
- 'users' => [user]
26
+ analysys[:foreign_languages][abbreviation] = {
27
+ :count => 1,
28
+ :language => Language.find_by_abbreviation(abbreviation),
29
+ :users => [user]
63
30
  }
64
31
  end
65
- languages['languages'][abbreviation]['percentage'] = ((100 / users_total_without_user_language.to_f) * languages['languages'][abbreviation]['count']).round(2)
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
- def user_language_count
77
- @user_language_count ||= if with_user_language['languages'][@language]
78
- with_user_language['languages'][@language]['count']
79
- else
80
- 0
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
 
@@ -1,3 +1,3 @@
1
1
  module AlohaAnalyzer
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -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[:with_user_language]['languages'].should eq({})
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[:without_user_language]['languages'].should eq({})
58
- subject[:without_user_language]['count'].should eq 0
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
- "abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"
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 'returns results based on the user language' do
90
- subject[:with_user_language].should == {
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 results based on the non user language' do
116
- subject[:without_user_language].should eq(
117
- 'count' => 2,
118
- 'languages' => {
119
- 'fr' => {
120
- 'percentage' => 50,
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
- 'percentage' => 50,
127
- 'count' => 1,
128
- 'language' => {'abbreviation'=>'de', 'name'=>'German', 'population'=>5000000, 'countries' => 'Germany, Austria, Switzerland, Belgium'},
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
- it 'returns results based on the user language' do
155
- subject[:with_user_language].should == {
156
- 'count' => 2,
157
- 'languages' => {
158
- 'en' => {
159
- 'percentage' => 100,
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
- it 'returns a hash' do
183
- subject.should be_a Hash
184
- end
118
+ it 'returns a hash' do
119
+ subject.should be_a Hash
120
+ end
185
121
 
186
- it 'includes the user lanugage' do
187
- subject[:user_language].should eq(
188
- "abbreviation"=>"en", "name"=>"English", "population"=>238000000, "countries"=>"USA, Canada, UK, Ireland, Australia"
189
- )
190
- end
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
- it 'returns results based on the user language' do
193
- subject[:with_user_language].should == {
194
- 'count' => 2,
195
- 'languages' => {
196
- 'fr' => {
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
- it 'returns results results based on the non user language' do
213
- subject[:without_user_language].should eq(
214
- 'count' => 2,
215
- 'languages' => {
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
- context 'when aliases' do
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' => 'en'},
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 'includes the user lanugage' do
244
- subject[:user_language].should eq(
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 'merges english and british' do
250
- subject[:with_user_language].should == {
251
- 'count' => 3,
252
- 'languages' => {
253
- 'en' => {
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
- subject[:without_user_language].should eq(
269
- 'count' => 1,
270
- 'languages' => {
271
- 'fr' => {
272
- 'percentage' => 100,
273
- 'count' => 1,
274
- 'language' => {'abbreviation'=>'fr', 'name'=>'French', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
275
- 'users' => [{'id' => '2', 'lang' => 'fr'}]
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 'and some users are chinese' do
182
+ context 'when aliases' do
283
183
  let(:users) {
284
184
  [
285
- {'id' => '1', 'lang' => 'zh-cn'},
286
- {'id' => '2', 'lang' => 'zh-cn'},
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 'merges chinese' do
293
- subject[:with_user_language].should == {
294
- 'count' => 4,
295
- 'languages' => {
296
- 'zh' => {
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
- subject[:without_user_language].should eq(
312
- 'count' => 3,
313
- 'languages' => {
314
- 'zh' => {
315
- 'percentage' => 100,
316
- 'count' => 3,
317
- 'language'=>{'abbreviation'=>'zh', 'name'=>'Chinese', 'population'=>20000, 'countries' => 'China, Hong-Kong, Macau' },
318
- 'users' => [{'id' => '1', 'lang' => 'zh'}, {'id' => '2', 'lang' => 'zh'}, {'id' => '4', 'lang' => 'zh'}]
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.3
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-08 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler