Class: MakeBook::Formats::HTML::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/makebook/formats/html.rb

Overview

External element

Direct Known Subclasses

Stylesheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, mime: nil) ⇒ Asset

Returns a new instance of Asset.



20
21
22
23
# File 'lib/makebook/formats/html.rb', line 20

def initialize(source, mime: nil)
  @source = source
  @mime = mime
end

Instance Attribute Details

#mimeObject (readonly)

Returns the value of attribute mime.



18
19
20
# File 'lib/makebook/formats/html.rb', line 18

def mime
  @mime
end

#sourceObject (readonly)

Returns the value of attribute source.



18
19
20
# File 'lib/makebook/formats/html.rb', line 18

def source
  @source
end

Instance Method Details

#base64Object



39
40
41
# File 'lib/makebook/formats/html.rb', line 39

def base64
  Base64.encode64(read)
end

#build_nameObject



31
32
33
# File 'lib/makebook/formats/html.rb', line 31

def build_name
  "#{digest}#{source.extname}"
end

#data_uriObject



43
44
45
# File 'lib/makebook/formats/html.rb', line 43

def data_uri
  "data:#{mime};base64,#{base64}"
end

#digestObject



25
26
27
28
29
# File 'lib/makebook/formats/html.rb', line 25

def digest
  sha1 = Digest::SHA1.new
  sha1 << read
  sha1.hexdigest
end

#readObject



35
36
37
# File 'lib/makebook/formats/html.rb', line 35

def read
  File.read(source)
end