Class: Metric

Inherits:
Object
  • Object
show all
Defined in:
app/metrics/metric.rb

Direct Known Subclasses

SqlQuery

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Metric

Returns a new instance of Metric.



29
30
31
# File 'app/metrics/metric.rb', line 29

def initialize(data)
  self.data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



28
29
30
# File 'app/metrics/metric.rb', line 28

def data
  @data
end

Class Method Details

.display_nameObject



7
8
9
# File 'app/metrics/metric.rb', line 7

def self.display_name
  name.demodulize.underscore.humanize.titleize
end

.form_keysObject



11
12
13
# File 'app/metrics/metric.rb', line 11

def self.form_keys
  []  # override to get more / different
end

.get_data_errors(data) ⇒ Object



19
20
21
22
# File 'app/metrics/metric.rb', line 19

def self.get_data_errors(data)
  return ["can't be blank"] if @validates_presence_of_data and data.blank?
  validate_data(data) || []
end

.metricsObject



2
3
4
5
# File 'app/metrics/metric.rb', line 2

def self.metrics
  DailyConfig.load_classes if Rails.env.development?
  subclasses
end

.validate_data(data) ⇒ Object



24
25
26
# File 'app/metrics/metric.rb', line 24

def self.validate_data(data)
  []
end

.validates_presence_of_dataObject



15
16
17
# File 'app/metrics/metric.rb', line 15

def self.validates_presence_of_data
  @validates_presence_of_data = true
end

Instance Method Details

#add_rows(table) ⇒ Object



69
70
71
# File 'app/metrics/metric.rb', line 69

def add_rows(table)
  
end

#after_creation(table) ⇒ Object



61
62
63
# File 'app/metrics/metric.rb', line 61

def after_creation(table)
  
end

#after_rows(table) ⇒ Object



73
74
75
# File 'app/metrics/metric.rb', line 73

def after_rows(table)
  
end

#after_table(table) ⇒ Object



77
78
79
# File 'app/metrics/metric.rb', line 77

def after_table(table)
  
end

#before_creationObject



42
43
44
# File 'app/metrics/metric.rb', line 42

def before_creation
  
end

#before_rows(table) ⇒ Object



65
66
67
# File 'app/metrics/metric.rb', line 65

def before_rows(table)
  
end

#before_tableObject



38
39
40
# File 'app/metrics/metric.rb', line 38

def before_table
  
end

#column_namesObject



46
47
48
# File 'app/metrics/metric.rb', line 46

def column_names
  []
end

#create_tableObject



57
58
59
# File 'app/metrics/metric.rb', line 57

def create_table
  Ruport::Data::Table.new(table_options)
end

#resultObject



81
82
83
84
85
86
87
88
89
90
91
# File 'app/metrics/metric.rb', line 81

def result
  before_table
  before_creation
  out = create_table
  after_creation(out)
  before_rows(out)
  add_rows(out)
  after_rows(out)
  after_table(out)
  out
end

#setting(key, default = nil) ⇒ Object



33
34
35
36
# File 'app/metrics/metric.rb', line 33

def setting(key, default = nil)
  val = settings[key.to_sym]
  val.blank? ? default : val
end

#table_optionsObject



50
51
52
53
54
55
# File 'app/metrics/metric.rb', line 50

def table_options
  out = {}
  cols = self.column_names
  out[:column_names] = cols if cols and not cols.empty?
  out
end