agoragames / bnet_scraper

A Nokogiri-based scraper of Battle.net profiles. Currently this only includes Starcraft2.
MIT License
22 stars 7 forks source link

added portrait name scraping to ProfileScraper #5

Closed fx closed 11 years ago

fx commented 11 years ago

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.

cadwallion commented 11 years ago

Looks great, thanks! :+1: