Class: AnbtSql::Rule
- Inherits:
-
Object
- Object
- AnbtSql::Rule
- Includes:
- StringUtil
- Defined in:
- lib/anbt-sql-formatter/rule.rb
Constant Summary collapse
- KEYWORD_NONE =
キーワードの変換規則: 何もしない
0- KEYWORD_UPPER_CASE =
キーワードの変換規則: 大文字にする
1- KEYWORD_LOWER_CASE =
キーワードの変換規則: 小文字にする
2- ONELINE_IN_VALUES_NUM =
IN の値を一行表示する場合の in_values_num 値
0
Instance Attribute Summary collapse
-
#function_names ⇒ Object
Returns the value of attribute function_names.
-
#in_values_num ⇒ Object
Limit number of values per line in IN clause to this value.
-
#indent_string ⇒ Object
Returns the value of attribute indent_string.
-
#keyword ⇒ Object
Returns the value of attribute keyword.
-
#kw_minus1_indent_nl_x_plus1_indent ⇒ Object
Returns the value of attribute kw_minus1_indent_nl_x_plus1_indent.
-
#kw_multi_words ⇒ Object
Returns the value of attribute kw_multi_words.
-
#kw_nl_x ⇒ Object
Returns the value of attribute kw_nl_x.
-
#kw_nl_x_plus1_indent ⇒ Object
Returns the value of attribute kw_nl_x_plus1_indent.
-
#kw_plus1_indent_x_nl ⇒ Object
nl: New Line x: the keyword.
-
#space_after_comma ⇒ Object
Returns the value of attribute space_after_comma.
Instance Method Summary collapse
- #function?(name) ⇒ Boolean
-
#initialize ⇒ Rule
constructor
A new instance of Rule.
Methods included from StringUtil
Constructor Details
#initialize ⇒ Rule
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/anbt-sql-formatter/rule.rb', line 52 def initialize # キーワードの変換規則. @keyword = KEYWORD_UPPER_CASE # インデントの文字列. 設定は自由入力とする。 # 通常は " ", " ", "\t" のいずれか。 @indent_string = " " @space_after_comma = false # __foo # ____KW @kw_plus1_indent_x_nl = %w(INSERT INTO CREATE DROP TRUNCATE TABLE CASE) # ____foo # __KW # ____bar @kw_minus1_indent_nl_x_plus1_indent = %w(FROM WHERE SET HAVING) @kw_minus1_indent_nl_x_plus1_indent.concat ["ORDER BY", "GROUP BY"] # __foo # ____KW @kw_nl_x_plus1_indent = %w(ON USING) # __foo # __KW @kw_nl_x = %w(OR THEN ELSE) # @kw_nl_x = %w(OR WHEN ELSE) @kw_multi_words = ["ORDER BY", "GROUP BY"] # 関数の名前。 # Java版は初期値 null @function_names = [ # getNumericFunctions "ABS", "ACOS", "ASIN", "ATAN", "ATAN2", "BIT_COUNT", "CEILING", "COS", "COT", "DEGREES", "EXP", "FLOOR", "LOG", "LOG10", "MAX", "MIN", "MOD", "PI", "POW", "POWER", "RADIANS", "RAND", "ROUND", "SIN", "SQRT", "TAN", "TRUNCATE", # getStringFunctions "ASCII", "BIN", "BIT_LENGTH", "CHAR", "CHARACTER_LENGTH", "CHAR_LENGTH", "CONCAT", "CONCAT_WS", "CONV", "ELT", "EXPORT_SET", "FIELD", "FIND_IN_SET", "HEX,INSERT", "INSTR", "LCASE", "LEFT", "LENGTH", "LOAD_FILE", "LOCATE", "LOCATE", "LOWER", "LPAD", "LTRIM", "MAKE_SET", "MATCH", "MID", "OCT", "OCTET_LENGTH", "ORD", "POSITION", "QUOTE", "REPEAT", "REPLACE", "REVERSE", "RIGHT", "RPAD", "RTRIM", "SOUNDEX", "SPACE", "STRCMP", "SUBSTRING", "SUBSTRING", "SUBSTRING", "SUBSTRING", "SUBSTRING_INDEX", "TRIM", "UCASE", "UPPER", # getSystemFunctions "DATABASE", "USER", "SYSTEM_USER", "SESSION_USER", "PASSWORD", "ENCRYPT", "LAST_INSERT_ID", "VERSION", # getTimeDateFunctions "DAYOFWEEK", "WEEKDAY", "DAYOFMONTH", "DAYOFYEAR", "MONTH", "DAYNAME", "MONTHNAME", "QUARTER", "WEEK", "YEAR", "HOUR", "MINUTE", "SECOND", "PERIOD_ADD", "PERIOD_DIFF", "TO_DAYS", "FROM_DAYS", "DATE_FORMAT", "TIME_FORMAT", "CURDATE", "CURRENT_DATE", "CURTIME", "CURRENT_TIME", "NOW", "SYSDATE", "CURRENT_TIMESTAMP", "UNIX_TIMESTAMP", "FROM_UNIXTIME", "SEC_TO_TIME", "TIME_TO_SEC" ] end |
Instance Attribute Details
#function_names ⇒ Object
Returns the value of attribute function_names.
23 24 25 |
# File 'lib/anbt-sql-formatter/rule.rb', line 23 def function_names @function_names end |
#in_values_num ⇒ Object
Limit number of values per line in IN clause to this value.
- nil
-
one value per line (default)
- n (>=2)
-
n values per line
- ONELINE_IN_VALUES_NUM
-
all values in one line
38 39 40 |
# File 'lib/anbt-sql-formatter/rule.rb', line 38 def in_values_num @in_values_num end |
#indent_string ⇒ Object
Returns the value of attribute indent_string.
23 24 25 |
# File 'lib/anbt-sql-formatter/rule.rb', line 23 def indent_string @indent_string end |
#keyword ⇒ Object
Returns the value of attribute keyword.
23 24 25 |
# File 'lib/anbt-sql-formatter/rule.rb', line 23 def keyword @keyword end |
#kw_minus1_indent_nl_x_plus1_indent ⇒ Object
Returns the value of attribute kw_minus1_indent_nl_x_plus1_indent.
29 30 31 |
# File 'lib/anbt-sql-formatter/rule.rb', line 29 def kw_minus1_indent_nl_x_plus1_indent @kw_minus1_indent_nl_x_plus1_indent end |
#kw_multi_words ⇒ Object
Returns the value of attribute kw_multi_words.
24 25 26 |
# File 'lib/anbt-sql-formatter/rule.rb', line 24 def kw_multi_words @kw_multi_words end |
#kw_nl_x ⇒ Object
Returns the value of attribute kw_nl_x.
30 31 32 |
# File 'lib/anbt-sql-formatter/rule.rb', line 30 def kw_nl_x @kw_nl_x end |
#kw_nl_x_plus1_indent ⇒ Object
Returns the value of attribute kw_nl_x_plus1_indent.
31 32 33 |
# File 'lib/anbt-sql-formatter/rule.rb', line 31 def kw_nl_x_plus1_indent @kw_nl_x_plus1_indent end |
#kw_plus1_indent_x_nl ⇒ Object
nl: New Line x: the keyword
28 29 30 |
# File 'lib/anbt-sql-formatter/rule.rb', line 28 def kw_plus1_indent_x_nl @kw_plus1_indent_x_nl end |
#space_after_comma ⇒ Object
Returns the value of attribute space_after_comma.
23 24 25 |
# File 'lib/anbt-sql-formatter/rule.rb', line 23 def space_after_comma @space_after_comma end |
Instance Method Details
#function?(name) ⇒ Boolean
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/anbt-sql-formatter/rule.rb', line 117 def function?(name) if (@function_names == nil) return false end for i in 0...(@function_names.length) if (equals_ignore_case(@function_names[i], name)) return true end end return false end |