Class: ErrorNormalizer::SchemaPathTranslator
- Inherits:
-
Object
- Object
- ErrorNormalizer::SchemaPathTranslator
- Defined in:
- lib/error_normalizer/schema_path_translator.rb
Overview
Find I18n locale for the given path.
Instance Method Summary collapse
-
#initialize(path) ⇒ SchemaPathTranslator
constructor
A new instance of SchemaPathTranslator.
-
#translate ⇒ String
Take the path and try to translate each part of it.
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
#translate ⇒ String
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
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 |