Class: Tinify::Result
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #to_buffer)
readonly
Returns the value of attribute data.
Instance Method Summary
collapse
Methods inherited from ResultMeta
#height, #location, #width
Constructor Details
#initialize(meta, data) ⇒ Result
Returns a new instance of Result.
5
6
7
|
# File 'lib/tinify/result.rb', line 5
def initialize(meta, data)
@meta, @data = meta.freeze, data.freeze
end
|
Instance Attribute Details
#data ⇒ Object
Also known as:
to_buffer
Returns the value of attribute data.
3
4
5
|
# File 'lib/tinify/result.rb', line 3
def data
@data
end
|
Instance Method Details
#extension ⇒ Object
24
25
26
27
28
29
|
# File 'lib/tinify/result.rb', line 24
def extension
if @meta['Content-Type']
parts = @meta["Content-Type"].split "/"
parts.last
end
end
|
19
20
21
|
# File 'lib/tinify/result.rb', line 19
def media_type
@meta["Content-Type"]
end
|
#size ⇒ Object
15
16
17
|
# File 'lib/tinify/result.rb', line 15
def size
@meta["Content-Length"].to_i.nonzero?
end
|
#to_file(path) ⇒ Object
9
10
11
|
# File 'lib/tinify/result.rb', line 9
def to_file(path)
File.open(path, "wb") { |file| file.write(data) }
end
|