Sha256: 47a72101792cf12fa4993639de21f13662939194a7db331f9476ff64f40a2cc9

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

module Vedeu

  module Templating

    # Converts an encoded string back into an object or collection of
    # objects.
    #
    # @api private
    #
    class Decoder

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

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

      # Converts an encoded string back into an object or collection
      # of objects.
      #
      # @return [Object]
      def process
        demarshal
      end

      protected

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

      private

      # Convert the marshalled object or objects back into an
      # object(s).
      #
      # @return [Object]
      def demarshal
        Marshal.load(decompress)
      end

      # Decompress the marshalled object or objects.
      #
      # @return [String]
      def decompress
        Zlib::Inflate.inflate(decode64)
      end

      # Decode the Base64 string into a compressed, marshalled object
      # or objects.
      #
      # @return [String]
      def decode64
        Base64.strict_decode64(unwrap)
      end

      # Removes delimiters from the start and end of the data.
      #
      # @return [String]
      def unwrap
        data.gsub(/({{)|(}})/, '')
      end

    end # Decoder

  end # Templating

end # Vedeu

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vedeu-0.8.0 lib/vedeu/templating/decoder.rb
vedeu-0.7.4 lib/vedeu/templating/decoder.rb
vedeu-0.7.3 lib/vedeu/templating/decoder.rb
vedeu-0.7.2 lib/vedeu/templating/decoder.rb
vedeu-0.7.1 lib/vedeu/templating/decoder.rb
vedeu-0.7.0 lib/vedeu/templating/decoder.rb