Class: FormatTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/ModelGenerator/FormatTransformer.rb

Class Method Summary collapse

Class Method Details

.transform(property_type, property_format, json_type, json_formate) ⇒ Object

reverse please exchange property and json position



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ModelGenerator/FormatTransformer.rb', line 4

def FormatTransformer.transform(property_type,property_format,json_type,json_formate)
  property_format = '<#format#>' if  property_format.nil? || property_format.empty?
  json_formate  = '<#format#>' if json_formate.nil? || json_formate.empty?
   if property_type == "string" 
     if json_type == property_type && property_format != json_formate
        return "[NSString stringWithFormat:@\"#{property_format}\",#{$json_var}];"
      elsif json_type=="int"
        if  property_format == '<#format#>' 
          return "[NSString stringWithFormat:@\"%ld\",(long)#{$json_var}];"
        else
          return "[NSString stringWithFormat:@\"#{property_format}\",#{$json_var}];"
        end
      elsif json_type=="double" || json_type=="float"
        if  property_format == '<#format#>' 
          return "[NSString stringWithFormat:@\"%f\",#{$json_var}];"
        else
          return "[NSString stringWithFormat:@\"#{property_format}\",#{$json_var}];"
        end
      elsif json_type=="date"
        return  %Q/NSDateFormatter * formatter=[[NSDateFormatter alloc] init],\\
                      \t\t\t formatter.dateFormat=@\"#{property_format}\",\\
                      \t\t\t  NSDate * date=[formatter stringFromDate:@\"#{$json_var}\"],\\
                      \t\t\t date;/
      else
        return nil
     end
   elsif property_type =="int"
     if json_type == "string" || json_type == "number"
        return "[#{$json_var} integerValue];"
     else 
        return "<#"+"custom"+"#>"
     end
    elsif property_type =="float"
      if json_type == "string" || json_type == "number"
         return "[#{$json_var} floatValue];"
      else 
         return "<#"+"custom"+"#>"
      end
    elsif property_type =="double" || property_type =="time"
      if json_type == "string" || json_type == "number"
         return "[#{$json_var} doubleValue]"
      elsif json_type=="date"
         return "[#{$json_var} timeIntervalSinceReferenceDate];"
      else 
         return "<#"+"custom"+"#>"
      end
    elsif property_type =="date"
      if json_type == "string"
         return %Q/NSDateFormatter * formatter=[[NSDateFormatter alloc] init],\\
                      \t\t\t formatter.dateFormat=@\"#{json_formate}\",\\
                      \t\t\t NSDate * date=[formatter dateFromString:@\"#{$json_var}\"],\\
                      \t\t\t date;/
      elsif json_type=="time" || json_type=="double"
         return " [NSDate dateWithTimeIntervalSinceReferenceDate:#{$json_var}];"
      else 
         return "<#"+"custom"+"#>"
      end
   end
    
end