lib/entityjs/parsers/parse_tmx.rb in entityjs-0.3.0 vs lib/entityjs/parsers/parse_tmx.rb in entityjs-0.3.1
- old
+ new
@@ -1,32 +1,32 @@
module Entityjs
class ParseTMX
def self.parse(data)
+ if data.nil? || data.empty?
+ return '{}'
+ end
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
+ elsif contents['layer'].is_a? Hash
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
+ #transform into strin
+ return ParseXML.parse(contents)
end
def self.parse_layer(k)
+ if k.nil? || k.empty?
+ return
+ end
map = k['data']
#remove encoding
map.delete '@encoding'
#convert csv to array
\ No newline at end of file