Class: GrabzIt::Image
- Inherits:
-
Object
- Object
- GrabzIt::Image
- Defined in:
- lib/grabz_it/image.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#image_bytes ⇒ Object
Returns the value of attribute image_bytes.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(response) ⇒ Image
constructor
A new instance of Image.
- #save(path) ⇒ Object
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_type ⇒ Object
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_bytes ⇒ Object
Returns the value of attribute image_bytes.
3 4 5 |
# File 'lib/grabz_it/image.rb', line 3 def image_bytes @image_bytes end |
#size ⇒ Object
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 |