Class: Metric
- Inherits:
-
Object
- Object
- Metric
- Defined in:
- app/metrics/metric.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
- .display_name ⇒ Object
- .form_keys ⇒ Object
- .get_data_errors(data) ⇒ Object
- .metrics ⇒ Object
- .validate_data(data) ⇒ Object
- .validates_presence_of_data ⇒ Object
Instance Method Summary collapse
- #add_rows(table) ⇒ Object
- #after_creation(table) ⇒ Object
- #after_rows(table) ⇒ Object
- #after_table(table) ⇒ Object
- #before_creation ⇒ Object
- #before_rows(table) ⇒ Object
- #before_table ⇒ Object
- #column_names ⇒ Object
- #create_table ⇒ Object
-
#initialize(data) ⇒ Metric
constructor
A new instance of Metric.
- #result ⇒ Object
- #setting(key, default = nil) ⇒ Object
- #table_options ⇒ Object
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
#data ⇒ Object
Returns the value of attribute data.
28 29 30 |
# File 'app/metrics/metric.rb', line 28 def data @data end |
Class Method Details
.display_name ⇒ Object
7 8 9 |
# File 'app/metrics/metric.rb', line 7 def self.display_name name.demodulize.underscore.humanize.titleize end |
.form_keys ⇒ Object
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 |
.metrics ⇒ Object
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_data ⇒ Object
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_creation ⇒ Object
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_table ⇒ Object
38 39 40 |
# File 'app/metrics/metric.rb', line 38 def before_table end |
#column_names ⇒ Object
46 47 48 |
# File 'app/metrics/metric.rb', line 46 def column_names [] end |
#create_table ⇒ Object
57 58 59 |
# File 'app/metrics/metric.rb', line 57 def create_table Ruport::Data::Table.new() end |
#result ⇒ Object
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_options ⇒ Object
50 51 52 53 54 55 |
# File 'app/metrics/metric.rb', line 50 def out = {} cols = self.column_names out[:column_names] = cols if cols and not cols.empty? out end |