Sha256: 18422c8e2e470c965bb25bd2b2d3b1799fa86b98c8f98d969486e98e416b8323

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module CloudSesame
  module Query
    module AST
      class Value < Abstract::Value

        TYPES = {
          string: StringValue,
          numeric: NumericValue,
          date: DateValue
        }

        def self.map_type(symbol)
          (klass =TYPES[symbol]) ? klass : self
        end

        # if the value is already a range value object
        # set the type to Value and return the value
        # else determine the type of value and create it
        def self.parse(value)
          if value.kind_of?(RangeValue)
            value.type = self
            return value
          end

          (
            range_value?(value) ? RangeValue :
            numeric_value?(value) ? NumericValue :
            datetime?(value) ? DateValue : StringValue
          ).new(value, self)

        end

        def self.range_value?(value)
          range?(value) || string_range?(value)
        end

        def self.numeric_value?(value)
          numeric?(value) || string_numeric?(value)
        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
CloudSesame-0.7.4 lib/cloud_sesame/query/ast/value.rb
CloudSesame-0.7.3 lib/cloud_sesame/query/ast/value.rb
CloudSesame-0.7.2 lib/cloud_sesame/query/ast/value.rb
CloudSesame-0.7.1 lib/cloud_sesame/query/ast/value.rb
CloudSesame-0.7.0 lib/cloud_sesame/query/ast/value.rb