Class: MHVAccountTypeService

Inherits:
Object
  • Object
show all
Defined in:
app/services/mhv_account_type_service.rb

Overview

Models logic pertaining to the verification and logging of MHV accounts

Constant Summary collapse

ELIGIBLE_DATA_CLASS_COUNT_TO_ACCOUNT_LEVEL =
{
  32 => 'Premium',
  18 => 'Advanced',
  16 => 'Basic'
}.freeze
DEFAULT_ACCOUNT_LEVEL =
'Unknown'
MHV_DOWN_MESSAGE =
'MHVAccountTypeService: could not fetch eligible data classes'
UNEXPECTED_DATA_CLASS_COUNT_MESSAGE =
'MHVAccountTypeService: eligible data class mapping inconsistency'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ MHVAccountTypeService

Returns a new instance of MHVAccountTypeService.



20
21
22
23
# File 'app/services/mhv_account_type_service.rb', line 20

def initialize(user)
  @user = user
  @eligible_data_classes = fetch_eligible_data_classes if mhv_account?
end

Instance Attribute Details

#eligible_data_classesObject (readonly)

Returns the value of attribute eligible_data_classes.



25
26
27
# File 'app/services/mhv_account_type_service.rb', line 25

def eligible_data_classes
  @eligible_data_classes
end

#userObject (readonly)

Returns the value of attribute user.



25
26
27
# File 'app/services/mhv_account_type_service.rb', line 25

def user
  @user
end

Instance Method Details

#account_type_known?Boolean

Returns is the user MHV account type known?.

Returns:

  • (Boolean)

    is the user MHV account type known?



58
59
60
# File 'app/services/mhv_account_type_service.rb', line 58

def 
  user.identity..present?
end

#mhv_account?Boolean

Returns does the user have an MHV correlation ID?.

Returns:

  • (Boolean)

    does the user have an MHV correlation ID?



51
52
53
# File 'app/services/mhv_account_type_service.rb', line 51

def mhv_account?
  user.mhv_correlation_id.present?
end

#mhv_account_typeNilClass, String

Retrieve the MHV account type

Returns:

  • (NilClass)

    if the account is not an MHV account

  • (String)

    if the account is an MHV account, returns the account type



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/mhv_account_type_service.rb', line 33

def 
  return nil unless mhv_account?

  if 
    user.identity.
  elsif eligible_data_classes.nil?
    'Error'
  else
    ELIGIBLE_DATA_CLASS_COUNT_TO_ACCOUNT_LEVEL.fetch(eligible_data_classes.size)
  end
rescue KeyError
  (UNEXPECTED_DATA_CLASS_COUNT_MESSAGE)
  DEFAULT_ACCOUNT_LEVEL
end