Class: Terrestrial::Cli::VariableNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/terrestrial/cli/variable_normalizer.rb

Class Method Summary collapse

Class Method Details

.format_string(target_string) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/terrestrial/cli/variable_normalizer.rb', line 22

def self.format_string(target_string)
  formatted_string = target_string
  regex = /\%@/
  index = 1
  while formatted_string.scan(regex).any?
    formatted_string = formatted_string.sub(regex, "%#{index}$@")
    index += 1
  end
  formatted_string
end

.format_swift_string(target_string) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/terrestrial/cli/variable_normalizer.rb', line 11

def self.format_swift_string(target_string)
  formatted_string = target_string
  regex = /\\\(.*?\)/
  index = 1
  while formatted_string.scan(regex).any?
    formatted_string = formatted_string.sub(regex, "%#{index}$@")
    index += 1
  end
  formatted_string
end

.run(string, swift: false) ⇒ Object



5
6
7
8
9
# File 'lib/terrestrial/cli/variable_normalizer.rb', line 5

def self.run(string, swift: false)
  result = string
  result = format_swift_string(result) if swift
  result = format_string(result)
end