class AlgebraDB::SyntaxBuilder
Class that builds syntax.
Public Class Methods
new(params = [])
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 5 def initialize(params = []) @params = params @syntax = +'' end
Public Instance Methods
param(param)
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 19 def param(param) text "$#{@params.length + 1}" @params << param end
params()
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 50 def params @params.map(&:dup) end
parenthesize() { |self| ... }
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 37 def parenthesize raise ArgumentError, 'need a block' unless block_given? text_nospace('(') yield self @syntax.strip! text(')') end
separate(listish, separator: ',') { |e, self| ... }
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 24 def separate(listish, separator: ',') raise ArgumentError, 'need a block' unless block_given? len = listish.length listish.each.with_index do |e, i| yield e, self unless (i + 1) == len @syntax.strip! text(separator) end end end
syntax()
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 46 def syntax @syntax.dup end
text(str)
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 10 def text(str) @syntax << str @syntax << ' ' end
text_nospace(str)
click to toggle source
# File lib/algebra_db/syntax_builder.rb, line 15 def text_nospace(str) @syntax << str end