Sha256: 0b364513777de5d428cbe56b40ebb1479252b5abca3346f2ec554beff23dab71

Contents?: true

Size: 1.38 KB

Versions: 23

Compression:

Stored size: 1.38 KB

Contents

module Vedeu

  module Templating

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

      # @param data [Object]
      # @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}}}"
      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

23 entries across 23 versions & 1 rubygems

Version Path
vedeu-0.6.9 lib/vedeu/templating/encoder.rb
vedeu-0.6.8 lib/vedeu/templating/encoder.rb
vedeu-0.6.7 lib/vedeu/templating/encoder.rb
vedeu-0.6.6 lib/vedeu/templating/encoder.rb
vedeu-0.6.5 lib/vedeu/templating/encoder.rb
vedeu-0.6.4 lib/vedeu/templating/encoder.rb
vedeu-0.6.3 lib/vedeu/templating/encoder.rb
vedeu-0.6.2 lib/vedeu/templating/encoder.rb
vedeu-0.6.1 lib/vedeu/templating/encoder.rb
vedeu-0.6.0 lib/vedeu/templating/encoder.rb
vedeu-0.5.13 lib/vedeu/templating/encoder.rb
vedeu-0.5.12 lib/vedeu/templating/encoder.rb
vedeu-0.5.11 lib/vedeu/templating/encoder.rb
vedeu-0.5.10 lib/vedeu/templating/encoder.rb
vedeu-0.5.9 lib/vedeu/templating/encoder.rb
vedeu-0.5.8 lib/vedeu/templating/encoder.rb
vedeu-0.5.7 lib/vedeu/templating/encoder.rb
vedeu-0.5.6 lib/vedeu/templating/encoder.rb
vedeu-0.5.5 lib/vedeu/templating/encoder.rb
vedeu-0.5.4 lib/vedeu/templating/encoder.rb