lib/udgenerator.rb in udgenerator-1.0.4 vs lib/udgenerator.rb in udgenerator-1.0.5

- old
+ new

@@ -19,11 +19,15 @@ end def initialize end def fileRead(fileName) - File.open(fileName, :encoding => Encoding::UTF_8).read.scan(/(.*)\n/).flatten + if (File.exist?(fileName)) then + File.open(fileName, :encoding => Encoding::UTF_8).read.scan(/(.*)\n/).flatten + else + [] + end end def registHeader(register) if (register) "" else @@ -93,18 +97,22 @@ } ' + swift_get_sets(arrType, fileName) + "}\n" end def swift_register_defaults(arrType, fileName, register) if register then - " defaults().registerDefaults([\n" + registers(arrType, fileName) + " ])" + " defaults().registerDefaults(" + registers(arrType, fileName) + ")" else " }\n func registerDefaults(dict: [String: AnyObject]) {\n defaults().registerDefaults(dict)" end end def registers(arrType, fileName) - result = "" - arrType.each_pair{|k, v| result += swift_register_default(k, v, fileName)} - result + if (arrType.count == 0) then + "[:]" + else + result = "" + arrType.each_pair{|k, v| result += swift_register_default(k, v, fileName)} + "[\n#{result} ]" + end end def structs(arrType) result = "" arrType.each_pair{|s, d| result += struct(s) + "\n"} result