Class: Rabbit::ImageDataLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit/image-data-loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ImageDataLoader

Returns a new instance of ImageDataLoader.



22
23
24
25
26
27
# File 'lib/rabbit/image-data-loader.rb', line 22

def initialize(data)
  @width = 0
  @height = 0
  @pixbuf = nil
  @data = data
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



21
22
23
# File 'lib/rabbit/image-data-loader.rb', line 21

def height
  @height
end

#pixbufObject (readonly)

Returns the value of attribute pixbuf.



21
22
23
# File 'lib/rabbit/image-data-loader.rb', line 21

def pixbuf
  @pixbuf
end

#widthObject (readonly)

Returns the value of attribute width.



21
22
23
# File 'lib/rabbit/image-data-loader.rb', line 21

def width
  @width
end

Instance Method Details

#loadObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rabbit/image-data-loader.rb', line 29

def load
  loader = Gdk::PixbufLoader.new
  id = loader.signal_connect("size_prepared") do |l, width, height|
    @width = width
    @height = height
  end
  begin
    loader.last_write(@data)
  rescue Gdk::PixbufError => error
    loader.close rescue Gdk::PixbufError
    raise ImageLoadError.new(error.message)
  end
  loader.signal_handler_disconnect(id)
  @pixbuf = loader.pixbuf
  @pixbuf
end