Class: CloudSesame::Query::AST::RangeValue

Inherits:
Abstract::Value show all
Defined in:
lib/cloud_sesame/query/ast/range_value.rb

Constant Summary collapse

STRING_NUMBER =
Regexp.new(/^\d+(.\d+?)$/)

Constants inherited from Abstract::Value

Abstract::Value::DATETIME_FORMAT, Abstract::Value::DATE_FORMAT, Abstract::Value::DIGIT_FORMAT, Abstract::Value::RANGE_FORMAT, Abstract::Value::TIME_FORMAT

Instance Attribute Summary

Attributes inherited from Abstract::Value

#changed, #compiled, #value

Instance Method Summary collapse

Methods inherited from Abstract::Value

#compile, datetime?, numeric?, range?, string_date?, string_datetime?, string_numeric?, string_range?, string_time?

Constructor Details

#initialize(value = nil, type = nil) ⇒ RangeValue

Returns a new instance of RangeValue.



8
9
10
11
12
13
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 8

def initialize(value = nil, type = nil)
  self.value =  RangeValue.range?(value) ? build_from_range(value) :
                RangeValue.string_range?(value) ? build_from_string(value) :
                initialize_value
  self.parse type
end

Instance Method Details

#==(object) ⇒ Object



64
65
66
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 64

def ==(object)
  value == (object.is_a?(RangeValue) ? object : RangeValue.new(object, Value)).value
end

#beginObject



24
25
26
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 24

def begin
  value[1]
end

#endObject



28
29
30
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 28

def end
  value[2]
end

#gt(value) ⇒ Object



40
41
42
43
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 40

def gt(value)
  set_begin(value) if value
  return self
end

#gte(value) ⇒ Object



45
46
47
48
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 45

def gte(value)
  set_begin(value, '[') if value
  return self
end

#lower_boundObject



32
33
34
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 32

def lower_bound
  value[0]
end

#lt(value) ⇒ Object



50
51
52
53
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 50

def lt(value)
  set_end(value) if value
  return self
end

#lte(value) ⇒ Object



55
56
57
58
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 55

def lte(value)
  set_end(value, ']') if value
  return self
end

#parse(type) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 15

def parse(type)
  if type && type.respond_to?(:parse)
    @changed = true
    value[1] = type.parse(self.begin) unless self.begin.to_s.empty?
    value[2] = type.parse(self.end) unless self.end.to_s.empty?
  end
  return self
end

#to_sObject



60
61
62
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 60

def to_s
  compile
end

#upper_boundObject



36
37
38
# File 'lib/cloud_sesame/query/ast/range_value.rb', line 36

def upper_bound
  value[3]
end