Module: TDiary::RefererManager
- Included in:
- RefererDiary, Style::BaseDiary
- Defined in:
- lib/tdiary/referer_manager.rb
Instance Method Summary collapse
- #add_referer(ref, count = 1) ⇒ Object
- #clear_referers ⇒ Object
- #count_referers ⇒ Object
- #each_referer(limit = 10) ⇒ Object
Instance Method Details
#add_referer(ref, count = 1) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tdiary/referer_manager.rb', line 18 def add_referer( ref, count = 1 ) newer_referer ref = ref.sub( /#.*$/, '' ).sub( /\?\d{8}$/, '' ) if /^([^:]+:\/\/)([^\/]+)/ =~ ref ref = $1 + $2.downcase + $' end begin uref = CGI::unescape( ref ) rescue ::Encoding::CompatibilityError return end if pair = @referers[uref] then pair = [pair, ref] if pair.class != Array # for compatibility @referers[uref] = [pair[0] + count, pair[1]] else @referers[uref] = [count, ref] end end |
#clear_referers ⇒ Object
37 38 39 |
# File 'lib/tdiary/referer_manager.rb', line 37 def clear_referers @referers = {} end |
#count_referers ⇒ Object
41 42 43 |
# File 'lib/tdiary/referer_manager.rb', line 41 def count_referers @referers.size end |
#each_referer(limit = 10) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tdiary/referer_manager.rb', line 45 def each_referer( limit = 10 ) newer_referer # dirty workaround to avoid recursive sort that # causes SecurityError in @secure=true # environment since # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=16081 @referers.values.sort_by{|e| "%08d_%s" % e}.reverse.each_with_index do |ary,idx| break if idx >= limit yield ary[0], ary[1] end end |