class SearchCopGrammar::Attributes::Datetime
Public Instance Methods
between(range)
click to toggle source
# File lib/search_cop_grammar/attributes.rb, line 257 def between(range) gteq(range.first).and(lteq(range.last)) end
eq(value)
click to toggle source
# File lib/search_cop_grammar/attributes.rb, line 245 def eq(value) between parse(value) end
gt(value)
click to toggle source
Calls superclass method
# File lib/search_cop_grammar/attributes.rb, line 253 def gt(value) super parse(value).last end
map(value)
click to toggle source
# File lib/search_cop_grammar/attributes.rb, line 241 def map(value) parse(value).first end
not_eq(value)
click to toggle source
# File lib/search_cop_grammar/attributes.rb, line 249 def not_eq(value) between(parse(value)).not end
parse(value)
click to toggle source
# File lib/search_cop_grammar/attributes.rb, line 215 def parse(value) return value..value unless value.is_a?(::String) if value =~ /^[0-9]+ (hour|day|week|month|year)s{0,1} (ago)$/ number, period, ago = value.split(" ") time = number.to_i.send(period.to_sym).send(ago.to_sym) time..::Time.now elsif value =~ /^[0-9]{4}$/ ::Time.new(value).beginning_of_year..::Time.new(value).end_of_year elsif value =~ %r{^([0-9]{4})(\.|-|/)([0-9]{1,2})$} ::Time.new(Regexp.last_match(1), Regexp.last_match(3), 15).beginning_of_month..::Time.new(Regexp.last_match(1), Regexp.last_match(3), 15).end_of_month elsif value =~ %r{^([0-9]{1,2})(\.|-|/)([0-9]{4})$} ::Time.new(Regexp.last_match(3), Regexp.last_match(1), 15).beginning_of_month..::Time.new(Regexp.last_match(3), Regexp.last_match(1), 15).end_of_month elsif value =~ %r{^[0-9]{4}(\.|-|/)[0-9]{1,2}(\.|-|/)[0-9]{1,2}$} || value =~ %r{^[0-9]{1,2}(\.|-|/)[0-9]{1,2}(\.|-|/)[0-9]{4}$} time = ::Time.parse(value) time.beginning_of_day..time.end_of_day elsif value =~ %r{[0-9]{4}(\.|-|/)[0-9]{1,2}(\.|-|/)[0-9]{1,2}} || value =~ %r{[0-9]{1,2}(\.|-|/)[0-9]{1,2}(\.|-|/)[0-9]{4}} time = ::Time.parse(value) time..time else raise ArgumentError end rescue ArgumentError raise SearchCop::IncompatibleDatatype, "Incompatible datatype for #{value}" end