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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/gtfs_engine/calendar.rb', line 22 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 |