Class: AttrSearchableGrammar::Attributes::Datetime
Instance Attribute Summary
Attributes inherited from Base
#attribute, #options
Instance Method Summary
collapse
#matches
Methods inherited from Base
#compatible?, #fulltext?, #initialize, #method_missing, #respond_to?
Instance Method Details
#between(range) ⇒ Object
189
190
191
|
# File 'lib/attr_searchable_grammar/attributes.rb', line 189
def between(range)
gteq(range.first).and(lteq(range.last))
end
|
#eq(value) ⇒ Object
177
178
179
|
# File 'lib/attr_searchable_grammar/attributes.rb', line 177
def eq(value)
between parse(value)
end
|
#gt(value) ⇒ Object
185
186
187
|
# File 'lib/attr_searchable_grammar/attributes.rb', line 185
def gt(value)
super parse(value).last
end
|
#map(value) ⇒ Object
173
174
175
|
# File 'lib/attr_searchable_grammar/attributes.rb', line 173
def map(value)
parse(value).first
end
|
#not_eq(value) ⇒ Object
181
182
183
|
# File 'lib/attr_searchable_grammar/attributes.rb', line 181
def not_eq(value)
between(parse(value)).not
end
|
#parse(value) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/attr_searchable_grammar/attributes.rb', line 153
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 AttrSearchable::IncompatibleDatatype, "Incompatible datatype for #{value}"
end
|