class Rescodegen::StringsGenerator

Public Instance Methods

generate(singular_keys, singular_values, plural_keys, plural_values) click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 5
def generate(singular_keys, singular_values, plural_keys, plural_values)
    raise "Expects keys and values of equal sizes" if singular_keys.size != singular_values.size || plural_keys.size != plural_values.size
    raise "Expects at least one key and one value" if singular_keys.size == 0 && plural_keys.size == 0
    @output = ""
    @tab_level = 0
end

Protected Instance Methods

close_brackets() click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 29
def close_brackets
    decrement_indent_level
    indent
    @output += "}"
    newline
end
decrement_indent_level() click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 41
def decrement_indent_level
    @tab_level -= 1
    self
end
increment_indent_level() click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 36
def increment_indent_level
    @tab_level += 1
    self
end
indent() click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 46
def indent
    @output += (1..@tab_level).reduce("") { |a, b| a + tab }
    self
end
newline() click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 18
def newline
    @output += "\n"
    self
end
open_brackets() click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 23
def open_brackets
    @output += " {"
    newline
    increment_indent_level
end
prefix(string) click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 14
def prefix(string)
    @prefix + string
end
tab() click to toggle source
# File lib/rescodegen/code_generator/strings_generator.rb, line 51
def tab
    "    "
end