Class: MinecraftAvatars::RawSkin
- Inherits:
-
Object
- Object
- MinecraftAvatars::RawSkin
- Defined in:
- lib/minecraft-avatars/raw_skin.rb
Instance Attribute Summary collapse
-
#image ⇒ Object
Returns the value of attribute image.
-
#player_name ⇒ Object
Returns the value of attribute player_name.
-
#sections ⇒ Object
Returns the value of attribute sections.
Instance Method Summary collapse
- #deconstruct ⇒ Object
-
#initialize(player_name) ⇒ RawSkin
constructor
A new instance of RawSkin.
Constructor Details
#initialize(player_name) ⇒ RawSkin
Returns a new instance of RawSkin.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/minecraft-avatars/raw_skin.rb', line 13 def initialize(player_name) self.sections = {} self.player_name = player_name begin image_uri = open "#{MinecraftAvatars::SKIN_URL}/#{player_name}.png" raw_data = image_uri.read rescue OpenURI::HTTPError => e if e. == "403 Forbidden" raise MinecraftAvatars::InvalidPlayerException.new(player_name) else raise e end end self.image = ChunkyPNG::Image.from_blob(raw_data) deconstruct end |
Instance Attribute Details
#image ⇒ Object
Returns the value of attribute image.
11 12 13 |
# File 'lib/minecraft-avatars/raw_skin.rb', line 11 def image @image end |
#player_name ⇒ Object
Returns the value of attribute player_name.
9 10 11 |
# File 'lib/minecraft-avatars/raw_skin.rb', line 9 def player_name @player_name end |
#sections ⇒ Object
Returns the value of attribute sections.
10 11 12 |
# File 'lib/minecraft-avatars/raw_skin.rb', line 10 def sections @sections end |
Instance Method Details
#deconstruct ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/minecraft-avatars/raw_skin.rb', line 34 def deconstruct MinecraftAvatars::SKIN_SECTIONS.each do |name, section| x, y, width, height = section chunk = self.image.crop x, y, width, height self.sections[name] = chunk end end |