class OCModelDefinition

Public Instance Methods

finishTranslate() click to toggle source
# File lib/translate2OC.rb, line 95
def finishTranslate
    replace_file("#{getDirPath}/#{class_name}.h",header)
    replace_file("#{getDirPath}/#{class_name}.m",implementation)
end
header_template() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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