af83/chouette-core

View on GitHub
app/lib/query/time_table.rb

Summary

Maintainability
A
35 mins
Test Coverage
# frozen_string_literal: true

module Query
  class TimeTable < Base
    def comment(value)
      change_scope(if: value.present?) do |scope|
        table = scope.arel_table

        comment = table[:comment].matches("%#{value}%")
        objectid = table[:objectid].matches("%#{value}%")

        scope.where(comment.or(objectid))
      end
    end

    def in_period(period)
      change_scope(if: period.present?) do |scope|
        scope.where('daterange(start_date, end_date) && ? OR (start_date IS NULL AND end_date IS NULL)', period.to_postgresql_daterange)
      end
    end
  end
end