Class: Trackablaze::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/trackablaze/tracker.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_metricsObject

Returns the value of attribute default_metrics.



4
5
6
# File 'lib/trackablaze/tracker.rb', line 4

def default_metrics
  @default_metrics
end

.handleObject

Returns the value of attribute handle.



4
5
6
# File 'lib/trackablaze/tracker.rb', line 4

def handle
  @handle
end

.infoObject

Returns the value of attribute info.



4
5
6
# File 'lib/trackablaze/tracker.rb', line 4

def info
  @info
end

.metricsObject

Returns the value of attribute metrics.



4
5
6
# File 'lib/trackablaze/tracker.rb', line 4

def metrics
  @metrics
end

.paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/trackablaze/tracker.rb', line 4

def params
  @params
end

.titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/trackablaze/tracker.rb', line 4

def title
  @title
end

.trackersObject

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

.loadObject



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_trackersObject



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