Class: GtfsEngine::Calendar
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GtfsEngine::Calendar
- Defined in:
- app/models/gtfs_engine/calendar.rb
Class Method Summary collapse
-
.from_date_string(date) ⇒ ActiveRecord_Relation
This method will add/remove entries listed in CalendarDate and will also filter out entries which don’t match the correct day-of-week.
Class Method Details
.from_date_string(date) ⇒ ActiveRecord_Relation
This method will add/remove entries listed in CalendarDate and will also filter out entries which don’t match the correct day-of-week.
TODO: Currently, this method does 3 SQL queries. Try to lower this.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/gtfs_engine/calendar.rb', line 35 def from_date_string(date) dates = GtfsEngine::CalendarDate.where date: date add = dates.where(exception_type: 1).pluck :service_id query = if add.any? where '((start_date <= :date AND end_date >= :date) OR service_id IN (:ids)', date: date, ids: add else where '(start_date <= :date AND end_date >= :date)', date: date end query = where_day_of_week query, date rem = dates.where(exception_type: 2).pluck :service_id if rem.any? query.where '(service_id NOT IN (?))', rem else query end end |