Class: SearchCopGrammar::Attributes::Datetime
Instance Attribute Summary
Attributes inherited from Base
#attribute, #column_name, #options, #table_alias
Instance Method Summary
collapse
#matches
Methods inherited from Base
#compatible?, #fulltext?, #initialize, #method_missing, #respond_to?
Instance Method Details
#between(range) ⇒ Object
214
215
216
|
# File 'lib/search_cop_grammar/attributes.rb', line 214
def between(range)
gteq(range.first).and(lteq(range.last))
end
|
#eq(value) ⇒ Object
202
203
204
|
# File 'lib/search_cop_grammar/attributes.rb', line 202
def eq(value)
between parse(value)
end
|
#gt(value) ⇒ Object
210
211
212
|
# File 'lib/search_cop_grammar/attributes.rb', line 210
def gt(value)
super parse(value).last
end
|
#map(value) ⇒ Object
198
199
200
|
# File 'lib/search_cop_grammar/attributes.rb', line 198
def map(value)
parse(value).first
end
|
#not_eq(value) ⇒ Object
206
207
208
|
# File 'lib/search_cop_grammar/attributes.rb', line 206
def not_eq(value)
between(parse(value)).not
end
|
#parse(value) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/search_cop_grammar/attributes.rb', line 178
def parse(value)
return value .. value unless value.is_a?(::String)
if value =~ /^[0-9]{4,}$/
::Time.new(value).beginning_of_year .. ::Time.new(value).end_of_year
elsif value =~ /^([0-9]{4,})(\.|-|\/)([0-9]{1,2})$/
::Time.new($1, $3, 15).beginning_of_month .. ::Time.new($1, $3, 15).end_of_month
elsif value =~ /^([0-9]{1,2})(\.|-|\/)([0-9]{4,})$/
::Time.new($3, $1, 15).beginning_of_month .. ::Time.new($3, $1, 15).end_of_month
elsif value !~ /:/
time = ::Time.parse(value)
time.beginning_of_day .. time.end_of_day
else
time = ::Time.parse(value)
time .. time
end
rescue ArgumentError
raise SearchCop::IncompatibleDatatype, "Incompatible datatype for #{value}"
end
|