Class: ActiveReporter::Dimension::Time
- Defined in:
- lib/active_reporter/dimension/time.rb
Defined Under Namespace
Classes: Set
Constant Summary collapse
- STEPS =
%i(seconds minutes hours days weeks months years)
- BIN_STEPS =
(STEPS - [:seconds]).map { |step| step.to_s.singularize(:_gem_active_reporter) }
- DURATION_PATTERN =
/\A\d+ (?:#{STEPS.map{ |step| "#{step}?" }.join('|')})\z/
Constants inherited from Bin
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Bin
#domain, #filter, #filter_max, #filter_min, #filter_values, #group, #group_values, #max, #max_bins, #min
Methods inherited from Base
#attribute, #expression, #extract_sql_value, #filter, #filter_values, #filtering?, #group, #group_values, #grouping?, #initialize, #model, #null_order, #nulls_last?, #order, #order_expression, #params, #relate, #sort_desc?, #sort_order
Constructor Details
This class inherits a constructor from ActiveReporter::Dimension::Base
Instance Method Details
#bin_start ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_reporter/dimension/time.rb', line 28 def bin_start # ensure that each autogenerated bin represents a correctly aligned # day/week/month/year bin_start = super return if bin_start.nil? step = BIN_STEPS.detect { |step| bin_width == 1.send(step) } step.present? ? bin_start.send(:"beginning_of_#{step}") : bin_start end |
#bin_width ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_reporter/dimension/time.rb', line 17 def bin_width @bin_width ||= case when params.key?(:bin_width) custom_bin_width when params.key?(:bin_count) && domain > 0 (domain / params[:bin_count].to_f).seconds else default_bin_width end end |
#validate_params! ⇒ Object
11 12 13 14 15 |
# File 'lib/active_reporter/dimension/time.rb', line 11 def validate_params! super invalid_param!(:bin_width, "must be a valid width value or a hash where each hash keys is a valid value and each hash value\n is interger representing the count of the key width\n valid :bin_width values include #{STEPS.to_sentence}.") if params.key?(:bin_width) && !valid_duration?(params[:bin_width]) end |