Class: OCModelDefinition

Inherits:
ModelDefinition show all
Defined in:
lib/translate2OC.rb

Instance Attribute Summary

Attributes inherited from ModelDefinition

#configHash, #context

Instance Method Summary collapse

Methods inherited from ModelDefinition

#class_name, getModelDefinition, #header, #implementation, #initialize, #processTranslate, #setcontext, #startTranslate

Constructor Details

This class inherits a constructor from ModelDefinition

Instance Method Details

#finishTranslateObject



95
96
97
98
# File 'lib/translate2OC.rb', line 95

def finishTranslate
    replace_file("#{getDirPath}/#{class_name}.h",header)
    replace_file("#{getDirPath}/#{class_name}.m",implementation)
end

#header_templateObject



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 header_template
  template = <<-EOS
#import <Foundation/Foundation.h>
<%- if context.headers_str -%>
<%= context.headers_str %>
<%- end -%>

<%- if context.enums_str -%>
<%= context.enums_str %>
<%- end -%>

@interface <%= context.class_name %> : NSObject
<% context.properties.each do |prop| -%>
<%= property_definition(true, prop) %>
<% end -%>
@end
EOS
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_templateObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/translate2OC.rb', line 81

def implementation_template
    template = <<-EOS
#import "<%= context.class_name %>.h"
#import "VideoConfigCacheMgr.h"

@implementation <%= context.class_name %>
<% context.properties.each do |prop| -%>
<%= propterty_getterGenerator(prop) %>
<% end -%>
@end
EOS
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(@"#{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