Class: Vedeu::Templating::Encoder
- Inherits:
-
Object
- Object
- Vedeu::Templating::Encoder
- Defined in:
- lib/vedeu/templating/encoder.rb
Overview
Converts an object or collection of objects into an encoded String.
Instance Attribute Summary collapse
- #data ⇒ Object readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#compress ⇒ String
private
Compress the marshalled object or objects.
-
#encode64 ⇒ String
private
Encode the compressed, marshalled object or objects into a Base64 string.
-
#initialize(data) ⇒ Vedeu::Templating::Encoder
constructor
Returns a new instance of Vedeu::Templating::Encoder.
-
#marshal ⇒ String
private
Convert the object or objects into marshalled object(s).
-
#process ⇒ String
Converts an object or collection of objects into an encoded String.
-
#wrap ⇒ String
private
Adds delimiters to the start and end of the data.
Constructor Details
#initialize(data) ⇒ Vedeu::Templating::Encoder
Returns a new instance of Vedeu::Templating::Encoder.
20 21 22 |
# File 'lib/vedeu/templating/encoder.rb', line 20 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly, protected)
36 37 38 |
# File 'lib/vedeu/templating/encoder.rb', line 36 def data @data end |
Class Method Details
.process(data) ⇒ String
12 13 14 |
# File 'lib/vedeu/templating/encoder.rb', line 12 def self.process(data) new(data).process end |
Instance Method Details
#compress ⇒ String (private)
Compress the marshalled object or objects.
58 59 60 |
# File 'lib/vedeu/templating/encoder.rb', line 58 def compress Zlib::Deflate.deflate(marshal) end |
#encode64 ⇒ String (private)
Encode the compressed, marshalled object or objects into a Base64 string.
51 52 53 |
# File 'lib/vedeu/templating/encoder.rb', line 51 def encode64 Base64.strict_encode64(compress) end |
#marshal ⇒ String (private)
Convert the object or objects into marshalled object(s).
65 66 67 |
# File 'lib/vedeu/templating/encoder.rb', line 65 def marshal Marshal.dump(data) end |
#process ⇒ String
Converts an object or collection of objects into an encoded String.
28 29 30 |
# File 'lib/vedeu/templating/encoder.rb', line 28 def process wrap end |
#wrap ⇒ String (private)
Adds delimiters to the start and end of the data.
43 44 45 |
# File 'lib/vedeu/templating/encoder.rb', line 43 def wrap "{{#{encode64}}}" end |