Class: Workarea::Search::DateFilter
- Inherits:
-
Filter
- Object
- Filter
- Workarea::Search::DateFilter
show all
- Defined in:
- app/queries/workarea/search/date_filter.rb
Instance Attribute Summary
Attributes inherited from Filter
#name, #options, #search
Instance Method Summary
collapse
Methods inherited from Filter
#current_value, #display_name, #initialize, #params_for, #selected?, #useless?, #valid_params
Instance Method Details
#greater_than? ⇒ Boolean
29
30
31
|
# File 'app/queries/workarea/search/date_filter.rb', line 29
def greater_than?
%w(gt gte).include?(options.to_s)
end
|
#less_than? ⇒ Boolean
25
26
27
|
# File 'app/queries/workarea/search/date_filter.rb', line 25
def less_than?
%w(lt lte).include?(options.to_s)
end
|
#query_clause ⇒ Object
4
5
6
7
|
# File 'app/queries/workarea/search/date_filter.rb', line 4
def query_clause
return {} unless current_value.present?
{ range: { name => { options => query_value.to_s(:iso8601) } } }
end
|
#query_value ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/queries/workarea/search/date_filter.rb', line 9
def query_value
result = Time.zone.parse(current_value.to_s)
if greater_than? && !time_specified?
result.beginning_of_day
elsif less_than? && !time_specified?
result.end_of_day
else
result
end
end
|
#system_name ⇒ Object
21
22
23
|
# File 'app/queries/workarea/search/date_filter.rb', line 21
def system_name
@system_name ||= name + suffix
end
|
#time_specified? ⇒ Boolean
33
34
35
36
|
# File 'app/queries/workarea/search/date_filter.rb', line 33
def time_specified?
parsed = Time.zone.parse(current_value.to_s)
parsed != parsed.beginning_of_day
end
|