Sha256: 346b0adbf32839cbd4a4f1ce361e51a207284e88ed797342b2c066e88ec159a5

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

module Entityjs
  
  class ParseTMX
    
    def self.parse(data)
      
      contents = ParseXML.parse_to_hash(data)
      
      #convert csv map into json array
      if contents['layer'].is_a? Array
        contents['layer'].each do |k|
          self.parse_layer(k)
        end
      else
        self.parse_layer(contents['layer'])
      end
      
      #transform into string
      out = ParseXML.parse(contents)
      
      #transform string-numbers into numbers
      
      out = out.gsub(/"[0-9\.]*"/){|s| s[1..-2] }
      
      return out
    end
    
    def self.parse_layer(k)
      
        map = k['data']
        #remove encoding
        map.delete '@encoding'
        #convert csv to array
        tiles = map['$'].split(",\n")
        k['data']['$'] = tiles.collect{|i| i.split(',').collect{|j| j.to_i }}
      
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
entityjs-0.3.0 lib/entityjs/parsers/parse_tmx.rb