Class: MakeBook::Formats::HTML::Asset
- Inherits:
-
Object
- Object
- MakeBook::Formats::HTML::Asset
- Defined in:
- lib/makebook/formats/html.rb
Overview
External element
Direct Known Subclasses
Instance Attribute Summary collapse
-
#mime ⇒ Object
readonly
Returns the value of attribute mime.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #base64 ⇒ Object
- #build_name ⇒ Object
- #data_uri ⇒ Object
- #digest ⇒ Object
-
#initialize(source, mime: nil) ⇒ Asset
constructor
A new instance of Asset.
- #read ⇒ Object
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
#mime ⇒ Object (readonly)
Returns the value of attribute mime.
18 19 20 |
# File 'lib/makebook/formats/html.rb', line 18 def mime @mime end |
#source ⇒ Object (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
#base64 ⇒ Object
39 40 41 |
# File 'lib/makebook/formats/html.rb', line 39 def base64 Base64.encode64(read) end |
#build_name ⇒ Object
31 32 33 |
# File 'lib/makebook/formats/html.rb', line 31 def build_name "#{digest}#{source.extname}" end |
#data_uri ⇒ Object
43 44 45 |
# File 'lib/makebook/formats/html.rb', line 43 def data_uri "data:#{mime};base64,#{base64}" end |
#digest ⇒ Object
25 26 27 28 29 |
# File 'lib/makebook/formats/html.rb', line 25 def digest sha1 = Digest::SHA1.new sha1 << read sha1.hexdigest end |
#read ⇒ Object
35 36 37 |
# File 'lib/makebook/formats/html.rb', line 35 def read File.read(source) end |