Class: Vedeu::Templating::Decoder
- Inherits:
-
Object
- Object
- Vedeu::Templating::Decoder
- Defined in:
- lib/vedeu/templating/decoder.rb
Overview
Converts an encoded string back into an object or collection of objects.
Instance Attribute Summary collapse
- #data ⇒ String readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#decode64 ⇒ String
private
Decode the Base64 string into a compressed, marshalled object or objects.
-
#decompress ⇒ String
private
Decompress the marshalled object or objects.
-
#demarshal ⇒ Object
private
Convert the marshalled object or objects back into an object(s).
-
#initialize(data) ⇒ Vedeu::Templating::Decoder
constructor
Returns a new instance of Vedeu::Templating::Decoder.
-
#process ⇒ Object
Converts an encoded string back into an object or collection of objects.
-
#unwrap ⇒ String
private
Removes delimiters from the start and end of the data.
Constructor Details
#initialize(data) ⇒ Vedeu::Templating::Decoder
Returns a new instance of Vedeu::Templating::Decoder.
20 21 22 |
# File 'lib/vedeu/templating/decoder.rb', line 20 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ String (readonly, protected)
36 37 38 |
# File 'lib/vedeu/templating/decoder.rb', line 36 def data @data end |
Class Method Details
.process(data) ⇒ Object
12 13 14 |
# File 'lib/vedeu/templating/decoder.rb', line 12 def self.process(data) new(data).process end |
Instance Method Details
#decode64 ⇒ String (private)
Decode the Base64 string into a compressed, marshalled object or objects.
59 60 61 |
# File 'lib/vedeu/templating/decoder.rb', line 59 def decode64 Base64.strict_decode64(unwrap) end |
#decompress ⇒ String (private)
Decompress the marshalled object or objects.
51 52 53 |
# File 'lib/vedeu/templating/decoder.rb', line 51 def decompress Zlib::Inflate.inflate(decode64) end |
#demarshal ⇒ Object (private)
Convert the marshalled object or objects back into an object(s).
44 45 46 |
# File 'lib/vedeu/templating/decoder.rb', line 44 def demarshal Marshal.load(decompress) end |
#process ⇒ Object
Converts an encoded string back into an object or collection of objects.
28 29 30 |
# File 'lib/vedeu/templating/decoder.rb', line 28 def process demarshal end |
#unwrap ⇒ String (private)
Removes delimiters from the start and end of the data.
66 67 68 |
# File 'lib/vedeu/templating/decoder.rb', line 66 def unwrap data.gsub(/({{)|(}})/, '') end |