aloha_analyzer 0.5.3 → 0.6.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: 06dab42fd8ef139daabd06a5587505684d75ba86
4
- data.tar.gz: 760700cff1546260101b5530cf0edd778d46dbd8
3
+ metadata.gz: 36b2f48d7da6a71e6ee989066f3ecdd0cf52415c
4
+ data.tar.gz: 13836892ac1a676e5c86e9115f0b638e88e7a2f6
5
5
  SHA512:
6
- metadata.gz: bec55fcc4fda67e5f079bee903329764f13c9dea95a73b81536aacee2251540068c855dfc133dd45e12efe8827dc5f01f3db2b315435cd87c9bcbf7f728ce872
7
- data.tar.gz: b619e0b67131637f5929bb5e0150fbb681b336193fc7b93ba7399c41606d0b831067e76047b73d3d46aab7a80f3ead2a70deb45c23915ce68f3a58ed547e4b94
6
+ metadata.gz: eea341593848177dd6e5aa52696f2fc0cddedf4ac7979075172ba9e4d1c76cc593c831a342b39d4b2043a4be5ace24324ddfa0784159dce95f95fd752b0df7e7
7
+ data.tar.gz: 248eec547e964eea2e6f603fae70343e4f88028a8c996495a71a9036cc63d1db05c9edb0834e4f82a08626b4191f3dba6a5dce7e656ea86ab6eac7d69a92da80
data/README.md CHANGED
@@ -16,13 +16,6 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install aloha_analyzer
18
18
 
19
- ## Usage
20
-
21
- ```ruby
22
- aloha = AlohaAnalyser::User.new(username, { credentials: credentials })
23
- aloha.analyze!
24
- ```
25
-
26
19
  ## Contributing
27
20
 
28
21
  1. Fork it
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency 'twitter_cldr', '~> 3.0'
21
+ spec.add_development_dependency 'twitter_cldr', '~> 3.0.0'
22
22
  spec.add_development_dependency 'bundler', '~> 1.3'
23
23
  spec.add_development_dependency 'rake', '~> 10.3'
24
- spec.add_development_dependency 'rspec', '~> 2.14'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
25
  spec.add_development_dependency 'byebug', '~> 3.1'
26
26
  end
@@ -1,6 +1,5 @@
1
1
  module AlohaAnalyzer
2
- class User
3
-
2
+ class Base
4
3
  attr_reader :language, :analysis
5
4
 
6
5
  def initialize(options)
@@ -11,7 +10,7 @@ module AlohaAnalyzer
11
10
 
12
11
  def analyze(users)
13
12
  clean_users(users).each do |user|
14
- if user['lang'] == @language
13
+ if user[language_key] == @language
15
14
  add_account_language_user(user)
16
15
  @analysis['account_language']['count'] += 1
17
16
  else
@@ -27,7 +26,7 @@ module AlohaAnalyzer
27
26
  {
28
27
  'account_language' => {
29
28
  'count' => 0,
30
- 'language' => Language.find_by_abbreviation(@language),
29
+ 'language' => Language.find_by_abbreviation(@language, network_name),
31
30
  'users' => []
32
31
  },
33
32
  'foreign_languages_count' => 0,
@@ -36,30 +35,29 @@ module AlohaAnalyzer
36
35
  }
37
36
  end
38
37
 
39
- private
40
-
41
- def add_account_language_user(user)
42
- unless too_many_users?(@analysis['account_language']['users'])
43
- @analysis['account_language']['users'].push(user)
38
+ def clean_language(language)
39
+ if Language.aliases.keys.include?(language)
40
+ Language.aliases[language]
41
+ else
42
+ language
44
43
  end
45
44
  end
46
45
 
47
- def add_foreign_language_user(user)
48
- prepare_foreign_language(user['lang'])
49
- @analysis['foreign_languages'][user['lang']]['count'] += 1
50
- unless too_many_users?(@analysis['foreign_languages'][user['lang']]['users'])
51
- @analysis['foreign_languages'][user['lang']]['users'].push(user)
46
+ def clean_users(users)
47
+ users.map do |user|
48
+ if Language.aliases.keys.include?(user[language_key].downcase)
49
+ user[language_key] = Language.aliases[user[language_key].downcase]
50
+ end
51
+ user
52
52
  end
