Class: WebResourceBundler::Filters::ImageEncodeFilter::ImageData

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#existObject (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

#extensionObject (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

#idObject (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

#pathObject (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

#urlObject (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

#encodedObject



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

#sizeObject



25
26
27
# File 'lib/web_resource_bundler/filters/image_encode_filter/image_data.rb', line 25

def size
  @size / 1024
end