Sha256: 9b922fc85d1af5be2d103ae96155db7a392133c9683aa8993d0b2867480c8797

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

class SymbolMatrix < Hash
  class Serialization
    def self.parse serialization
      result = SymbolMatrix.new
      return result if serialization.length == 0
      
      if serialization.include? " "
        serialization.split(" ").each do |command|
          result = result.recursive_merge parse command
        end
      else
        parts = serialization.split ":"
        unless parts.first.include? "."          
          begin
            parts[1] = Integer parts.last
          rescue ArgumentError => e
          end
          result.merge! parts.first => parts.last
        else
          the_key = serialization[0..serialization.index(".") -1]
          result[the_key] = parse serialization[serialization.index(".")+1..-1]
        end
      end
      result
    end
  end

  def initialize argument = nil
    if argument.is_a? String
      if File.exist? argument
        from.file argument
      else
        begin
          from.yaml argument
        rescue NoMethodError => e
          from.serialization argument
        end
      end
    else
      merge! argument unless argument.nil?
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
gamera-symbolmatrix-1.2.1 lib/symbolmatrix/serialization.rb
symbolmatrix-1.2.0 lib/symbolmatrix/serialization.rb
symbolmatrix-1.1.3 lib/symbolmatrix/serialization.rb
symbolmatrix-1.1.2 lib/symbolmatrix/serialization.rb
symbolmatrix-1.1.1 lib/symbolmatrix/serialization.rb