Class: Cubicle::BucketizedDimension

Inherits:
Dimension show all
Defined in:
lib/cubicle/bucketized_dimension.rb

Instance Attribute Summary collapse

Attributes inherited from Member

#alias_list, #condition, #expression_type, #field_name, #name, #options

Instance Method Summary collapse

Methods inherited from Member

#included_in?, #matches, #to_js_keys, #to_js_value

Constructor Details

#initialize(dimension_name, measure, bucket_range, options = {}, &block) ⇒ BucketizedDimension

Returns a new instance of BucketizedDimension.



7
8
9
10
11
12
13
14
15
# File 'lib/cubicle/bucketized_dimension.rb', line 7

def initialize(dimension_name, measure, bucket_range, options={}, &block)
  super(dimension_name, options)
  @measure = measure
  @bucket_range = bucket_range
  @formatter = block
  @step = options(:bucket_size, :step) || 1
  @bump = options(:range_start_bump, :bump) || 1
  self.expression_type = :javascript
end

Instance Attribute Details

#bucket_rangeObject

Returns the value of attribute bucket_range.



5
6
7
# File 'lib/cubicle/bucketized_dimension.rb', line 5

def bucket_range
  @bucket_range
end

#bumpObject

Returns the value of attribute bump.



5
6
7
# File 'lib/cubicle/bucketized_dimension.rb', line 5

def bump
  @bump
end

#formatterObject

Returns the value of attribute formatter.



5
6
7
# File 'lib/cubicle/bucketized_dimension.rb', line 5

def formatter
  @formatter
end

#measureObject

Returns the value of attribute measure.



5
6
7
# File 'lib/cubicle/bucketized_dimension.rb', line 5

def measure
  @measure
end

#stepObject

Returns the value of attribute step.



5
6
7
# File 'lib/cubicle/bucketized_dimension.rb', line 5

def step
  @step
end

Instance Method Details

#expressionObject



22
23
24
25
# File 'lib/cubicle/bucketized_dimension.rb', line 22

def expression
generate_buckets
  @expression = "(function(val){if(val==null || isNaN(val))return null; #{@buckets.join(';')}})(#{value_expression})"
end

#value_expressionObject



17
18
19
20
# File 'lib/cubicle/bucketized_dimension.rb', line 17

def value_expression
  return measure.to_js_value if measure.respond_to?(:to_js_value)
  measure.to_s
end