Sha256: 4755c2ec98ff132c70ef89ce91eca756f213001cf9268c52011814d8f19af892

Contents?: true

Size: 1.45 KB

Versions: 11

Compression:

Stored size: 1.45 KB

Contents

module Vedeu

  module Templating

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

      # @param data [String]
      # @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

11 entries across 11 versions & 1 rubygems

Version Path
vedeu-0.6.20 lib/vedeu/templating/decoder.rb
vedeu-0.6.19 lib/vedeu/templating/decoder.rb
vedeu-0.6.18 lib/vedeu/templating/decoder.rb
vedeu-0.6.17 lib/vedeu/templating/decoder.rb
vedeu-0.6.16 lib/vedeu/templating/decoder.rb
vedeu-0.6.15 lib/vedeu/templating/decoder.rb
vedeu-0.6.14 lib/vedeu/templating/decoder.rb
vedeu-0.6.13 lib/vedeu/templating/decoder.rb
vedeu-0.6.12 lib/vedeu/templating/decoder.rb
vedeu-0.6.11 lib/vedeu/templating/decoder.rb
vedeu-0.6.10 lib/vedeu/templating/decoder.rb