aloha_analyzer 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f365ff8ea98aed30b293c506c024b2bd9cc6392e
4
- data.tar.gz: 41440c2ab6bad0ddb4b3473c7cd7dd4a58cd6715
3
+ metadata.gz: ef74babf1f476d54991db96d7037a33b4ae682f0
4
+ data.tar.gz: b35b6e264346d2ad56c9d5f7df1ba276905d9212
5
5
  SHA512:
6
- metadata.gz: 8f24982aee08a1063139ca71613aafcf5158c34a4a97a6078968e0038f115ef1ab92ad4e2a7bb46063707972943edbedfff02053c695ec2addadbd90996a3a5f
7
- data.tar.gz: 902e781c090f5ef1711bb645987645e629f0ffa7e81904286bf23a0223ede1f5c24c2131efe86df15ee1ce3cabd1765475c6ed17fbc4b40ec2c104b153e9bb3c
6
+ metadata.gz: 58fa95446a8e3d340f4b1a6320e2dc1690e683982c20be6134810a8a12459618cced954822d8f25ab7d6e4a2e490f3b30212048511b60b945d1f15af96677498
7
+ data.tar.gz: fc197b9e40eef6c933457720b3586ecf1a52196480f0032e1d2900c7225ecf1f9c9cf4346a68463918766b61f3f89cc01f082f9d0ae7e543e9d1ce5f12c536f7
@@ -3,12 +3,11 @@ module AlohaAnalyzer
3
3
 
4
4
  attr_reader :language, :analysis
5
5
 
6
- def initialize(language, users, options = {}, analysis = nil)
7
- @language = clean_language(language.downcase)
8
- @users = clean_users(users)
9
- @users_count = users.size
6
+ def initialize(options)
7
+ @language = clean_language(options['language'].downcase)
8
+ @users = clean_users(options['users'])
9
+ @analysis = options['analysis'] || boilerplate
10
10
  @options = options
11
- @analysis = analysis || boilerplate
12
11
  end
13
12
 
14
13
  def analyze
@@ -65,7 +64,7 @@ module AlohaAnalyzer
65
64
  end
66
65
 
67
66
  def too_many_users?(users)
68
- if @options['user_limit_per_language'] && users.size >= @options['user_limit_per_language']
67
+ if @options['max_users'] && users.size >= @options['max_users']
69
68
  true
70
69
  else
71
70
  false
@@ -1,3 +1,3 @@
1
1
  module AlohaAnalyzer
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,9 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AlohaAnalyzer::User do
4
- subject(:user) { described_class.new(language, users, options, analysis) }
4
+ subject(:user) { described_class.new(options) }
5
5
  let(:language) { 'en' }
6
- let(:options) { {} }
6
+ let(:options) do
7
+ {
8
+ 'language' => language,
9
+ 'analysis' => analysis,
10
+ 'users' => users
11
+ }
12
+ end
13
+
7
14
  let(:analysis) { nil }
8
15
 
9
16
  describe '#new' do
@@ -42,29 +49,28 @@ describe AlohaAnalyzer::User do
42
49
  end
43
50
 
44
51
  describe '#analyze' do
45
- subject(:analyze) { described_class.new(language, users, options, analysis).analyze }
46
52
  context 'when no users' do
47
53
  let(:users) { [] }
48
54
 
49
55
  it 'returns a hash' do
50
- subject.should be_a Hash
56
+ subject.analyze.should be_a Hash
51
57
  end
52
58
 
53
59
  it 'includes the total count' do
54
- subject['count'].should eq 0
60
+ subject.analyze['count'].should eq 0
55
61
  end
56
62
 
57
63
  it 'has no results with the user language' do
58
- subject['account_language']['count'].should eq 0
64
+ subject.analyze['account_language']['count'].should eq 0
59
65
  end
60
66
 
61
67
  it 'has no results without the user language' do
62
- subject['foreign_languages'].should eq({})
63
- subject['foreign_languages_count'].should eq 0
68
+ subject.analyze['foreign_languages'].should eq({})
69
+ subject.analyze['foreign_languages_count'].should eq 0
64
70
  end