53
53
  end
54
54
 
55
- def prepare_foreign_language(abbreviation)
56
- if @analysis['foreign_languages'][abbreviation].nil?
57
- @analysis['foreign_languages'][abbreviation] = {
58
- 'count' => 0,
59
- 'language' => Language.find_by_abbreviation(abbreviation),
60
- 'users' => []
61
- }
62
- end
55
+ def network_name
56
+ self.class.network_name
57
+ end
58
+
59
+ def language_key
60
+ self.class.language_key
63
61
  end
64
62
 
65
63
  def too_many_users?(users)
@@ -70,20 +68,27 @@ module AlohaAnalyzer
70
68
  end
71
69
  end
72
70
 
73
- def clean_language(language)
74
- if Language.aliases.keys.include?(language)
75
- Language.aliases[language]
76
- else
77
- language
71
+ def add_account_language_user(user)
72
+ unless too_many_users?(@analysis['account_language']['users'])
73
+ @analysis['account_language']['users'].push(user)
78
74
  end
79
75
  end
80
76
 
81
- def clean_users(users)
82
- users.map do |user|
83
- if Language.aliases.keys.include?(user['lang'].downcase)
84
- user['lang'] = Language.aliases[user['lang'].downcase]
85
- end
86
- user
77
+ def add_foreign_language_user(user)
78
+ prepare_foreign_language(user[language_key])
79
+ @analysis['foreign_languages'][user[language_key]]['count'] += 1
80
+ unless too_many_users?(@analysis['foreign_languages'][user[language_key]]['users'])
81
+ @analysis['foreign_languages'][user[language_key]]['users'].push(user)
82
+ end
83
+ end
84
+
85
+ def prepare_foreign_language(abbreviation)
86
+ if @analysis['foreign_languages'][abbreviation].nil?
87
+ @analysis['foreign_languages'][abbreviation] = {
88
+ 'count' => 0,
89
+ 'language' => Language.find_by_abbreviation(abbreviation, network_name),
90
+ 'users' => []
91
+ }
87
92
  end
88
93
  end
89
94
  end
@@ -0,0 +1,11 @@
1
+ module AlohaAnalyzer
2
+ class Facebook < Base
3
+ def self.network_name
4
+ 'facebook'
5
+ end
6
+
7
+ def self.language_key
8
+ 'locale'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ module AlohaAnalyzer
2
+ class FacebookPage < Base
3
+ def self.network_name
4
+ 'facebook'
5
+ end
6
+
7
+ def analyze(languages)
8
+ clean_languages(languages).each do |language_key, count|
9
+ if language_key == @language
10
+ @analysis['account_language']['count'] += count
11
+ else
12
+ add_foreign_language_user(language_key, count)
13
+ @analysis['foreign_languages_count'] += count
14
+ end
15
+ @analysis['count'] += count
16
+ end
17
+ @analysis
18
+ end
19
+
20
+ def add_foreign_language_user(abbreviation, count)
21
+ prepare_foreign_language(abbreviation)
22
+ @analysis['foreign_languages'][abbreviation]['count'] += count
23
+ end
24
+
25
+ def clean_languages(languages)
26
+ languages.each do |language_key, count|
27
+ if Language.aliases.keys.include?(language_key.downcase)
28
+ if languages[Language.aliases[language_key.downcase]]
29
+ languages[Language.aliases[language_key.downcase]] = languages[Language.aliases[language_key.downcase]] + count
30
+ languages.delete language_key
31
+ else
32
+ languages[Language.aliases[language_key.downcase]] = languages.delete language_key
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
@@ -14,11 +14,11 @@ module AlohaAnalyzer
14
14
  ALIASES['aliases']
15
15
  end
16
16
 
17
- def self.find_by_abbreviation(abbreviation)
17
+ def self.find_by_abbreviation(abbreviation, network)
18
18
  if LANGUAGES['languages'][abbreviation]
19
- format(LANGUAGES['languages'][abbreviation], :twitter)
19
+ format(LANGUAGES['languages'][abbreviation], network)
20
20
  else
