Class: ClickHouse::Ast::Statement
- Inherits:
-
Object
- Object
- ClickHouse::Ast::Statement
- Defined in:
- lib/click_house/ast/statement.rb
Constant Summary collapse
- PLACEHOLDER_S =
'%s'
- PLACEHOLDER_D =
'%d'
- DIGIT_RE =
/\A\d+\Z/.freeze
Instance Attribute Summary collapse
-
#caster ⇒ Object
Returns the value of attribute caster.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_argument(st) ⇒ Object
- #argument! ⇒ Object
- #argument_first! ⇒ Object
-
#argument_values ⇒ Array
cached argument values to increase the casting perfomance.
- #arguments ⇒ Array<Statement>
- #buffer? ⇒ Boolean
- #digit? ⇒ Boolean
-
#initialize(name: '') ⇒ Statement
constructor
A new instance of Statement.
- #merge(other) ⇒ Object
- #name! ⇒ Object
- #named? ⇒ Boolean
- #placeholder ⇒ Object
- #print(value) ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(name: '') ⇒ Statement
Returns a new instance of Statement.
15 16 17 18 |
# File 'lib/click_house/ast/statement.rb', line 15 def initialize(name: '') @buffer = '' @name = name end |
Instance Attribute Details
#caster ⇒ Object
Returns the value of attribute caster.
13 14 15 |
# File 'lib/click_house/ast/statement.rb', line 13 def caster @caster end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/click_house/ast/statement.rb', line 12 def name @name end |
Instance Method Details
#add_argument(st) ⇒ Object
36 37 38 |
# File 'lib/click_house/ast/statement.rb', line 36 def add_argument(st) arguments.push(st) end |
#argument! ⇒ Object
30 31 32 33 |
# File 'lib/click_house/ast/statement.rb', line 30 def argument! add_argument(Statement.new(name: @buffer)) @buffer = '' end |
#argument_first! ⇒ Object
68 69 70 71 |
# File 'lib/click_house/ast/statement.rb', line 68 def argument_first! # TODO: raise an error if multiple arguments @argument_first ||= arguments.first end |
#argument_values ⇒ Array
cached argument values to increase the casting perfomance
64 65 66 |
# File 'lib/click_house/ast/statement.rb', line 64 def argument_values @argument_values ||= arguments.map(&:value) end |
#arguments ⇒ Array<Statement>
58 59 60 |
# File 'lib/click_house/ast/statement.rb', line 58 def arguments @arguments ||= [] end |
#buffer? ⇒ Boolean
53 54 55 |
# File 'lib/click_house/ast/statement.rb', line 53 def buffer? !@buffer.empty? end |
#digit? ⇒ Boolean
79 80 81 |
# File 'lib/click_house/ast/statement.rb', line 79 def digit? name.match?(DIGIT_RE) end |
#merge(other) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/click_house/ast/statement.rb', line 41 def merge(other) if other.named? add_argument(other) else @arguments = arguments.concat(other.arguments) end end |
#name! ⇒ Object
25 26 27 28 |
# File 'lib/click_house/ast/statement.rb', line 25 def name! @name = @buffer @buffer = '' end |
#named? ⇒ Boolean
49 50 51 |
# File 'lib/click_house/ast/statement.rb', line 49 def named? !@name.empty? end |
#placeholder ⇒ Object
73 74 75 76 77 |
# File 'lib/click_house/ast/statement.rb', line 73 def placeholder return @placeholder if defined?(@placeholder) @placeholder = digit? ? PLACEHOLDER_D : PLACEHOLDER_S end |
#print(value) ⇒ Object
21 22 23 |
# File 'lib/click_house/ast/statement.rb', line 21 def print(value) @buffer = "#{@buffer}#{value}" end |
#to_s ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/click_house/ast/statement.rb', line 96 def to_s out = StringIO.new out.print(name.empty? ? 'NO_NAME' : name) out.print("<#{@buffer}>") unless @buffer.empty? if arguments.any? out.print("(#{arguments.join(',')})") end out.string end |
#value ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/click_house/ast/statement.rb', line 83 def value @value ||= case placeholder when PLACEHOLDER_D Integer(name) when PLACEHOLDER_S # remove leading and trailing quotes name[1..-2] else raise "unknown value extractor for <#{placeholder}>" end end |