class BnetScraper::Starcraft2::Portrait

Portrait information pulled from the Armory. Portraits are 90-pixel jpgs that are either viewed as a single image or as part of a 6x6 spritesheet. There are several spritesheets with a few cells in the sheets not yet filled but will be in the future.

The Profile page uses the spritesheet version of the Portrait with an X/Y background position. This is converted into sheet, column, and row, which allows us to know the name and map to the single image url as well.

Constants

NAMES

The armory uses spritemaps that are sequentially named and have a fixed 6x6 grid. We’ll simply use the portrait names, left to right, top to bottom. The sheets are padded even when no portrait is present to account for the 36-image sheet

Attributes

column[R]
name[R]
row[R]
sheet[R]

Public Class Methods

new(sheet, pixel_size, pixel_column, pixel_row) click to toggle source
# File lib/bnet_scraper/starcraft2/portrait.rb, line 52
def initialize sheet, pixel_size, pixel_column, pixel_row
  @sheet = sheet
  @column = pixel_column / pixel_size
  @row = pixel_row / pixel_size
  @name = name_from_position
end

Public Instance Methods

image_position() click to toggle source

The image position within a given 6x6 spritesheet

@return [Fixnum] image position within the spritesheet

# File lib/bnet_scraper/starcraft2/portrait.rb, line 77
def image_position
  (@row * 6) + @column
end
name_from_position() click to toggle source
# File lib/bnet_scraper/starcraft2/portrait.rb, line 59
def name_from_position
  index = (@sheet * 36) + image_position
  NAMES[index]
end
spritesheet_url() click to toggle source

@return [String] The URL to the spritesheet the portrait is part of

# File lib/bnet_scraper/starcraft2/portrait.rb, line 70
def spritesheet_url
  "http://media.blizzard.com/sc2/portraits/#{@sheet}-90.jpg"
end
url() click to toggle source

@return [String] The URL to the portrait image iteslf

# File lib/bnet_scraper/starcraft2/portrait.rb, line 65
def url
  "http://media.blizzard.com/sc2/portraits/#{@sheet}-#{image_position}.jpg"
end