Module: Mkxms::Mssql::Utils

Defined in:
lib/mkxms/mssql/utils.rb

Defined Under Namespace

Modules: FlagsQueries, InitializedAttributes, SchemaQualifiedName Classes: NameRefGraph

Constant Summary collapse

INVALID_NAME_CHAR =
/[^A-Za-z0-9_]/

Class Method Summary collapse

Class Method Details

.chars_to_tab(prev, tab_width: 4) ⇒ Object



69
70
71
# File 'lib/mkxms/mssql/utils.rb', line 69

def chars_to_tab(prev, tab_width: 4)
  (prev.chars.length + 3) % 4 + 1
end

.code_sym_for(s) ⇒ Object



56
57
58
# File 'lib/mkxms/mssql/utils.rb', line 56

def code_sym_for(s)
  s.gsub(self::INVALID_NAME_CHAR, '_').downcase.to_sym
end

.expand_tabs(s, tab_width: 4) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/mkxms/mssql/utils.rb', line 73

def expand_tabs(s, tab_width: 4)
  return s unless s.include? "\t"
  
  s.each_line.map do |l|
    while l.include? "\t"
      l.sub!("\t") {|m| ' ' * chars_to_tab($`, tab_width: tab_width)}
    end
    l
  end.join('')
end

.newline_prefixed(s) ⇒ Object



65
66
67
# File 'lib/mkxms/mssql/utils.rb', line 65

def newline_prefixed(s)
  "\n" + s
end

.unquoted_name(s) ⇒ Object



60
61
62
63
# File 'lib/mkxms/mssql/utils.rb', line 60

def unquoted_name(s)
  return s unless s[0] == '[' && s[-1] == ']'
  return s[1...-1].gsub(']]', ']')
end