Sha256: 5a34e9604d75b866e8a7716fcd4aa351a68fb24e5e72e76e766c1f58943ba6ab

Contents?: true

Size: 776 Bytes

Versions: 4

Compression:

Stored size: 776 Bytes

Contents

module Writer
  class SymbolMatrix
    attr_accessor :source

    def initialize source
      @source = source
    end

    def serialization prefix = nil
      result = ""
      @source.each do |key, value|
        unless value.is_a? Hash
          result += " #{prefix}#{key}:#{value}"
        else
          result += " " + Writer::SymbolMatrix.new(value).serialization("#{prefix}#{key}.")
        end
      end
      result[1..-1]
    end

    alias :smas :serialization

    def hash
      the_hash = {}
      @source.each do |key, value|
        if value.respond_to? :to
          the_hash[key] = value.to.hash
        else
          the_hash[key] = value
        end
      end
      the_hash
    end
  end
end

class SymbolMatrix < Hash
  include Discoverer::Writer
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
symbolmatrix-1.1.2 lib/writer/symbolmatrix.rb
symbolmatrix-1.1.1 lib/writer/symbolmatrix.rb
symbolmatrix-1.1.0 lib/writer/symbolmatrix.rb
symbolmatrix-1.0.0 lib/writer/symbolmatrix.rb