Class: OCModelDefinition
Instance Attribute Summary
#configHash, #context
Instance Method Summary
collapse
#class_name, getModelDefinition, #header, #implementation, #initialize, #processTranslate, #setcontext, #startTranslate
Instance Method Details
#finishTranslate ⇒ Object
95
96
97
98
|
# File 'lib/translate2OC.rb', line 95
def finishTranslate
replace_file("#{getDirPath}/#{class_name}.h",)
replace_file("#{getDirPath}/#{class_name}.m",implementation)
end
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/translate2OC.rb', line 62
def
template = "#import <Foundation/Foundation.h>\n<%- if context.headers_str -%>\n<%= context.headers_str %>\n<%- end -%>\n\n<%- if context.enums_str -%>\n<%= context.enums_str %>\n<%- end -%>\n\n@interface <%= context.class_name %> : NSObject\n<% context.properties.each do |prop| -%>\n<%= property_definition(true, prop) %>\n<% end -%>\n@end\n"
end
|
#implementation_body(property) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/translate2OC.rb', line 26
def implementation_body(property)
case property
when String
return "getStringForKey:"
when TrueClass,FalseClass
return "getBoolForKey:"
when Float
return "getFloatForKey:"
when Fixnum
return "getInt32ForKey:"
when Bignum
return "getInt64ForKey:"
else
end
end
|
#implementation_template ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/translate2OC.rb', line 81
def implementation_template
template = "#import \"<%= context.class_name %>.h\"\n#import \"VideoConfigCacheMgr.h\"\n\n@implementation <%= context.class_name %>\n<% context.properties.each do |prop| -%>\n<%= propterty_getterGenerator(prop) %>\n<% end -%>\n@end\n"
end
|
#property_definition(readonly, args) ⇒ Object
6
7
8
|
# File 'lib/translate2OC.rb', line 6
def property_definition(readonly, args)
property_str = "@property(nonatomic,readonly,class)#{property_type(args[1])} #{args[0]}; "
end
|
#property_instance(args) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/translate2OC.rb', line 53
def property_instance(args)
property_value = args[1]
if String === args[1]
property_value = %Q(@"#{property_value}")
end
instance = "#{property_type(args[1])} _#{args[0]} = #{property_value};"
end
|
#property_type(property) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/translate2OC.rb', line 10
def property_type(property)
case property
when String
return "NSString *"
when TrueClass,FalseClass
return "BOOL"
when Float
return "float"
when Fixnum
return "int"
when Bignum
return "long long"
else
end
end
|
#propterty_getterGenerator(args) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/translate2OC.rb', line 42
def propterty_getterGenerator(args)
property_value = %Q(@"#{context.class_name}_#{args[0]}")
default_Value = args[1]
if String === args[1]
default_Value = %Q(@"#{default_Value}")
end
getter = "\n+(#{property_type(args[1])})#{args[0]} {
return [VideoConfigCacheMgr #{implementation_body(args[1])}:#{property_value} defaultValue:#{default_Value}];
}\n"
end
|