Class: DrivetimeBand

Inherits:
ApplicationRecord show all
Defined in:
app/models/drivetime_band.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Class Method Details

.find_within_max_distance(lat, lng, drive_time, ids) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/drivetime_band.rb', line 7

def find_within_max_distance(lat, lng, drive_time, ids)
  query = 'max <= :max AND ST_Intersects(polygon, ST_MakePoint(:lng,:lat))'
  params = { lng:, lat:, max: drive_time }

  if ids.present?
    query = "#{query} AND vha_facility_id IN (:ids)"
    params[:ids] = ids
  end

  DrivetimeBand.select(:name, :id, :vha_facility_id, :unit, :min, :max)
               .where(query, params)
end