aloha_analyzer 0.1.9 → 0.2.0
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 +53 -31
- data/lib/aloha_analyzer/version.rb +1 -1
- data/spec/aloha_analyzer/user_spec.rb +23 -2
- 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: c390df22ade9fd5d5fa60f666546be93d834bb9a
|
4
|
+
data.tar.gz: 1ca0491eed0055d5fecb8797926d4e81b9f1bf9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de8a6d1dcbca9b2d4b4b3c6f89bc6b82ee9d97c2d71c57e4a7dfacea77afd9b16a972a882f384ce0b902b935462ddf5c1b351a55e8c05bcfad47a3e8dfb1b35a
|
7
|
+
data.tar.gz: 12158be8ccded5051441322d8e2dcf5253f5e181c9977bb38a6dde54c335dc39e81f0f9f8affba9170a087666e2bffa33a9a120e076409af7374c1a1a242eec1
|
data/lib/aloha_analyzer/user.rb
CHANGED
@@ -3,52 +3,74 @@ module AlohaAnalyzer
|
|
3
3
|
|
4
4
|
attr_reader :language
|
5
5
|
|
6
|
-
def initialize(language, users)
|
6
|
+
def initialize(language, users, options = {})
|
7
7
|
@language = language.downcase
|
8
8
|
@users = users
|
9
9
|
@users_count = users.size
|
10
|
+
@options = options
|
11
|
+
@analysis = {}
|
12
|
+
|
10
13
|
clean_language!
|
11
14
|
clean_users_languages!
|
12
15
|
end
|
13
16
|
|
14
17
|
def analyze
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
analysys[:foreign_languages][abbreviation][:count] += 1
|
24
|
-
analysys[:foreign_languages][abbreviation][:users].push user
|
25
|
-
else
|
26
|
-
analysys[:foreign_languages][abbreviation] = {
|
27
|
-
:count => 1,
|
28
|
-
:language => Language.find_by_abbreviation(abbreviation),
|
29
|
-
:users => [user]
|
30
|
-
}
|
31
|
-
end
|
32
|
-
analysys[:foreign_languages_count] += 1
|
33
|
-
end
|
34
|
-
analysys[:count] += 1
|
18
|
+
prepare!
|
19
|
+
@users.each do |user|
|
20
|
+
if user['lang'] == @language
|
21
|
+
add_account_language_user(user)
|
22
|
+
@analysis[:account_language][:count] += 1
|
23
|
+
else
|
24
|
+
add_foreign_language_user(user)
|
25
|
+
@analysis[:foreign_languages_count] += 1
|
35
26
|
end
|
27
|
+
@analysis[:count] += 1
|
36
28
|
end
|
29
|
+
@analysis
|
37
30
|
end
|
38
31
|
|
39
|
-
|
40
32
|
private
|
41
33
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
def add_account_language_user(user)
|
35
|
+
unless too_many_users?(@analysis[:account_language][:users])
|
36
|
+
@analysis[:account_language][:users].push(user)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_foreign_language_user(user)
|
41
|
+
prepare_foreign_language(user['lang'])
|
42
|
+
@analysis[:foreign_languages][user['lang']][:count] += 1
|
43
|
+
unless too_many_users?(@analysis[:foreign_languages][user['lang']][:users])
|
44
|
+
@analysis[:foreign_languages][user['lang']][:users].push(user)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def prepare_foreign_language(abbreviation)
|
49
|
+
if @analysis[:foreign_languages][abbreviation].nil?
|
50
|
+
@analysis[:foreign_languages][abbreviation] = {
|
51
|
+
:count => 0,
|
52
|
+
:language => Language.find_by_abbreviation(abbreviation),
|
53
|
+
:users => []
|
48
54
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def prepare!
|
59
|
+
@analysis[:account_language] = {
|
60
|
+
count: 0,
|
61
|
+
language: Language.find_by_abbreviation(@language),
|
62
|
+
users: []
|
63
|
+
}
|
64
|
+
@analysis[:foreign_languages_count] = 0
|
65
|
+
@analysis[:count] = 0
|
66
|
+
@analysis[:foreign_languages] = Hash.new
|
67
|
+
end
|
68
|
+
|
69
|
+
def too_many_users?(users)
|
70
|
+
if @options[:user_limit_per_language] && users.size >= @options[:user_limit_per_language]
|
71
|
+
true
|
72
|
+
else
|
73
|
+
false
|
52
74
|
end
|
53
75
|
end
|
54
76
|
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AlohaAnalyzer::User do
|
4
|
-
subject(:user) { described_class.new(language, users) }
|
4
|
+
subject(:user) { described_class.new(language, users, options) }
|
5
5
|
let(:language) { 'en' }
|
6
|
+
let(:options) { {} }
|
6
7
|
|
7
8
|
describe '#new' do
|
8
9
|
let(:users) { [] }
|
@@ -40,7 +41,7 @@ describe AlohaAnalyzer::User do
|
|
40
41
|
end
|
41
42
|
|
42
43
|
describe '#analyze' do
|
43
|
-
subject(:analyze) { described_class.new(language, users).analyze }
|
44
|
+
subject(:analyze) { described_class.new(language, users, options).analyze }
|
44
45
|
context 'when no users' do
|
45
46
|
let(:users) { [] }
|
46
47
|
|
@@ -232,5 +233,25 @@ describe AlohaAnalyzer::User do
|
|
232
233
|
end
|
233
234
|
end
|
234
235
|
end
|
236
|
+
|
237
|
+
context 'when user limit per language' do
|
238
|
+
let(:options) { { user_limit_per_language: 1} }
|
239
|
+
let(:users) {
|
240
|
+
[
|
241
|
+
{'id' => '1', 'lang' => 'en'},
|
242
|
+
{'id' => '2', 'lang' => 'fr'},
|
243
|
+
{'id' => '3', 'lang' => 'en'},
|
244
|
+
{'id' => '4', 'lang' => 'fr'},
|
245
|
+
{'id' => '5', 'lang' => 'fr'}
|
246
|
+
]
|
247
|
+
}
|
248
|
+
|
249
|
+
it 'does not add more users per language' do
|
250
|
+
subject[:account_language][:users].size.should eq 1
|
251
|
+
subject[:account_language][:count].should eq 2
|
252
|
+
subject[:foreign_languages]['fr'][:users].size.should eq 1
|
253
|
+
subject[:foreign_languages]['fr'][:count].should eq 3
|
254
|
+
end
|
255
|
+
end
|
235
256
|
end
|
236
257
|
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.
|
4
|
+
version: 0.2.0
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|