Module: TranzitoUtils::SetPeriod
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/tranzito_utils/concerns/set_period.rb
Constant Summary collapse
- PERIOD_TYPES =
%w[hour day month year week all next_week next_month].freeze
Instance Method Summary collapse
- #controller_namespace ⇒ Object
-
#set_period ⇒ Object
For setting periods, particularly for graphing.
Instance Method Details
#controller_namespace ⇒ Object
12 13 14 |
# File 'lib/tranzito_utils/concerns/set_period.rb', line 12 def controller_namespace @controller_namespace ||= (self.class.module_parent.name != "Object") ? self.class.module_parent.name.downcase : nil end |
#set_period ⇒ Object
For setting periods, particularly for graphing
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tranzito_utils/concerns/set_period.rb', line 17 def set_period set_timezone # Set time period @period ||= params[:period] if @period == "custom" if params[:start_time].present? @start_time = TimeParser.parse(params[:start_time], @timezone) @end_time = TimeParser.parse(params[:end_time], @timezone) || Time.current @start_time, @end_time = @end_time, @start_time if @start_time > @end_time else set_time_range_from_period end elsif params[:search_at].present? @period = "custom" @search_at = TimeParser.parse(params[:search_at], @timezone) offset = params[:period].present? ? params[:period].to_i : 10.minutes.to_i @start_time = @search_at - offset @end_time = @search_at + offset else set_time_range_from_period end # Add this render_chart in here so we don't have to define it in all the controllers @render_chart = ActiveRecord::Type::Boolean.new.cast(params[:render_chart].to_s.strip) @time_range = @start_time..@end_time end |