Class: Vedeu::Templating::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/templating/decoder.rb

Overview

Converts an encoded string back into an object or collection of objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Vedeu::Templating::Decoder

Returns a new instance of Vedeu::Templating::Decoder.

Parameters:

  • data (String)


20
21
22
# File 'lib/vedeu/templating/decoder.rb', line 20

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataString (readonly, protected)

Returns:

  • (String)


36
37
38
# File 'lib/vedeu/templating/decoder.rb', line 36

def data
  @data
end

Class Method Details

.process(data) ⇒ Object

Parameters:

  • data (String)

Returns:

  • (Object)


12
13
14
# File 'lib/vedeu/templating/decoder.rb', line 12

def self.process(data)
  new(data).process
end

Instance Method Details

#decode64String (private)

Decode the Base64 string into a compressed, marshalled object or objects.

Returns:

  • (String)


59
60
61
# File 'lib/vedeu/templating/decoder.rb', line 59

def decode64
  Base64.strict_decode64(unwrap)
end

#decompressString (private)

Decompress the marshalled object or objects.

Returns:

  • (String)


51
52
53
# File 'lib/vedeu/templating/decoder.rb', line 51

def decompress
  Zlib::Inflate.inflate(decode64)
end

#demarshalObject (private)

Convert the marshalled object or objects back into an object(s).

Returns:

  • (Object)


44
45
46
# File 'lib/vedeu/templating/decoder.rb', line 44

def demarshal
  Marshal.load(decompress)
end

#processObject

Converts an encoded string back into an object or collection of objects.

Returns:

  • (Object)


28
29
30
# File 'lib/vedeu/templating/decoder.rb', line 28

def process
  demarshal
end

#unwrapString (private)

Removes delimiters from the start and end of the data.

Returns:

  • (String)


66
67
68
# File 'lib/vedeu/templating/decoder.rb', line 66

def unwrap
  data.gsub(/({{)|(}})/, '')
end