Class: ActiveReporter::Dimension::Number

Inherits:
Bin
  • Object
show all
Defined in:
lib/active_reporter/dimension/number.rb

Defined Under Namespace

Classes: Set

Constant Summary collapse

DEFAULT_BIN_COUNT =
10

Constants inherited from Bin

Bin::MAX_BINS

Instance Attribute Summary

Attributes inherited from Base

#name, #opts, #report

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_widthObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_reporter/dimension/number.rb', line 17

def bin_width
  case
  when params.key?(:bin_width)
    params[:bin_width].to_f
  when domain.zero?
    1
  when params.key?(:bin_count)
    domain / params[:bin_count].to_f
  else
    default_bin_width
  end
end

#validate_params!Object



8
9
10
11
12
13
14
15
# File 'lib/active_reporter/dimension/number.rb', line 8

def validate_params!
  super

  if params.key?(:bin_width)
    invalid_param!(:bin_width, 'must be numeric') unless ActiveReporter.numeric?(params[:bin_width])
    invalid_param!(:bin_width, 'must be greater than 0') unless params[:bin_width].to_f > 0
  end
end