21
- format(LANGUAGES['languages']['other'], :twitter)
21
+ format(LANGUAGES['languages']['other'], network)
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1,11 @@
1
+ module AlohaAnalyzer
2
+ class Twitter < Base
3
+ def self.network_name
4
+ 'twitter'
5
+ end
6
+
7
+ def self.language_key
8
+ 'lang'
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module AlohaAnalyzer
2
- VERSION = '0.5.3'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -52,89 +52,89 @@ aliases:
52
52
  'zh-hk': 'zh'
53
53
  'zh-tw': 'zh'
54
54
  'lolc': 'en'
55
- 'ar_AR': 'ar'
56
- 'bg_BG': 'bg'
57
- 'cs_CZ': 'cs'
58
- 'da_DK': 'da'
59
- 'de_DE': 'de'
60
- 'el_GR': 'el'
61
- 'en_GB': 'en'
62
- 'en_PI': 'en'
63
- 'en_UD': 'en'
64
- 'en_US': 'en'
65
- 'es_ES': 'es'
66
- 'es_LA': 'es'
67
- 'eu_ES': 'es'
68
- 'fi_FI': 'fi'
69
- 'fr_CA': 'fr'
70
- 'fr_FR': 'fr'
71
- 'ga_IE': 'en'
72
- 'he_IL': 'he'
73
- 'hi_IN': 'hi'
74
- 'hr_HR': 'hr'
75
- 'hu_HU': 'hu'
76
- 'id_ID': 'id'
77
- 'is_IS': 'is'
78
- 'it_IT': 'it'
79
- 'ja_JP': 'ja'
80
- 'jv_ID': 'id'
81
- 'km_KH': 'km'
82
- 'ko_KR': 'ko'
83
- 'lt_LT': 'lt'
84
- 'lv_LV': 'lv'
85
- 'mk_MK': 'mk'
86
- 'ml_IN': 'ms'
87
- 'ms_MY': 'ms'
88
- 'nb_NO': 'no'
89
- 'nl_NL': 'nl'
90
- 'nn_NO': 'no'
91
- 'pa_IN': 'hi'
92
- 'pl_PL': 'pl'
93
- 'pt_BR': 'pt'
94
- 'pt_PT': 'pt'
95
- 'ro_RO': 'ro'
96
- 'ru_RU': 'ru'
97
- 'sl_SI': 'sl'
98
- 'sr_RS': 'sr'
99
- 'sv_SE': 'sv'
100
- 'th_TH': 'th'
101
- 'tl_PH': 'fil'
102
- 'tr_TR': 'tr'
103
- 'uk_UA': 'uk'
104
- 'ur_PK': 'ur'
105
- 'vi_VN': 'vi'
106
- 'zh_CN': 'zh'
107
- 'zh_HK': 'zh'
108
- 'zh_TW': 'zh'
109
- # af_ZA: 'Afrikaans'
110
- # az_AZ: 'Azerbaijani'
111
- # be_BY: 'Belarusian'
112
- # bn_IN: 'Bengali'
113
- # bs_BA: 'Bosnian'
114
- # ca_ES: 'Catalan'
115
- # cx_PH: 'Cebuano'
116
- # cy_GB: 'Welsh'
117
- # eo_EO: 'Esperanto'
118
- # et_EE: 'Estonian'
119
- # fa_IR: 'Persian'
120
- # fb_LT: 'Leet Speak'
121
- # fo_FO: 'Faroese'
122
- # fy_NL: 'Frisian'
123
- # gl_ES: 'Galician'
124
- # gn_PY: 'Guarani'
125
- # hy_AM: 'Armenian'
126
- # ka_GE: 'Georgian'
127
- # kn_IN: 'Kannada'
128
- # ku_TR: 'Kurdish'
129
- # la_VA: 'Latin'
130
- # ne_NP: 'Nepali'
131
- # ps_AF: 'Pashto'
132
- # si_LK: 'Sinhala'
133
- # sk_SK: 'Slovak'
134
- # sq_AL: 'Albanian'
135
- # sw_KE: 'Swahili'
136
- # ta_IN: 'Tamil'
137
- # te_IN: 'Telugu'
55
+ 'ar_ar': 'ar'
56
+ 'bg_bg': 'bg'
57
+ 'cs_cz': 'cs'
58
+ 'da_dk': 'da'
59
+ 'de_de': 'de'
60
+ 'el_gr': 'el'
61
+ 'en_gb': 'en'
62
+ 'en_pi': 'en'
63
+ 'en_ud': 'en'
64
+ 'en_us': 'en'
65
+ 'es_es': 'es'
66
+ 'es_la': 'es'
67
+ 'eu_es': 'es'
68
+ 'fi_fi': 'fi'
69
+ 'fr_ca': 'fr'
70
+ 'fr_fr': 'fr'
71
+ 'ga_ie': 'en'
72
+ 'he_il': 'he'
73
+ 'hi_in': 'hi'
74
+ 'hr_hr': 'hr'
75
+ 'hu_hu': 'hu'
76
+ 'id_id': 'id'
77
+ 'is_is': 'is'
78
+ 'it_it': 'it'
79
+ 'ja_jp': 'ja'
80
+ 'jv_id': 'id'
81
+ 'km_kh': 'km'
82
+ 'ko_kr': 'ko'
83
+ 'lt_lt': 'lt'
84
+ 'lv_lv': 'lv'
85
+ 'mk_mk': 'mk'
86
+ 'ml_in': 'ms'
87
+ 'ms_my': 'ms'
88
+ 'nb_no': 'no'
89
+ 'nl_nl': 'nl'
90
+ 'nn_no': 'no'
91
+ 'pa_in': 'hi'
92
+ 'pl_pl': 'pl'
93
+ 'pt_br': 'pt'
94
+ 'pt_pt': 'pt'
95
+ 'ro_ro': 'ro'
96
+ 'ru_ru': 'ru'
97
+ 'sl_si': 'sl'
98
+ 'sr_rs': 'sr'
99
+ 'sv_se': 'sv'
100
+ 'th_th': 'th'
101
+ 'tl_ph': 'fil'
102
+ 'tr_tr': 'tr'
103
+ 'uk_ua': 'uk'
104
+ 'ur_pk': 'ur'
105
+ 'vi_vn': 'vi'
106
+ 'zh_cn': 'zh'
107
+ 'zh_hk': 'zh'
108
+ 'zh_tw': 'zh'
109
+ # af_za: 'afrikaans'
110
+ # az_az: 'azerbaijani'
111
+ # be_by: 'belarusian'
112
+ # bn_in: 'bengali'
113
+ # bs_ba: 'bosnian'
114
+ # ca_es: 'catalan'
115
+ # cx_ph: 'cebuano'
116
+ # cy_gb: 'welsh'
117
+ # eo_eo: 'esperanto'
118
+ # et_ee: 'estonian'
119
+ # fa_ir: 'persian'
120
+ # fb_lt: 'leet speak'
121
+ # fo_fo: 'faroese'
122
+ # fy_nl: 'frisian'
123
+ # gl_es: 'galician'
124
+ # gn_py: 'guarani'
125
+ # hy_am: 'armenian'
126
+ # ka_ge: 'georgian'
127
+ # kn_in: 'kannada'
128
+ # ku_tr: 'kurdish'
129
+ # la_va: 'latin'
130
+ # ne_np: 'nepali'
131
+ # ps_af: 'pashto'
132
+ # si_lk: 'sinhala'
133
+ # sk_sk: 'slovak'
134
+ # sq_al: 'albanian'
135
+ # sw_ke: 'swahili'
136
+ # ta_in: 'tamil'
137
+ # te_in: 'telugu'
138
138
  # 'aa': 'afar'
139
139
  # 'ab': 'abkhazian'
140
140
  # 'ach': 'acoli'
@@ -1,6 +1,9 @@
1
- require "aloha_analyzer/version"
2
- require "aloha_analyzer/language"
3
- require "aloha_analyzer/user"
1
+ require 'aloha_analyzer/version'
2
+ require 'aloha_analyzer/language'
3
+ require 'aloha_analyzer/base'
4
+ require 'aloha_analyzer/twitter'
5
+ require 'aloha_analyzer/facebook'
6
+ require 'aloha_analyzer/facebook_page'
4
7
 
5
8
  module AlohaAnalyzer
6
9
  end