Module: PolyglotIos::Helper::General
- Included in:
- Command::Projects, Command::Pull, Command::Setup, Resource::Language, Serializer::Source::TranslationCase, Serializer::Source::TranslationEnum
- Defined in:
- lib/ios_polyglot_cli/helpers/general.rb
Constant Summary collapse
- ESCAPE_KEYWORDS =
["associatedtype", "class", "deinit", "enum", "extension", "fileprivate", "func", "import", "init", "inout", "internal", "let", "operator", "private", "protocol", "public", "static", "struct", "subscript", "typealias", "var", "break", "case", "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard", "if", "in", "repeat", "return", "switch", "where", "while", "as", "Any", "catch", "false", "is", "nil", "rethrows", "super", "self", "Self", "throw", "throws", "true", "try", "_"]
Instance Method Summary collapse
- #clean_case_name(name) ⇒ Object
- #clean_enum_name(name) ⇒ Object
- #clean_variable_name(name) ⇒ Object
- #config ⇒ Object
- #escape_keyword_if_needed(name) ⇒ Object
- #escape_with_underscore_if_needed(name) ⇒ Object
- #indent(level = 0, initial = "") ⇒ Object
- #programming_language ⇒ Object
- #project_configs ⇒ Object
- #token ⇒ Object
- #use_old_naming ⇒ Object
Instance Method Details
#clean_case_name(name) ⇒ Object
51 52 53 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 51 def clean_case_name(name) clean_variable_name(name) end |
#clean_enum_name(name) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 41 def clean_enum_name(name) clean_name = name .split(/[^0-9a-zA-Z]/) .reject { |c| c.empty? } .map { |value| value.capitalize } .join escape_with_underscore_if_needed(clean_name) end |
#clean_variable_name(name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 55 def clean_variable_name(name) clean_name = name .split(/[^0-9a-zA-Z]/) .reject { |c| c.empty? } .each_with_index .map { |value, index| index == 0 ? value.downcase : value.capitalize } .join escaped_underscore = escape_with_underscore_if_needed(clean_name) escape_keyword_if_needed(escaped_underscore) end |
#config ⇒ Object
19 20 21 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 19 def config @config ||= PolyglotIos::IO::Config.read.with_indifferent_access end |
#escape_keyword_if_needed(name) ⇒ Object
72 73 74 75 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 72 def escape_keyword_if_needed(name) return name if !ESCAPE_KEYWORDS.include? name "`#{name}`" end |
#escape_with_underscore_if_needed(name) ⇒ Object
67 68 69 70 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 67 def escape_with_underscore_if_needed(name) return name if name.match(/^[A-Za-z_]/) "_" + name end |
#indent(level = 0, initial = "") ⇒ Object
35 36 37 38 39 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 35 def indent(level = 0, initial = "") (1..level) .to_a.reduce("") { |result, value| result + " " } .concat(initial) end |
#programming_language ⇒ Object
27 28 29 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 27 def programming_language @programming_language ||= config[:language] end |
#project_configs ⇒ Object
23 24 25 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 23 def project_configs @project_configs ||= config[:projects] end |
#token ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 10 def token @token ||= PolyglotIos::IO::Token.read if @token.to_s.empty? PolyglotIos::Command::Login.init @token = PolyglotIos::IO::Token.read end @token end |
#use_old_naming ⇒ Object
31 32 33 |
# File 'lib/ios_polyglot_cli/helpers/general.rb', line 31 def use_old_naming @useOldNaming ||= config[:useOldNaming] end |