Class: Vedeu::Templating::Encoder

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

Overview

Converts an object or collection of objects into an encoded String.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

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

Parameters:

  • data (Object)


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

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly, protected)

Returns:

  • (Object)


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

def data
  @data
end

Class Method Details

.process(data) ⇒ String

Parameters:

  • data (Object)

Returns:

  • (String)


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

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

Instance Method Details

#compressString (private)

Compress the marshalled object or objects.

Returns:

  • (String)


58
59
60
# File 'lib/vedeu/templating/encoder.rb', line 58

def compress
  Zlib::Deflate.deflate(marshal)
end

#encode64String (private)

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

Returns:

  • (String)


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

def encode64
  Base64.strict_encode64(compress)
end

#marshalString (private)

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

Returns:

  • (String)


65
66
67
# File 'lib/vedeu/templating/encoder.rb', line 65

def marshal
  Marshal.dump(data)
end

#processString

Converts an object or collection of objects into an encoded String.

Returns:

  • (String)


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

def process
  wrap
end

#wrapString (private)

Adds delimiters to the start and end of the data.

Returns:

  • (String)


43
44
45
# File 'lib/vedeu/templating/encoder.rb', line 43

def wrap
  "{{#{encode64}}}"
end