class Rescodegen::SwiftStringsGenerator
Public Instance Methods
generate(singular_keys, singular_values, plural_keys, plural_values)
click to toggle source
Calls superclass method
Rescodegen::StringsGenerator#generate
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 6 def generate(singular_keys, singular_values, plural_keys, plural_values) super(singular_keys, singular_values, plural_keys, plural_values) import_header("Foundation") start_struct("Strings") .add_singular_enum(singular_keys, singular_values) .add_plural_enum(plural_keys, plural_values) .close_brackets @output end
Protected Instance Methods
add_cases(keys, values)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 62 def add_cases(keys, values) ### a.zip(b) -> [ [ a[0], b[0] ], [ a[n], b[n] ] ] keys.zip(values).each do |i| indent @output += "case #{i[0]} = \"#{i[1]}\"" newline end newline end
add_line(line)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 95 def add_line(line) indent @output += "#{line}" newline end
add_plural_enum(keys, values)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 29 def add_plural_enum(keys, values) return self if keys.size == 0 newline .start_enum("Plural", "String") .add_cases(keys, values) .start_function("localizedString", "args: CVarArgType...", "String") .return_localized_plural_string .close_brackets close_brackets end
add_singular_enum(keys, values)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 18 def add_singular_enum(keys, values) return self if keys.size == 0 newline .start_enum("Singular", "String") .add_cases(keys, values) .start_computed_property("localizedString", "String") .return_localized_string .close_brackets .close_brackets end
import_header(name)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 45 def import_header(name) @output += "import #{name}" newline end
newline()
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 40 def newline @output += "\n" self end
return_localized_plural_string()
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 90 def return_localized_plural_string add_line "let localized = NSLocalizedString(rawValue, comment: \"\")" add_line "return String(format: localized, locale: NSLocale.currentLocale(), arguments: args)" end
return_localized_string()
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 78 def return_localized_string indent @output += "return NSLocalizedString(rawValue, comment: \"\")" newline end
start_computed_property(name, type)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 72 def start_computed_property(name, type) indent @output += "var #{name}: #{type}" open_brackets end
start_enum(name, type)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 56 def start_enum(name, type) indent @output += "enum #{name}: #{type}" open_brackets end
start_function(name, parameter_list, return_type)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 84 def start_function(name, parameter_list, return_type) indent @output += "func #{name}(#{parameter_list}) -> #{return_type}" open_brackets end
start_struct(name)
click to toggle source
# File lib/rescodegen/code_generator/swift_strings_generator.rb, line 50 def start_struct(name) newline @output += "struct #{name}" open_brackets end