Class: SmqlToAR::ConditionTypes::Overlaps
- Defined in:
- lib/smql_to_ar/condition_types.rb
Overview
Every key-pair will be ORed. No multiple values possible.
Constant Summary collapse
- Expected =
[Range, lambda {|val| Array === val && 2 == val.length && [Time, Date, String].any? {|v|v===val[0]} && [Numeric, String].any? {|v|v===val[1]} }]
Constants inherited from Condition
Condition::Operator, Condition::Where
Instance Attribute Summary
Attributes inherited from Condition
Instance Method Summary collapse
-
#initialize(model, cols, val) ⇒ Overlaps
constructor
A new instance of Overlaps.
- #overlaps_build(builder, table) ⇒ Object (also: #build)
Methods inherited from Condition
#condition_build, inspect, #inspect, try_parse, #verify, #verify_allowed, #verify_column
Methods included from Assertion
Constructor Details
#initialize(model, cols, val) ⇒ Overlaps
Returns a new instance of Overlaps.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/smql_to_ar/condition_types.rb', line 215 def initialize model, cols, val if Array === val f = Time.parse( val[0]).localtime l = val[1] l = case l when String then Time.parse( l).localtime when Numeric then f+l else raise ArgumentError, "Unexpected type for end-value #{l.inspect}" end f += f.utc_offset l += l.utc_offset val = f.utc..l.utc end super model, cols, val end |
Instance Method Details
#overlaps_build(builder, table) ⇒ Object Also known as: build
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/smql_to_ar/condition_types.rb', line 231 def overlaps_build builder, table builder = Or.new builder builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end v1 = "TIMESTAMP #{v1}" v2 = "TIMESTAMP #{v2}" @cols.each do |col| col.joins builder, table end.each_slice 2 do |f,s| builder.where self.class::Where % [ builder.column( table+f.path, f.col), builder.column( table+s.path, s.col), v1, v2] end end |