Module: DateParser

Included in:
SearchQuery
Defined in:
app/parsers/date_parser.rb

Instance Method Summary collapse

Instance Method Details

#handle_empty_dates(date, default) ⇒ Object

Use default for empty dates



26
27
28
# File 'app/parsers/date_parser.rb', line 26

def handle_empty_dates(date, default)
  date && !date.empty? ? parse_date(date) : default
end

#parse_date(date) ⇒ Object

Convert date into appropriate format for elasticsearch



31
32
33
34
# File 'app/parsers/date_parser.rb', line 31

def parse_date(date)
  parseddate = date.split("/")
  return "#{parseddate[2]}-#{parseddate[0]}-#{parseddate[1]}"
end

#process_date_paramsObject

Process parameters for date query into form needed for build_search_query



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/parsers/date_parser.rb', line 3

def process_date_params
  startrange, endrange, fieldname, dataspec = ""

  # Get the sart and end of range vals
  @params.each do |key, value|
    if key.include?("startrange_")
      startrange = @params[key]
      fieldname, dataspec = get_date_index(key)
    elsif key.include?("endrange_")
      endrange = @params[key]
      fieldname, dataspec = get_date_index(key)
    end
  end
 
  # Return dataspec and date info
  return dataspec, {
    field: fieldname,
    start_date: handle_empty_dates(startrange, "0001-01-01"),
    end_date: handle_empty_dates(endrange, Time.now)
  }
end