Class: Webstalker::Flickr

Inherits:
Base
  • Object
show all
Defined in:
lib/webstalker/flickr.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #username

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Webstalker::Base

Instance Method Details

#tagsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/webstalker/flickr.rb', line 3

def tags
  url = "http://www.flickr.com/photos/#{username}/tags/"

  doc = Nokogiri::HTML(open(url))
  w=[]
  doc.css("#TagCloud a").each do |link|
    t = link.text.strip
    if t !~ /#{Regexp.escape(username)}/
      w << [link.text.strip, link.attr("style").match(/(\d+)/)[0].to_i ]
    end
  end
  w=w.sort_by {|e| e.last*-1}

  tags = Set.new(w[0,options[:limit]||3].map{|e| e.first})
  if w.size > 10
    6.times do
      tags << w.at(rand(w.size)).first
    end
  end

  tags
end