Class: WebResourceBundler::Filters::ImageEncodeFilter::ImageData
- Inherits:
-
Object
- Object
- WebResourceBundler::Filters::ImageEncodeFilter::ImageData
- Defined in:
- lib/web_resource_bundler/filters/image_encode_filter/image_data.rb
Overview
ImageData contains info about image found in css files
Constant Summary collapse
- MHTML_CONTENT_LOCATION =
'Content-Location:'
- MHTML_CONTENT_ENCODING =
'Content-Transfer-Encoding:base64'
Instance Attribute Summary collapse
-
#exist ⇒ Object
readonly
Returns the value of attribute exist.
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#construct_mhtml_image_data(separator) ⇒ Object
constructs part of css header with data for current image.
- #encoded ⇒ Object
-
#initialize(url, folder) ⇒ ImageData
constructor
A new instance of ImageData.
- #size ⇒ Object
Constructor Details
#initialize(url, folder) ⇒ ImageData
Returns a new instance of ImageData.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 13 def initialize(url, folder) @url = url @path = File.join(folder, url) @exist = File.file?(@path) report_problem_if_file_not_found if @exist @size = File.size(@path) @id = Digest::MD5.hexdigest(url) @extension = File.basename(@path).split('.').last end end |
Instance Attribute Details
#exist ⇒ Object (readonly)
Returns the value of attribute exist.
11 12 13 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 11 def exist @exist end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
11 12 13 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 11 def extension @extension end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 11 def id @id end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 11 def path @path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 11 def url @url end |
Instance Method Details
#construct_mhtml_image_data(separator) ⇒ Object
constructs part of css header with data for current image
30 31 32 33 34 35 36 37 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 30 def construct_mhtml_image_data(separator) if @exist result = separator + "\n" result << MHTML_CONTENT_LOCATION << @id << "\n" result << MHTML_CONTENT_ENCODING << "\n\n" result << encoded << "\n\n" end end |
#encoded ⇒ Object
39 40 41 42 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 39 def encoded return nil unless @exist Base64.encode64(File.read(@path)).gsub("\n", '') end |
#size ⇒ Object
25 26 27 |
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 25 def size @size / 1024 end |