Class: ActiveReporter::Dimension::Category

Inherits:
Base
  • Object
show all
Defined in:
lib/active_reporter/dimension/category.rb

Direct Known Subclasses

Enum

Instance Attribute Summary

Attributes inherited from Base

#name, #opts, #report

Instance Method Summary collapse

Methods inherited from Base

#attribute, #expression, #extract_sql_value, #filter_values, #filtering?, #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

#all_valuesObject



24
25
26
# File 'lib/active_reporter/dimension/category.rb', line 24

def all_values
  relate(report.base_relation).pluck("DISTINCT #{expression}").map(&method(:sanitize_sql_value))
end

#filter(relation) ⇒ Object



6
7
8
9
10
11
# File 'lib/active_reporter/dimension/category.rb', line 6

def filter(relation)
  values = filter_values
  query = "#{expression} IN (?)"
  query = "#{expression} IS NULL OR #{query}" if values.include?(nil)
  relation.where(query, values.compact)
end

#group(relation) ⇒ Object



13
14
15
# File 'lib/active_reporter/dimension/category.rb', line 13

def group(relation)
  order relation.select("#{expression} AS #{sql_value_name}").group(sql_value_name)
end

#group_valuesObject



17
18
19
20
21
22
# File 'lib/active_reporter/dimension/category.rb', line 17

def group_values
  return filter_values if filtering?

  i = report.groupers.index(self)
  report.raw_data.keys.map { |x| x[i] }.uniq
end