Class: ClarkKent::ReportColumn

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Cloneable
Defined in:
app/models/clark_kent/report_column.rb

Constant Summary collapse

SummaryMethods =
['total','average']

Instance Method Summary collapse

Methods included from Cloneable

#cloneable_attributes, #reset_timestamps

Instance Method Details

#calculate_summary(values) ⇒ Object



21
22
23
24
# File 'app/models/clark_kent/report_column.rb', line 21

def calculate_summary(values)
	return nil unless self.summary_method.present?
	calculator.new(values).calculate
end

#calculatorObject



34
35
36
# File 'app/models/clark_kent/report_column.rb', line 34

def calculator
	('ClarkKent::' + summary_method.camelcase + 'Calculator').constantize
end

#config_optionsObject



42
43
44
# File 'app/models/clark_kent/report_column.rb', line 42

def config_options
  report.column_options_for(self.name.to_sym)
end

#has_options?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/models/clark_kent/report_column.rb', line 13

def has_options?
  config_options.present?
end


46
47
48
# File 'app/models/clark_kent/report_column.rb', line 46

def link
  config_options.link
end

#nameObject



38
39
40
# File 'app/models/clark_kent/report_column.rb', line 38

def name
  column_name
end

#report_sort_prettyObject



17
18
19
# File 'app/models/clark_kent/report_column.rb', line 17

def report_sort_pretty
	{'ascending' => 'A->Z','descending' => 'Z->A'}[self.report_sort]
end

#sortable?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/clark_kent/report_column.rb', line 30

def sortable?
  config_options.order_sql.present?
end

#summarizable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/clark_kent/report_column.rb', line 26

def summarizable?
	config_options.summarizable
end

#time_formatObject



54
55
56
# File 'app/models/clark_kent/report_column.rb', line 54

def time_format
  config_options.time_format
end

#time_zone_columnObject



50
51
52
# File 'app/models/clark_kent/report_column.rb', line 50

def time_zone_column
  config_options.time_zone_column
end