Sha256: 0e932271980426b60708865757382491ff699e857dca5d47018d6b6fdea1f157

Contents?: true

Size: 1.48 KB

Versions: 20

Compression:

Stored size: 1.48 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 [Object]
      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

20 entries across 20 versions & 1 rubygems

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