Class: PolyglotIos::Serializer::Source::TranslationCase

Inherits:
Object
  • Object
show all
Includes:
Helper::General
Defined in:
lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb

Constant Summary

Constants included from Helper::General

Helper::General::ESCAPE_KEYWORDS

Instance Attribute Summary collapse

Instance Method Summary collapse

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, value, translation = nil) ⇒ TranslationCase

Returns a new instance of TranslationCase.



11
12
13
14
15
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb', line 11

def initialize(name, value, translation = nil)
  @name = name
  @value = value
  @translation = translation
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb', line 7

def name
  @name
end

#translationObject

Returns the value of attribute translation.



9
10
11
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb', line 9

def translation
  @translation
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb', line 8

def value
  @value
end

Instance Method Details

#format_translation_as_comment(translation) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb', line 29

def format_translation_as_comment(translation)
  lines = translation.lines
  lines.each_with_index.map do |line, index|
    if index == 0
      "/// Value: #{line.chomp}"
    else
      "\t/// #{line.chomp}"
    end
  end.join("\n")
end

#serializedObject



17
18
19
20
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb', line 17

def serialized()
  clean_name = clean_case_name(name)
  "public static let #{clean_name}: Strings = \"#{value}\""
end

#serializedDefaultTranslationObject



22
23
24
25
26
27
# File 'lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb', line 22

def serializedDefaultTranslation()
  if !translation.nil?
    return format_translation_as_comment(translation)
  end
  return ""
end