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
Public Class Methods
# 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
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
# File lib/bnet_scraper/starcraft2/portrait.rb, line 59 def name_from_position index = (@sheet * 36) + image_position NAMES[index] end
@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
@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