Class: AlohaAnalyzer::User

Inherits:
Object
  • Object
show all
Defined in:
lib/aloha_analyzer/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ User

Returns a new instance of User.



6
7
8
9
10
# File 'lib/aloha_analyzer/user.rb', line 6

def initialize(options)
  @language = clean_language(options['language'].downcase)
  @analysis = (options['analysis'] || boilerplate).clone
  @options  = options
end

Instance Attribute Details

#analysisObject (readonly)

Returns the value of attribute analysis.



4
5
6
# File 'lib/aloha_analyzer/user.rb', line 4

def analysis
  @analysis
end

#languageObject (readonly)

Returns the value of attribute language.



4
5
6
# File 'lib/aloha_analyzer/user.rb', line 4

def language
  @language
end

Instance Method Details

#analyze(users) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/aloha_analyzer/user.rb', line 12

def analyze(users)
  clean_users(users).each do |user|
    if user['lang'] == @language
      (user)
      @analysis['account_language']['count'] += 1
    else
      add_foreign_language_user(user)
      @analysis['foreign_languages_count'] += 1
    end
    @analysis['count'] += 1
  end
  @analysis
end

#boilerplateObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aloha_analyzer/user.rb', line 26

def boilerplate
  {
    'account_language' => {
      'count'    => 0,
      'language' => Language.find_by_abbreviation(@language),
      'users'    => []
    },
    'foreign_languages_count' => 0,
    'count'                   => 0,
    'foreign_languages'       => {}
  }
end