Class: MinecraftAvatars::RawSkin

Inherits:
Object
  • Object
show all
Defined in:
lib/minecraft-avatars/raw_skin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message == "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

#imageObject

Returns the value of attribute image.



11
12
13
# File 'lib/minecraft-avatars/raw_skin.rb', line 11

def image
  @image
end

#player_nameObject

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

#sectionsObject

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

#deconstructObject



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