Sha256: 219b904d9f517fe8982e09f0c4f475ad913f2cf50bf22c8e7e00464f94a4935a

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

module Vedeu

  module Templating

    # Converts an object or collection of objects into an encoded
    # String.
    #
    # @api private
    #
    class Encoder

      # @param (see #initialize)
      # @return [String]
      def self.process(data)
        new(data).process
      end

      # Returns a new instance of Vedeu::Templating::Encoder.
      #
      # @param data [Object]
      # @return [Vedeu::Templating::Encoder]
      def initialize(data)
        @data = data
      end

      # Converts an object or collection of objects into an encoded
      # String.
      #
      # @return [String]
      def process
        wrap
      end

      protected

      # @!attribute [r] data
      # @return [Object]
      attr_reader :data

      private

      # Adds delimiters to the start and end of the data.
      #
      # @return [String]
      def wrap
        "{{#{encode64}}}".freeze
      end

      # Encode the compressed, marshalled object or objects into a
      # Base64 string.
      #
      # @return [String]
      def encode64
        Base64.strict_encode64(compress)
      end

      # Compress the marshalled object or objects.
      #
      # @return [String]
      def compress
        Zlib::Deflate.deflate(marshal)
      end

      # Convert the object or objects into marshalled object(s).
      #
      # @return [String]
      def marshal
        Marshal.dump(data)
      end

    end # Encoder

  end # Templating

end # Vedeu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
vedeu-0.6.71 lib/vedeu/templating/encoder.rb
vedeu-0.6.70 lib/vedeu/templating/encoder.rb
vedeu-0.6.69 lib/vedeu/templating/encoder.rb
vedeu-0.6.68 lib/vedeu/templating/encoder.rb
vedeu-0.6.67 lib/vedeu/templating/encoder.rb
vedeu-0.6.66 lib/vedeu/templating/encoder.rb
vedeu-0.6.65 lib/vedeu/templating/encoder.rb
vedeu-0.6.64 lib/vedeu/templating/encoder.rb
vedeu-0.6.63 lib/vedeu/templating/encoder.rb
vedeu-0.6.62 lib/vedeu/templating/encoder.rb
vedeu-0.6.61 lib/vedeu/templating/encoder.rb
vedeu-0.6.60 lib/vedeu/templating/encoder.rb
vedeu-0.6.59 lib/vedeu/templating/encoder.rb
vedeu-0.6.58 lib/vedeu/templating/encoder.rb
vedeu-0.6.57 lib/vedeu/templating/encoder.rb
vedeu-0.6.56 lib/vedeu/templating/encoder.rb
vedeu-0.6.54 lib/vedeu/templating/encoder.rb
vedeu-0.6.53 lib/vedeu/templating/encoder.rb
vedeu-0.6.52 lib/vedeu/templating/encoder.rb
vedeu-0.6.51 lib/vedeu/templating/encoder.rb