Module: ScaffoldParser::Scaffolders::XSD::Parser::Handlers::Utils

Included in:
ScaffoldParser::Scaffolders::XSD, AtMethod, Klass, ListMethod, Module, ProxyListMethod, SubmodelMethod, ModuleTemplate
Defined in:
lib/scaffold_parser/scaffolders/xsd/parser/handlers/utils.rb

Instance Method Summary collapse

Instance Method Details

#indent(lines_or_string) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/utils.rb', line 7

def indent(lines_or_string)
  if lines_or_string.is_a? Array
    lines_or_string.map { |line| indent_string(line) }
  else
    indent_string(lines_or_string)
  end
end

#indent_string(string) ⇒ Object



15
16
17
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/utils.rb', line 15

def indent_string(string)
  string == "\n" ? string : string.prepend('  ')
end

#single_quote(string) ⇒ Object



19
20
21
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/utils.rb', line 19

def single_quote(string)
  string.to_s.gsub('"', '\'')
end

#wrap_in_namespace(klass, namespace) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scaffold_parser/scaffolders/xsd/parser/handlers/utils.rb', line 23

def wrap_in_namespace(klass, namespace)
  return klass unless namespace

  lines = klass.lines
  indented = indent(lines)

  indented.unshift "module #{namespace}\n"
  indented << "\nend"

  indented.join
end