Sha256: 770c8d13403c03208ca702264939e2f3ff620b4fedc0a8388a629f4380d4860c
Contents?: true
Size: 1.33 KB
Versions: 18
Compression:
Stored size: 1.33 KB
Contents
module CloudSesame module Query module AST class Value RANGE_FORMAT = /\A(\[|{)(.*),(.*)(\}|\])\z/ DIGIT_FORMAT = /\A\d+(.\d+)?\z/ SINGLE_QUATE = /\'/ ESCAPE_QUATE = "\\'" attr_reader :data def self.parse(value) return value if value.kind_of? AST::Value return AST::NumericValue.new(value) if value.is_a?(Numeric) || (value.is_a?(String) && DIGIT_FORMAT =~ value) return AST::DateValue.new(value) if value.kind_of?(Date) || value.kind_of?(Time) return AST::RangeValue.new(value) if value.kind_of?(Range) || (value.is_a?(String) && RANGE_FORMAT =~ value) AST::Value.new(value) end def initialize(data) @data = data end def compile updated? ? recompile : @compiled end def to_s compile end def ==(value) value == data || value == compile end private def updated? @compiled_data != @data end def recompile @compiled_data = @data @compiled = escape @compiled_data end def escape(data) "'#{ data.gsub(SINGLE_QUATE) { ESCAPE_QUATE } }'" end def strip(string) string.tr(" ", "") end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems