Class: ErrorNormalizer::SchemaPathTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/error_normalizer/schema_path_translator.rb

Overview

Find I18n locale for the given path.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SchemaPathTranslator

Returns a new instance of SchemaPathTranslator.



8
9
10
11
# File 'lib/error_normalizer/schema_path_translator.rb', line 8

def initialize(path)
  @path = path
  @namespace = 'schemas' # TODO: make it configurable
end

Instance Method Details

#translateString

Take the path and try to translate each part of it. Given the path: “user.account.status” lookup path (and translation) will looks like:

schemas.user.@
schemas.user
user.@
user
+
schemas.user.account.@
schemas.user.account
schemas.account.@
schemas.account
account.@
account
+
schemas.user.account.status.@
schemas.user.account.status
schemas.status.@
schemas.status
status.@
status

Returns:

  • (String)

    translated path



37
38
39
40
41
42
43
44
45
46
# File 'lib/error_normalizer/schema_path_translator.rb', line 37

def translate
  tokens = @path.split('.')

  translated_tokens = []
  tokens.each.with_index do |token, i|
    translated_tokens << translate_token(token, i, tokens)
  end

  upcase_sentence(translated_tokens.join(' '))
end