agoragames/bnet_scraper — pull request #5 by fx (2012-09-19 05:52:01+00:00)
Title: added portrait name scraping to ProfileScraper

I'm back with goodies!

Due to how portraits are set up, I decided to simply produce the name. I'm using something like this to get back the image map and position from the name:

module BnetScraper
module Starcraft2
# Returns the map file and position of a portrait by name
def self.portrait_position(name)
index = PORTRAITS.flatten(1).collect(&:downcase).index(name.to_s.downcase)
map = (index / 36)
map_index = (index - map * 36) + 1
y = (map_index.to_f / 6.0).ceil.to_i - 1
x = (map_index - (y*6)) - 1
[map, x, y]
end
end
end

Simply using the map-size.jpg and x, y * size in CSS.