Class: Trackablaze::TrackerItem

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TrackerItem

Returns a new instance of TrackerItem.



4
5
6
7
8
9
10
# File 'lib/trackablaze/tracker_item.rb', line 4

def initialize(config)
	@name = config.keys[0]
@tracker_class = Trackablaze::Tracker.trackers[self.name]
	@config = config[self.name]
@params = self.config['params']
@metrics = self.config['metrics'] || @tracker_class.default_metrics
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/trackablaze/tracker_item.rb', line 3

def config
  @config
end

#metricsObject

Returns the value of attribute metrics.



3
4
5
# File 'lib/trackablaze/tracker_item.rb', line 3

def metrics
  @metrics
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/trackablaze/tracker_item.rb', line 3

def name
  @name
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/trackablaze/tracker_item.rb', line 3

def params
  @params
end

#tracker_classObject

Returns the value of attribute tracker_class.



3
4
5
# File 'lib/trackablaze/tracker_item.rb', line 3

def tracker_class
  @tracker_class
end

Class Method Details

.run(tracker_items) ⇒ Object

This function takes config object, similar in structure to a loaded yml config file



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/trackablaze/tracker_item.rb', line 36

def self.run(tracker_items)
  Trackablaze::Tracker.load_trackers
  
  results = {}

  # Dedup tracker items using unique key
  unique_tracker_items = tracker_items.uniq {|ti| ti.key}

  # Gather up all unique tracker_items for a given tracker
  tracker_items_by_tracker = {}
  unique_tracker_items.each do |tracker_item|
    tracker_name = tracker_item.name
  
    tracker_items_by_tracker[tracker_name] ||= []
    tracker_items_by_tracker[tracker_name] << tracker_item
  end

  # Run one tracker at a time
  tracker_items_by_tracker.each do |tracker_name, items|
    tracker = items.first.tracker_class.new
    tracker_results = tracker.get_metrics(items)
  
    # Store results by tracker item key
    (0..items.length-1).each do |index|
      item = items[index]
      results[item.key] = tracker_results[index]
    end
  end

  # All keys should have results now, return results
  return results
end

Instance Method Details

#full_titleObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/trackablaze/tracker_item.rb', line 24

def full_title
  sb = []
sb << @tracker_class.title
sb << " "
@params.each do |p, v|
  sb << "[#{@tracker_class.param_title(p)} = #{v}]"
end

return sb.join('')
end

#keyObject



12
13
14
# File 'lib/trackablaze/tracker_item.rb', line 12

def key()
  @key ||= tracker_class.key(config)
end

#key2Object



16
17
18
# File 'lib/trackablaze/tracker_item.rb', line 16

def key2()
  @key2 ||= tracker_class.key2(config)
end

#titleObject



20
21
22
# File 'lib/trackablaze/tracker_item.rb', line 20

def title
  @tracker_class.title
end