Module: SqlBeautifier::Util
- Defined in:
- lib/sql_beautifier/util.rb
Class Method Summary collapse
- .continuation_padding ⇒ Object
- .double_quote_string(value) ⇒ Object
- .escape_double_quote(value) ⇒ Object
- .first_word(text) ⇒ Object
- .format_keyword(keyword) ⇒ Object
- .format_table_name(name) ⇒ Object
- .keyword_padding(keyword) ⇒ Object
- .strip_outer_parentheses(text) ⇒ Object
- .upper_pascal_case(name) ⇒ Object
- .whitespace(length) ⇒ Object
Class Method Details
.continuation_padding ⇒ Object
45 46 47 |
# File 'lib/sql_beautifier/util.rb', line 45 def continuation_padding whitespace(SqlBeautifier.config_for(:keyword_column_width)) end |
.double_quote_string(value) ⇒ Object
26 27 28 29 30 |
# File 'lib/sql_beautifier/util.rb', line 26 def double_quote_string(value) return if value.nil? "#{Constants::DOUBLE_QUOTE}#{value}#{Constants::DOUBLE_QUOTE}" end |
.escape_double_quote(value) ⇒ Object
32 33 34 35 36 |
# File 'lib/sql_beautifier/util.rb', line 32 def escape_double_quote(value) return if value.nil? value.gsub(Constants::DOUBLE_QUOTE, Constants::ESCAPED_DOUBLE_QUOTE) end |
.first_word(text) ⇒ Object
15 16 17 |
# File 'lib/sql_beautifier/util.rb', line 15 def first_word(text) text.strip.split(Constants::WHITESPACE_REGEX).first end |
.format_keyword(keyword) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/sql_beautifier/util.rb', line 49 def format_keyword(keyword) case SqlBeautifier.config_for(:keyword_case) when :upper keyword.upcase else keyword.downcase end end |
.format_table_name(name) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/sql_beautifier/util.rb', line 58 def format_table_name(name) case SqlBeautifier.config_for(:table_name_format) when :lowercase name.downcase else upper_pascal_case(name) end end |
.keyword_padding(keyword) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/sql_beautifier/util.rb', line 38 def keyword_padding(keyword) formatted_keyword = format_keyword(keyword) padding_width = [SqlBeautifier.config_for(:keyword_column_width) - formatted_keyword.length, 1].max "#{formatted_keyword}#{whitespace(padding_width)}" end |
.strip_outer_parentheses(text) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/sql_beautifier/util.rb', line 19 def strip_outer_parentheses(text) stripped_text = text.strip return stripped_text unless stripped_text.start_with?(Constants::OPEN_PARENTHESIS) && stripped_text.end_with?(Constants::CLOSE_PARENTHESIS) stripped_text[1...-1].strip end |
.upper_pascal_case(name) ⇒ Object
11 12 13 |
# File 'lib/sql_beautifier/util.rb', line 11 def upper_pascal_case(name) name.split("_").map(&:capitalize).join("_") end |
.whitespace(length) ⇒ Object
7 8 9 |
# File 'lib/sql_beautifier/util.rb', line 7 def whitespace(length) " " * length end |