65
71
 
66
72
  it 'includes the user lanugage' do
67
- subject['account_language']['language'].should eq(
73
+ subject.analyze['account_language']['language'].should eq(
68
74
  'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
69
75
  )
70
76
  end
@@ -82,15 +88,15 @@ describe AlohaAnalyzer::User do
82
88
  }
83
89
 
84
90
  it 'returns a hash' do
85
- subject.should be_a Hash
91
+ subject.analyze.should be_a Hash
86
92
  end
87
93
 
88
94
  it 'includes the total count' do
89
- subject['count'].should eq 4
95
+ subject.analyze['count'].should eq 4
90
96
  end
91
97
 
92
98
  it 'includes the user lanugage' do
93
- subject['account_language'].should eq(
99
+ subject.analyze['account_language'].should eq(
94
100
  'count' => 2,
95
101
  'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
96
102
  'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
@@ -98,11 +104,11 @@ describe AlohaAnalyzer::User do
98
104
  end
99
105
 
100
106
  it 'includs the foreign followers count' do
101
- subject['foreign_languages_count'].should eq 2
107
+ subject.analyze['foreign_languages_count'].should eq 2
102
108
  end
103
109
 
104
110
  it 'returns results based on the user language' do
105
- subject['foreign_languages'].should == {
111
+ subject.analyze['foreign_languages'].should == {
106
112
  'fr' => {
107
113
  'count' => 1,
108
114
  'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>14000000, 'countries'=>'France, Canada, Belgium, Switzerland'},
@@ -126,21 +132,21 @@ describe AlohaAnalyzer::User do
126
132
  }
127
133
 
128
134
  it 'returns a hash' do
129
- subject.should be_a Hash
135
+ subject.analyze.should be_a Hash
130
136
  end
131
137
 
132
138
  it 'includes the total count' do
133
- subject['count'].should eq 2
139
+ subject.analyze['count'].should eq 2
134
140
  end
135
141
 
136
142
  it 'includes the user lanugage' do
137
- subject['account_language']['language'].should eq(
143
+ subject.analyze['account_language']['language'].should eq(
138
144
  'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'
139
145
  )
140
146
  end
141
147
 
142
148
  it 'returns results based on the user language' do
143
- subject['account_language'].should == {
149
+ subject.analyze['account_language'].should == {
144
150
  'count' => 2,
145
151
  'language' => {'abbreviation'=>'en', 'name'=>'English', 'population'=>238000000, 'countries' => 'USA, UK, Canada, Ireland, Australia', 'greeting'=>'hello!'},
146
152
  'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '2', 'lang' => 'en'}]
@@ -148,8 +154,8 @@ describe AlohaAnalyzer::User do
148
154
  end
149
155
 
150
156
  it 'returns results results based on the non user language' do
151
- subject['foreign_languages'].should == {}
152
- subject['foreign_languages_count'].should eq 0
157
+ subject.analyze['foreign_languages'].should == {}
158
+ subject.analyze['foreign_languages_count'].should eq 0
153
159
  end
154
160
  end
155
161
 
@@ -163,15 +169,15 @@ describe AlohaAnalyzer::User do
163
169
  }
164
170
 
165
171
  it 'returns a hash' do
166
- subject.should be_a Hash
172
+ subject.analyze.should be_a Hash
167
173
  end
168
174
 
169
175
  it 'includes the total count' do
170
- subject['count'].should eq 3
176
+ subject.analyze['count'].should eq 3
171
177
  end
172
178
 
173
179
  it 'returns results based on the user language' do
174
- subject['account_language'].should == {
180
+ subject.analyze['account_language'].should == {
175
181
  'count' => 0,
176
182
  'language' => {'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
177
183
  'users' => []
@@ -179,11 +185,11 @@ describe AlohaAnalyzer::User do
179
185
  end
180
186
 
181
187
  it 'includes the correct foreign_languages_count' do
182
- subject['foreign_languages_count'].should eq 3
188
+ subject.analyze['foreign_languages_count'].should eq 3
183
189
  end
184
190
 
185
191
  it 'returns results results based on the non user language' do
186
- subject['foreign_languages'].should eq(
192
+ subject.analyze['foreign_languages'].should eq(
187
193
  'fr' => {
188
194
  'count' => 2,
189
195
  'language' => { 'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland' },
@@ -208,11 +214,11 @@ describe AlohaAnalyzer::User do
208
214
  }
209
215
 
210
216
  it 'includes the total count' do
211
- subject['count'].should eq 3
217
+ subject.analyze['count'].should eq 3
212
218
  end
213
219
 
214
220
  it 'includes the user lanugage' do
215
- subject['account_language'].should == {
221
+ subject.analyze['account_language'].should == {
216
222
  'count' => 2,
217
223
  'language' => { 'abbreviation'=>'en', 'greeting' => 'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia' },
218
224
  'users' => [{'id' => '1', 'lang' => 'en'}, {'id' => '3', 'lang' => 'en'}]
@@ -220,11 +226,11 @@ describe AlohaAnalyzer::User do
220
226
  end
221
227
 
222
228
  it 'includes the correct foreign_languages_count' do
223
- subject['foreign_languages_count'].should eq 1
229
+ subject.analyze['foreign_languages_count'].should eq 1
224
230
  end
225
231
 
226
232
  it 'merges english and british' do
227
- subject['foreign_languages'].should eq(
233
+ subject.analyze['foreign_languages'].should eq(
228
234
  'fr' => {
229
235
  'count' => 1,
230
236
  'language' => {'abbreviation'=>'fr', 'name'=>'French', 'greeting'=>'bonjour!', 'population'=>14000000, 'countries' => 'France, Canada, Belgium, Switzerland'},
@@ -236,7 +242,14 @@ describe AlohaAnalyzer::User do
236
242
  end
237
243
 
238
244
  context 'when user limit per language' do
239
- let(:options) { { 'user_limit_per_language' => 1} }
245
+ let(:options) do
246
+ {
247
+ 'language' => language,
248
+ 'analysis' => analysis,
249
+ 'users' => users,
250
+ 'max_users' => 1
251
+ }
252
+ end
240
253
  let(:users) {
241
254
  [
242
255
  {'id' => '1', 'lang' => 'en'},
@@ -247,11 +260,28 @@ describe AlohaAnalyzer::User do
247
260
  ]
248
261
  }
249
262
 
250
- it 'does not add more users per language' do
251
- subject['account_language']['users'].size.should eq 1
252
- subject['account_language']['count'].should eq 2
253
- subject['foreign_languages']['fr']['users'].size.should eq 1
254
- subject['foreign_languages']['fr']['count'].should eq 3
263
+ it 'limits the number of account language users to 1' do
264
+ subject.analyze['account_language']['users'].size.should eq 1
265
+ end
266
+
267
+ it 'limits the number of foreign languages users to 1' do
268
+ subject.analyze['foreign_languages']['fr']['users'].size.should eq 1
269
+ end
270
+
271
+ it 'does not affect the account language count' do
272
+ subject.analyze['account_language']['count'].should eq 2
273
+ end
274
+
275
+ it 'does not affect the foreign_languages_count' do
276
+ subject.analyze['foreign_languages_count'].should eq 3
277
+ end
278
+
279
+ it 'does not affect the total count' do
280
+ subject.analyze['count'].should eq 5
281
+ end
282
+
283
+ it 'does not affect a foreign language count' do
284
+ subject.analyze['foreign_languages']['fr']['count'].should eq 3
255
285
  end
256
286
  end
257
287
 
@@ -283,7 +313,7 @@ describe AlohaAnalyzer::User do
283
313
  end
284
314
 
285
315
  it 'starts from the existing analysis' do
286
- subject.should eq(
316
+ subject.analyze.should eq(
287
317
  'account_language' => {
288
318
  'count' => 3,
289
319
  'language' => {'abbreviation'=>'en', 'greeting'=>'hello!', 'name'=>'English', 'population'=>238000000, 'countries'=>'USA, UK, Canada, Ireland, Australia'},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aloha_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Aussaguel