aloha_analyzer 0.3.1 → 0.4.0
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 +4 -4
- data/lib/aloha_analyzer/user.rb +5 -6
- data/lib/aloha_analyzer/version.rb +1 -1
- data/spec/aloha_analyzer/user_spec.rb +35 -37
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c2bc2b5fb168b92598aaf665bd052e34d6a8d0d
|
4
|
+
data.tar.gz: 2656ab9c6028b898d38dd6e61b3d856d43d1adb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 404f72d579c02ab3bf911ead9cfe416a05442727716c2e498506bdcd3ee4bbd74bdea768cdf014470e3f6a3b5e1495f08702090941b1fff4342efd0988819e5c
|
7
|
+
data.tar.gz: e55890d6bd78147f23ab1e81605665bfb204e092ea0e27bd8e4fbeb2febd3305961fdafd42f507f92f258c97b23f51f2bd66f6c2022253eae74d6d334d4cc6b1
|
data/lib/aloha_analyzer/user.rb
CHANGED
@@ -4,14 +4,13 @@ module AlohaAnalyzer
|
|
4
4
|
attr_reader :language, :analysis
|
5
5
|
|
6
6
|
def initialize(options)
|
7
|
-
@language
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@options = options
|
7
|
+
@language = clean_language(options['language'].downcase)
|
8
|
+
@analysis = (options['analysis'] || boilerplate).clone
|
9
|
+
@options = options
|
11
10
|
end
|
12
11
|
|
13
|
-
def analyze
|
14
|
-
|
12
|
+
def analyze(users)
|
13
|
+
clean_users(users).each do |user|
|
15
14
|
if user['lang'] == @language
|
16
15
|
add_account_language_user(user)
|
17
16
|
@analysis['account_language']['count'] += 1
|
@@ -6,15 +6,13 @@ describe AlohaAnalyzer::User do
|
|
6
6
|
let(:options) do
|
7
7
|
{
|
8
8
|
'language' => language,
|
9
|
-
'analysis' => analysis
|
10
|
-
'users' => users
|
9
|
+
'analysis' => analysis
|
11
10
|
}
|
12
11
|
end
|
13
12
|
|
14
13
|
let(:analysis) { nil }
|
15
14
|
|
16
15
|
describe '#new' do
|
17
|
-
let(:users) { [] }
|
18
16
|
context 'when language is british' do
|
19
17
|
let(:language) { 'en-gb' }
|
20
18
|
|
@@ -65,28 +63,29 @@ describe AlohaAnalyzer::User do
|
|
65
63
|
end
|
66
64
|
|
67
65
|
describe '#analyze' do
|
66
|
+
subject(:results) { described_class.new(options).analyze(users) }
|
68
67
|
context 'when no users' do
|
69
68
|
let(:users) { [] }
|
70
69
|
|
71
70
|
it 'returns a hash' do
|
72
|
-
subject.
|
71
|
+
subject.should be_a Hash
|
73
72
|
end
|
74
73
|
|
75
74
|
it 'includes the total count' do
|
76
|
-
subject
|
75
|
+
subject['count'].should eq 0
|
77
76
|
end
|
78
77
|
|
79
78
|
it 'has no results with the user language' do
|
80
|
-
subject
|
79
|
+
subject['account_language']['count'].should eq 0
|
81
80
|
end
|
82
81
|
|
83
82
|
it 'has no results without the user language' do
|
84
|
-
subject
|
85
|
-
subject
|
83
|
+
subject['foreign_languages'].should eq({})
|
84
|
+
subject['foreign_languages_count'].should eq 0
|
86
85
|
end
|
87
86
|
|
88
87
|
it 'includes the user lanugage' do
|
89
|
-
subject
|
88
|
+
subject['account_language']['language'].should eq(
|
90
89
|
'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
|
91
90
|
)
|
92
91
|
end
|
@@ -104,15 +103,15 @@ describe AlohaAnalyzer::User do
|
|
104
103
|
}
|
105
104
|
|
106
105
|
it 'returns a hash' do
|
107
|
-
subject.
|
106
|
+
subject.should be_a Hash
|
108
107
|
end
|
109
108
|
|
110
109
|
it 'includes the total count' do
|
111
|
-
subject
|
110
|
+
subject['count'].should eq 4
|
112
111
|
end
|
113
112
|
|
114
113
|
it 'includes the user lanugage' do
|
115
|
-
subject
|
114
|
+
subject['account_language'].should eq(
|
116
115
|
'count' => 2,
|
117
116
|
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
|
118
117
|
'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
|
@@ -120,11 +119,11 @@ describe AlohaAnalyzer::User do
|
|
120
119
|
end
|
121
120
|
|
122
121
|
it 'includs the foreign followers count' do
|
123
|
-
subject
|
122
|
+
subject['foreign_languages_count'].should eq 2
|
124
123
|
end
|
125
124
|
|
126
125
|
it 'returns results based on the user language' do
|
127
|
-
subject
|
126
|
+
subject['foreign_languages'].should == {
|
128
127
|
'fr' => {
|
129
128
|
'count' => 1,
|
130
129
|
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>14000000, 'countries'=>'France, Canada, Belgium, Switzerland'},
|
@@ -148,21 +147,21 @@ describe AlohaAnalyzer::User do
|
|
148
147
|
}
|
149
148
|
|
150
149
|
it 'returns a hash' do
|
151
|
-
subject.
|
150
|
+
subject.should be_a Hash
|
152
151
|
end
|
153
152
|
|
154
153
|
it 'includes the total count' do
|
155
|
-
subject
|
154
|
+
subject['count'].should eq 2
|
156
155
|
end
|
157
156
|
|
158
157
|
it 'includes the user lanugage' do
|
159
|
-
subject
|
158
|
+
subject['account_language']['language'].should eq(
|
160
159
|
'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
|
161
160
|
)
|
162
161
|
end
|
163
162
|
|
164
163
|
it 'returns results based on the user language' do
|
165
|
-
subject
|
164
|
+
subject['account_language'].should == {
|
166
165
|
'count' => 2,
|
167
166
|
'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries' => 'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
|
168
167
|
'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '2', 'lang' => 'en'}]
|
@@ -170,8 +169,8 @@ describe AlohaAnalyzer::User do
|
|
170
169
|
end
|
171
170
|
|
172
171
|
it 'returns results results based on the non user language' do
|
173
|
-
subject
|
174
|
-
subject
|
172
|
+
subject['foreign_languages'].should == {}
|
173
|
+
subject['foreign_languages_count'].should eq 0
|
175
174
|
end
|
176
175
|
end
|
177
176
|
|
@@ -185,15 +184,15 @@ describe AlohaAnalyzer::User do
|
|
185
184
|
}
|
186
185
|
|
187
186
|
it 'returns a hash' do
|
188
|
-
subject.
|
187
|
+
subject.should be_a Hash
|
189
188
|
end
|
190
189
|
|
191
190
|
it 'includes the total count' do
|
192
|
-
subject
|
191
|
+
subject['count'].should eq 3
|
193
192
|
end
|
194
193
|
|
195
194
|
it 'returns results based on the user language' do
|
196
|
-
subject
|
195
|
+
subject['account_language'].should == {
|
197
196
|
'count' => 0,
|
198
197
|
'language' => {'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
|
199
198
|
'users' => []
|
@@ -201,11 +200,11 @@ describe AlohaAnalyzer::User do
|
|
201
200
|
end
|
202
201
|
|
203
202
|
it 'includes the correct foreign_languages_count' do
|
204
|
-
subject
|
203
|
+
subject['foreign_languages_count'].should eq 3
|
205
204
|
end
|
206
205
|
|
207
206
|
it 'returns results results based on the non user language' do
|
208
|
-
subject
|
207
|
+
subject['foreign_languages'].should eq(
|
209
208
|
'fr' => {
|
210
209
|
'count' => 2,
|
211
210
|
'language' => { 'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland' },
|
@@ -230,11 +229,11 @@ describe AlohaAnalyzer::User do
|
|
230
229
|
}
|
231
230
|
|
232
231
|
it 'includes the total count' do
|
233
|
-
subject
|
232
|
+
subject['count'].should eq 3
|
234
233
|
end
|
235
234
|
|
236
235
|
it 'includes the user lanugage' do
|
237
|
-
subject
|
236
|
+
subject['account_language'].should == {
|
238
237
|
'count' => 2,
|
239
238
|
'language' => { 'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia' },
|
240
239
|
'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
|
@@ -242,11 +241,11 @@ describe AlohaAnalyzer::User do
|
|
242
241
|
end
|
243
242
|
|
244
243
|
it 'includes the correct foreign_languages_count' do
|
245
|
-
subject
|
244
|
+
subject['foreign_languages_count'].should eq 1
|
246
245
|
end
|
247
246
|
|
248
247
|
it 'merges english and british' do
|
249
|
-
subject
|
248
|
+
subject['foreign_languages'].should eq(
|
250
249
|
'fr' => {
|
251
250
|
'count' => 1,
|
252
251
|
'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
|
@@ -262,7 +261,6 @@ describe AlohaAnalyzer::User do
|
|
262
261
|
{
|
263
262
|
'language' => language,
|
264
263
|
'analysis' => analysis,
|
265
|
-
'users' => users,
|
266
264
|
'max_users' => 1
|
267
265
|
}
|
268
266
|
end
|
@@ -277,27 +275,27 @@ describe AlohaAnalyzer::User do
|
|
277
275
|
}
|
278
276
|
|
279
277
|
it 'limits the number of account language users to 1' do
|
280
|
-
subject
|
278
|
+
subject['account_language']['users'].size.should eq 1
|
281
279
|
end
|
282
280
|
|
283
281
|
it 'limits the number of foreign languages users to 1' do
|
284
|
-
subject
|
282
|
+
subject['foreign_languages']['fr']['users'].size.should eq 1
|
285
283
|
end
|
286
284
|
|
287
285
|
it 'does not affect the account language count' do
|
288
|
-
subject
|
286
|
+
subject['account_language']['count'].should eq 2
|
289
287
|
end
|
290
288
|
|
291
289
|
it 'does not affect the foreign_languages_count' do
|
292
|
-
subject
|
290
|
+
subject['foreign_languages_count'].should eq 3
|
293
291
|
end
|
294
292
|
|
295
293
|
it 'does not affect the total count' do
|
296
|
-
subject
|
294
|
+
subject['count'].should eq 5
|
297
295
|
end
|
298
296
|
|
299
297
|
it 'does not affect a foreign language count' do
|
300
|
-
subject
|
298
|
+
subject['foreign_languages']['fr']['count'].should eq 3
|
301
299
|
end
|
302
300
|
end
|
303
301
|
|
@@ -329,7 +327,7 @@ describe AlohaAnalyzer::User do
|
|
329
327
|
end
|
330
328
|
|
331
329
|
it 'starts from the existing analysis' do
|
332
|
-
subject.
|
330
|
+
subject.should eq(
|
333
331
|
'account_language' => {
|
334
332
|
'count' => 3,
|
335
333
|
'language' => {'abbreviation'=>'en', 'greeting'=>'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
|