module PageRankr::Trackers
Attributes
site_trackers[RW]
Public Class Methods
new()
click to toggle source
# File lib/page_rankr/trackers.rb, line 7 def initialize @site_trackers = self.class.constants.collect{|tracker| symbol_for(tracker)} end
Public Instance Methods
lookup(site, *trackers)
click to toggle source
# File lib/page_rankr/trackers.rb, line 11 def lookup(site, *trackers) trackers = site_trackers if trackers.empty? tracked = trackers.map do |tracker| name, klass = constant_name(tracker), self.class next unless klass.const_defined? name [ tracker, build_thread(tracker, klass.const_get(name), site) ] end.each do |_, thread| thread.join end.map do |tracker, thread| [tracker, thread.value] end Hash[tracked] end
Private Instance Methods
build_thread(tracker, instance, site)
click to toggle source
# File lib/page_rankr/trackers.rb, line 34 def build_thread(tracker, instance, site) Thread.new(tracker, instance, site) do |t, i, s| i.new(s).run end end
constant_name(sym)
click to toggle source
# File lib/page_rankr/trackers.rb, line 49 def constant_name(sym) sym.to_s.split('_').collect{|str| str.capitalize}.join end
symbol_for(klass)
click to toggle source
# File lib/page_rankr/trackers.rb, line 40 def symbol_for(klass) word = klass.to_s.dup word.gsub!(/([A-Z]+)([A-Z][a-z])/){|match| "#{$1}_#{$2}" } word.gsub!(/([a-z\d])([A-Z])/){|match| "#{$1}_#{$2}" } word.tr!("-", "_") word.downcase! word.to_sym end