Class: Repor::Dimensions::NumberDimension

Inherits:
BinDimension show all
Defined in:
lib/repor/dimensions/number_dimension.rb

Defined Under Namespace

Classes: Bin

Instance Attribute Summary

Attributes inherited from BaseDimension

#name, #opts, #report

Instance Method Summary collapse

Methods inherited from BinDimension

#bin_start, #domain, #filter, #filter_max, #filter_min, #filter_values, #group, #group_values, #max, #max_bins, #min

Methods inherited from BaseDimension

#expression, #extract_sql_value, #filter, #filter_values, #filtering?, #group, #group_values, #grouping?, #initialize, #null_order, #nulls_last?, #order, #order_expression, #params, #relate, #sort_desc?, #sort_order

Constructor Details

This class inherits a constructor from Repor::Dimensions::BaseDimension

Instance Method Details

#bin_widthObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/repor/dimensions/number_dimension.rb', line 18

def bin_width
  if params.key?(:bin_width)
    params[:bin_width].to_f
  elsif domain == 0
    1
  elsif params.key?(:bin_count)
    domain / params[:bin_count].to_f
  else
    default_bin_width
  end
end

#validate_params!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/repor/dimensions/number_dimension.rb', line 4

def validate_params!
  super

  if params.key?(:bin_width)
    unless Repor.numeric?(params[:bin_width])
      invalid_param!(:bin_width, "must be numeric")
    end

    unless params[:bin_width].to_f > 0
      invalid_param!(:bin_width, "must be greater than 0")
    end
  end
end