Class: ManagerStringBase

Inherits:
ManagerBase show all
Defined in:
lib/mrpin/core/string/manager_string_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ManagerBase

#cleanup_data, #load_init_data, #on_data_loaded, #on_server_maintenance_on, #on_server_shutdown, #on_server_started, #post_init, #start_tasks

Constructor Details

#initialize(options = nil) ⇒ ManagerStringBase

default constructor



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mrpin/core/string/manager_string_base.rb', line 21

def initialize(options = nil)
  super(options)

  @supported_languages = ELanguageType.values_list.map(&:to_sym)

  @languages_priority = [ELanguageType::ELT_ENGLISH, ELanguageType::ELT_RUSSIAN]

  @class_localization = get_class_by_name(CLASS_MAP[EClassType::ECT_LOCALIZATION])

  #key - language, value - {key - string_key, value - string}
  @string_map         = {}

  @localization_keys_list = []

  @responses_map = {}
end

Instance Attribute Details

#languages_priorityObject (readonly)

Returns the value of attribute languages_priority.



9
10
11
# File 'lib/mrpin/core/string/manager_string_base.rb', line 9

def languages_priority
  @languages_priority
end

#localization_keys_listObject (readonly)

Properties



7
8
9
# File 'lib/mrpin/core/string/manager_string_base.rb', line 7

def localization_keys_list
  @localization_keys_list
end

#supported_languagesObject (readonly)

Returns the value of attribute supported_languages.



8
9
10
# File 'lib/mrpin/core/string/manager_string_base.rb', line 8

def supported_languages
  @supported_languages
end

Instance Method Details

#get_alphabet_for(language) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/mrpin/core/string/manager_string_base.rb', line 126

def get_alphabet_for(language)
  result = nil

  language_map = @string_map[language.to_sym]

  unless language_map.nil?
    result = language_map[EStringTypeBase::EST_ALPHABET]
  end

  result
end

#get_localization_base_mapObject



12
13
14
# File 'lib/mrpin/core/string/manager_string_base.rb', line 12

def get_localization_base_map
  {}
end

#get_localization_response_for(language) ⇒ Object



110
111
112
# File 'lib/mrpin/core/string/manager_string_base.rb', line 110

def get_localization_response_for(language)
  @responses_map[language.to_sym] || @responses_map[ELanguageType::ELT_ENGLISH.to_sym] || {}
end

#get_string_languages(key) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/mrpin/core/string/manager_string_base.rb', line 115

def get_string_languages(key)
  result = []

  @string_map.each do |language, keys_map|
    result << language.to_s unless keys_map[key.to_sym].nil?
  end

  result
end

#invalidate_cacheObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mrpin/core/string/manager_string_base.rb', line 39

def invalidate_cache
  super

  localization_base = get_localization_base_map

  string_map = localization_base.deep_dup

  localizations = @class_localization.all.to_a

  @supported_languages.each do |language|
    string_map[language] ||= {}
  end

  localizations.each do |localization_item|

    key = localization_item[:key].to_sym

    @supported_languages.each do |language|

      texts = localization_item[language]

      unless texts.nil? || texts.empty?
        string_map[language][key] = texts
      end

    end

  end

  localization_keys_list = []

  string_map.each do |language, keys_map|
    localization_keys_list |= keys_map.keys.map(&:to_s)
  end

  @string_map             = string_map
  @localization_keys_list = localization_keys_list

  update_responses_map
end

#localized_string(key, language) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/mrpin/core/string/manager_string_base.rb', line 95

def localized_string(key, language)
  keys_map = @string_map[language.to_sym]

  return nil if keys_map.nil?

  result = keys_map[key.to_sym]

  if result.is_a? (Array)
    result = result.sample
  end

  result
end