Sha256: 7dd1b6f22f5d76019dce722a3ce36bcfce576421377aa0e1a5eebb12bbcb0766

Contents?: true

Size: 1.46 KB

Versions: 31

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Templating

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

      # @param (see #initialize)
      # @return (see #process)
      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}}}"
      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

31 entries across 31 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/templating/encoder.rb
vedeu-0.8.31 lib/vedeu/templating/encoder.rb
vedeu-0.8.30 lib/vedeu/templating/encoder.rb
vedeu-0.8.29 lib/vedeu/templating/encoder.rb
vedeu-0.8.28 lib/vedeu/templating/encoder.rb
vedeu-0.8.27 lib/vedeu/templating/encoder.rb
vedeu-0.8.26 lib/vedeu/templating/encoder.rb
vedeu-0.8.25 lib/vedeu/templating/encoder.rb
vedeu-0.8.24 lib/vedeu/templating/encoder.rb
vedeu-0.8.23 lib/vedeu/templating/encoder.rb
vedeu-0.8.22 lib/vedeu/templating/encoder.rb
vedeu-0.8.21 lib/vedeu/templating/encoder.rb
vedeu-0.8.20 lib/vedeu/templating/encoder.rb
vedeu-0.8.19 lib/vedeu/templating/encoder.rb
vedeu-0.8.18 lib/vedeu/templating/encoder.rb
vedeu-0.8.17 lib/vedeu/templating/encoder.rb
vedeu-0.8.16 lib/vedeu/templating/encoder.rb
vedeu-0.8.15 lib/vedeu/templating/encoder.rb
vedeu-0.8.14 lib/vedeu/templating/encoder.rb
vedeu-0.8.13 lib/vedeu/templating/encoder.rb