Class: AllAvatarsSite
- Inherits:
-
Object
- Object
- AllAvatarsSite
- Defined in:
- lib/randomizer/all_avatars_site.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ AllAvatarsSite
constructor
A new instance of AllAvatarsSite.
- #load_urls ⇒ Object
- #random_url ⇒ Object
Constructor Details
#initialize ⇒ AllAvatarsSite
Returns a new instance of AllAvatarsSite.
10 11 12 13 |
# File 'lib/randomizer/all_avatars_site.rb', line 10 def initialize @unused_avatar_urls = [] @used_avatar_urls = [] end |
Class Method Details
.instance ⇒ Object
6 7 8 |
# File 'lib/randomizer/all_avatars_site.rb', line 6 def self.instance @@instance ||= AllAvatarsSite.new end |
Instance Method Details
#load_urls ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/randomizer/all_avatars_site.rb', line 15 def load_urls while @unused_avatar_urls.empty? path = "/avatars/showgallery.php?si=&perpage=18&sort=6&cat=all&ppuser=" response = Net::HTTP.get_response("www.allavatars.com", path).body doc = Nokogiri::HTML(response) (doc/'img').each do |img| source = img['src'] if source =~ %r{http://www.allavatars.com/avatars/data/.*} && !@used_avatar_urls.member?(source) @unused_avatar_urls << source end end end end |
#random_url ⇒ Object
29 30 31 32 33 34 |
# File 'lib/randomizer/all_avatars_site.rb', line 29 def random_url load_urls if @unused_avatar_urls.empty? url = @unused_avatar_urls.pop @used_avatar_urls << url url end |