Class: PolyglotIos::Serializer::Source::TranslationEnum
- Inherits:
-
Object
- Object
- PolyglotIos::Serializer::Source::TranslationEnum
- Includes:
- Helper::General
- Defined in:
- lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb
Constant Summary
Constants included from Helper::General
Helper::General::ESCAPE_KEYWORDS
Instance Attribute Summary collapse
-
#child_enums ⇒ Object
Returns the value of attribute child_enums.
-
#name ⇒ Object
Returns the value of attribute name.
-
#translations ⇒ Object
Returns the value of attribute translations.
Instance Method Summary collapse
-
#initialize(name) ⇒ TranslationEnum
constructor
A new instance of TranslationEnum.
- #insert(components, key_name, translation) ⇒ Object
- #serialized(indent_level = 0) ⇒ Object
Methods included from Helper::General
#clean_case_name, #clean_enum_name, #clean_variable_name, #config, #escape_keyword_if_needed, #escape_with_underscore_if_needed, #indent, #programming_language, #project_configs, #skip_writing_language_struct, #token, #token_env_variable, #url, #use_old_naming
Methods included from Helper::Terminal
#generate_token_message, #prompt, #success
Constructor Details
#initialize(name) ⇒ TranslationEnum
Returns a new instance of TranslationEnum.
12 13 14 15 16 |
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb', line 12 def initialize(name) @name = name @translations = [] @child_enums = [] end |
Instance Attribute Details
#child_enums ⇒ Object
Returns the value of attribute child_enums.
10 11 12 |
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb', line 10 def child_enums @child_enums end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb', line 8 def name @name end |
#translations ⇒ Object
Returns the value of attribute translations.
9 10 11 |
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb', line 9 def translations @translations end |
Instance Method Details
#insert(components, key_name, translation) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb', line 18 def insert(components, key_name, translation) if components.count > 1 insert_to_nested_enum(components, key_name, translation) elsif components.count == 1 translation_case = TranslationCase.new(components.first, key_name, translation) translations.push(translation_case) end end |
#serialized(indent_level = 0) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb', line 27 def serialized(indent_level = 0) output = indent(indent_level) clean_name = clean_enum_name(name) if indent_level == 0 # the root object should be an extension and not be public to avoid warnings output.concat("extension #{clean_name} {\n") else output.concat("public enum #{clean_name} {\n") end translations .sort_by { |translation| translation.name.downcase } .each do |translation| output .concat(indent(indent_level + 1, translation.serializedDefaultTranslation())) .concat("\n") .concat(indent(indent_level + 1, translation.serialized())) .concat("\n") end if translations.count > 0 && child_enums.count > 0 output.concat("\n") end serialized_enums = child_enums .sort_by { |child_enum| child_enum.name.downcase } .map { |child_enum| child_enum.serialized(indent_level + 1) } .join("\n") output.concat(serialized_enums) output.concat(indent(indent_level, "}\n")) return output end |