Class: GrabzIt::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/grabz_it/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Image

Returns a new instance of Image.



5
6
7
8
9
10
11
12
13
# File 'lib/grabz_it/image.rb', line 5

def initialize(response)
  begin
    @image_bytes = response.body
    @size = @image_bytes ? @image_bytes.size : 0
    @content_type = response.header['content-type']
  rescue => ex
    raise "Invalid Response"
  end
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



3
4
5
# File 'lib/grabz_it/image.rb', line 3

def content_type
  @content_type
end

#image_bytesObject

Returns the value of attribute image_bytes.



3
4
5
# File 'lib/grabz_it/image.rb', line 3

def image_bytes
  @image_bytes
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/grabz_it/image.rb', line 3

def size
  @size
end

Instance Method Details

#save(path) ⇒ Object



15
16
17
# File 'lib/grabz_it/image.rb', line 15

def save(path)
  File.open(path, 'wb') { |s| s.write(@image_bytes) }
end