Class: Lookbook::FileDataUriEncoder

Inherits:
Service
  • Object
show all
Defined in:
lib/lookbook/services/urls/file_data_uri_encoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Service

call

Constructor Details

#initialize(path, mime_type = nil) ⇒ FileDataUriEncoder

Returns a new instance of FileDataUriEncoder.



7
8
9
10
# File 'lib/lookbook/services/urls/file_data_uri_encoder.rb', line 7

def initialize(path, mime_type = nil)
  @path = path
  @mime_type = mime_type
end

Instance Attribute Details

#pathObject (readonly)



5
6
7
# File 'lib/lookbook/services/urls/file_data_uri_encoder.rb', line 5

def path
  @path
end

Instance Method Details

#callObject



20
21
22
# File 'lib/lookbook/services/urls/file_data_uri_encoder.rb', line 20

def call
  DataUriEncoder.call(content, mime_type)
end

#contentObject



12
13
14
# File 'lib/lookbook/services/urls/file_data_uri_encoder.rb', line 12

def content
  File.read(path)
end

#mime_typeObject



16
17
18
# File 'lib/lookbook/services/urls/file_data_uri_encoder.rb', line 16

def mime_type
  @mime_type || Marcel::MimeType.for(Pathname.new(path))
end