class ObjCGenerator::ClassImplementationGenerator
Public Instance Methods
class_implementation(class_name, vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 17 def class_implementation (class_name, vars) incipit = generate_incipit() @import_other_classes = generate_import_other_classes(vars) @init_method = generate_init_method(vars) @init_with_dict_method = generate_init_with_dict_method(vars) @class_init_with_dict = generate_class_init_with_dict(class_name) @to_dict_method = generate_to_dict_method(vars) @is_equals_method = generate_is_equals_method(class_name) @is_equals_to_Object_method = generate_is_equals_to_Object_method(class_name, vars) @description_method = generate_description_method( vars) @copy_method = generate_copy_method( class_name, vars) @hash_method = generate_hash_method( class_name, vars) class_implementation = File.read(template_path('class_implementation')) return incipit + ERB.new(class_implementation).result(binding) end
generate_class_init_with_dict(class_name)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 63 def generate_class_init_with_dict class_name @lowercaseClassName = class_name.dup @lowercaseClassName[0] = @lowercaseClassName[0].chr.downcase template = File.read(template_path('method_class_init_with_dict')) return ERB.new(template).result(binding) end
generate_copy_method(class_name, vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 109 def generate_copy_method(class_name, vars) @lowercaseClassName = class_name.dup @lowercaseClassName[0] = @lowercaseClassName[0].chr.downcase newName = "#{@lowercaseClassName}Copy" @copy_rows = vars.map { |var| var.copyrow(newName) } @copy_rows = ObjCGenerator::vertical_align_vars @copy_rows, /( = )/, 0 @class_name = class_name @varname = newName template = File.read(template_path('method_copy')) return ERB.new(template).result(binding) end
generate_description_method(vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 98 def generate_description_method vars @description_rows = vars.map { |var| "[NSString stringWithFormat:#{var.description_row}]," } @description_rows[-1] = @description_rows[-1][0...-1] @description_rows = ObjCGenerator::vertical_align_vars @description_rows, /( = )/, 0 @description_rows = ObjCGenerator::vertical_align_vars @description_rows, /( , )/, 0 template = File.read(template_path('method_description')) return ERB.new(template).result(binding) end
generate_hash_method(class_name, vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 124 def generate_hash_method(class_name, vars) @hash_rows = vars.map { |var| "#{var.hash_row};" } template = File.read(template_path('method_hash')) return ERB.new(template).result(binding) end
generate_import_other_classes(vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 36 def generate_import_other_classes vars custom_objects = vars.select { | var | var.is_a? TypeCustomObject } custom_objects.inject("") { |mem, var| mem << "#import \"#{var.var_type}.h\"" + "\n"} end
generate_incipit()
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 10 def generate_incipit() author = "Ignazioc" incipit_template = File.read(template_path('incipit')) ERB.new(incipit_template).result(binding) end
generate_init_method(vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 41 def generate_init_method vars @init_rows = vars.map { |var | "_#{var.varname} = #{var.default_value};" } @init_rows = ObjCGenerator::vertical_align_vars @init_rows, /(=)/, 0 init_method = File.read(template_path('method_init')) return ERB.new(init_method).result(binding) end
generate_init_with_dict_method(vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 49 def generate_init_with_dict_method vars @initWithDictRows = vars.map { |var| conversion_type = var.conversion_value("val") "if ((val = dict[@\"#{var.varname}\"])) { _#{var.varname} = #{conversion_type}; } else { NSLog(@\"Error initWithDict: Unable to find: #{var.varname}\"); }" } @initWithDictRows = ObjCGenerator::vertical_align_vars @initWithDictRows, /(\)\))/, 1 @initWithDictRows = ObjCGenerator::vertical_align_vars @initWithDictRows, /( = )/, 2 @initWithDictRows = ObjCGenerator::vertical_align_vars @initWithDictRows, /( } )/, 0 init_with_dict_method = File.read(template_path('method_init_with_dictionary')) return ERB.new(init_with_dict_method).result(binding) end
generate_is_equals_method(class_name)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 81 def generate_is_equals_method class_name @class_name = class_name template = File.read(template_path('method_is_equal')) return ERB.new(template).result(binding) end
generate_is_equals_to_Object_method(class_name, vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 87 def generate_is_equals_to_Object_method (class_name, vars) @class_name = class_name @is_equal_rows = vars.map { |var| "if (#{var.inEquality_test("other")}) return NO;" } @is_equal_rows = ObjCGenerator::vertical_align_vars @is_equal_rows, /( )/, 0 @is_equal_rows = ObjCGenerator::vertical_align_vars @is_equal_rows, /(\) )/, 0 template = File.read(template_path('method_is_equal_to')) return ERB.new(template).result(binding) end
generate_to_dict_method(vars)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 71 def generate_to_dict_method vars @to_ditc_rows = vars.map { |var| var.to_dictionary_item + ","} @to_ditc_rows[-1] = @to_ditc_rows[-1][0...-1] @to_ditc_rows = ObjCGenerator::vertical_align_vars @to_ditc_rows, /( : )/, 0 @to_ditc_rows = ObjCGenerator::vertical_align_vars @to_ditc_rows, /( \?: )/, 0 template = File.read(template_path('method_to_dict')) return ERB.new(template).result(binding) end
template_path(filename)
click to toggle source
# File lib/ObjCGenerator/class_implementation_generator.rb, line 6 def template_path filename File.join(File.expand_path("../..", File.dirname(__FILE__)), "templates/#{filename}.erb") end