Class: Trackablaze::Tracker
- Inherits:
-
Object
- Object
- Trackablaze::Tracker
- Defined in:
- lib/trackablaze/tracker.rb
Class Attribute Summary collapse
-
.default_metrics ⇒ Object
Returns the value of attribute default_metrics.
-
.handle ⇒ Object
Returns the value of attribute handle.
-
.info ⇒ Object
Returns the value of attribute info.
-
.metrics ⇒ Object
Returns the value of attribute metrics.
-
.params ⇒ Object
Returns the value of attribute params.
-
.title ⇒ Object
Returns the value of attribute title.
-
.trackers ⇒ Object
Returns the value of attribute trackers.
Class Method Summary collapse
-
.key(config) ⇒ Object
A string that uniquely identifies this instance of the tracker This is to optimize multiple instances that are exactly the same e.g.
-
.key2(config) ⇒ Object
A string that uniquely identifies this instance of the tracker, without the metrics list This is used in the csv output.
- .load ⇒ Object
- .load_trackers ⇒ Object
- .metric_title(metric_name) ⇒ Object
- .param_title(param_name) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.default_metrics ⇒ Object
Returns the value of attribute default_metrics.
4 5 6 |
# File 'lib/trackablaze/tracker.rb', line 4 def default_metrics @default_metrics end |
.handle ⇒ Object
Returns the value of attribute handle.
4 5 6 |
# File 'lib/trackablaze/tracker.rb', line 4 def handle @handle end |
.info ⇒ Object
Returns the value of attribute info.
4 5 6 |
# File 'lib/trackablaze/tracker.rb', line 4 def info @info end |
.metrics ⇒ Object
Returns the value of attribute metrics.
4 5 6 |
# File 'lib/trackablaze/tracker.rb', line 4 def metrics @metrics end |
.params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/trackablaze/tracker.rb', line 4 def params @params end |
.title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/trackablaze/tracker.rb', line 4 def title @title end |
.trackers ⇒ Object
Returns the value of attribute trackers.
4 5 6 |
# File 'lib/trackablaze/tracker.rb', line 4 def trackers @trackers end |
Class Method Details
.key(config) ⇒ Object
A string that uniquely identifies this instance of the tracker This is to optimize multiple instances that are exactly the same e.g. if 100 people want to track amolk’s twitter account, the tracker can be run only once, optimizing calls to Twitter API.
39 40 41 42 43 44 45 46 |
# File 'lib/trackablaze/tracker.rb', line 39 def key(config) # By default we use all params and metrics sb = [] sb.push(self.handle) sb.push(config['params'].flatten) if config['params'] sb.push((config['metrics'] || default_metrics).flatten) sb.flatten.join('_') end |
.key2(config) ⇒ Object
A string that uniquely identifies this instance of the tracker, without the metrics list This is used in the csv output
50 51 52 53 54 55 56 |
# File 'lib/trackablaze/tracker.rb', line 50 def key2(config) # By default we use all params and metrics sb = [] sb.push(self.handle) sb.push(config['params'].flatten) if config['params'] sb.flatten.join('_') end |
.load ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/trackablaze/tracker.rb', line 6 def load @info = YAML::load( File.open( File.dirname(__FILE__) + "/../../trackers/#{self.handle}.yml" ) ) @title = @info['title'] @params = {} self.info['params'].each do |param_name, param_config| @params[param_name] = Param.new(param_name, param_config) end @metrics = {} self.info['metrics'].each do |metric_name, metric_config| @metrics[metric_name] = Metric.new(metric_name, metric_config) end @default_metrics = self.info['metrics'].collect{|k, v| k if v && v['default']}.compact end |
.load_trackers ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/trackablaze/tracker.rb', line 27 def load_trackers @trackers = {} Trackablaze::Tracker.subclasses.each do |t| t.load @trackers[t.handle] = t end end |
.metric_title(metric_name) ⇒ Object
63 64 65 |
# File 'lib/trackablaze/tracker.rb', line 63 def metric_title(metric_name) (metrics[metric_name].title if metrics[metric_name]) || metric_name end |
.param_title(param_name) ⇒ Object
59 60 61 |
# File 'lib/trackablaze/tracker.rb', line 59 def param_title(param_name) (params[param_name].title if params[param_name]) || param_name end |
Instance Method Details
#add_error(metrics, error, field = nil) ⇒ Object
68 69 70 71 |
# File 'lib/trackablaze/tracker.rb', line 68 def add_error(metrics, error, field = nil) metrics['errors'] ||= [] metrics['errors'].push({:error => error, :field => field}) end |