Class: Trackablaze::Tracker
- Inherits:
-
Object
- Object
- Trackablaze::Tracker
- Defined in:
- lib/trackablaze/tracker.rb
Class Attribute Summary collapse
-
.trackers ⇒ Object
Returns the value of attribute trackers.
Class Method Summary collapse
- .default_metrics ⇒ Object
- .handle ⇒ Object
- .info ⇒ Object
-
.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.
- .load_trackers ⇒ Object
- .title ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.trackers ⇒ Object
Returns the value of attribute trackers.
18 19 20 |
# File 'lib/trackablaze/tracker.rb', line 18 def trackers @trackers end |
Class Method Details
.default_metrics ⇒ Object
40 41 42 |
# File 'lib/trackablaze/tracker.rb', line 40 def self.default_metrics @default_metrics ||= self.info['metrics'].collect{|k, v| k if v && v['default']}.compact end |
.handle ⇒ Object
28 29 30 |
# File 'lib/trackablaze/tracker.rb', line 28 def self.handle @handle ||= self.name.split('::')[1].underscore end |
.info ⇒ Object
32 33 34 |
# File 'lib/trackablaze/tracker.rb', line 32 def self.info @info ||= YAML::load( File.open( File.dirname(__FILE__) + "/../../trackers/#{self.handle}.yml" ) ) end |
.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.
8 9 10 11 12 13 14 15 |
# File 'lib/trackablaze/tracker.rb', line 8 def self.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 |
.load_trackers ⇒ Object
20 21 22 23 24 25 |
# File 'lib/trackablaze/tracker.rb', line 20 def load_trackers @trackers = {} Trackablaze::Tracker.subclasses.each do |t| @trackers[t.handle] = t end end |
.title ⇒ Object
36 37 38 |
# File 'lib/trackablaze/tracker.rb', line 36 def self.title self.info['title'] end |
Instance Method Details
#add_error(metrics, error, field = nil) ⇒ Object
48 49 50 51 |
# File 'lib/trackablaze/tracker.rb', line 48 def add_error(metrics, error, field = nil) metrics['errors'] ||= [] metrics['errors'].push({:error => error, :field => field}) end |
#get_metrics(params, metrics) ⇒ Object
44 45 46 |
# File 'lib/trackablaze/tracker.rb', line 44 def get_metrics(params, metrics) {} end |