Class: Udgenerator::Swift

Inherits:
Object
  • Object
show all
Defined in:
lib/udgenerator/swift.rb

Instance Method Summary collapse

Instance Method Details

#object(type) ⇒ Object



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
# File 'lib/udgenerator/swift.rb', line 21

def object(type)
	if "NSString" == type
		NSString.new()
	elsif "String" == type
		NSString.new()
	elsif "NSNumber" == type
		NSNumber.new()
	elsif "NSArray" == type
		NSArray.new()
	elsif "NSDictionary" == type
		NSDictionary.new()
	elsif "NSData" == type
		NSData.new()
	elsif "NSDate" == type
		NSDate.new()
	elsif "Bool" == type
		NSBOOL.new()
	elsif "Int" == type
		NSInteger.new()
	elsif "Double" == type
		NSDouble.new()
	elsif "Float" == type
		NSFloat.new()
	else
		AnyObject.new("#{type}")
	end
end

#parse(arrStr) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/udgenerator/swift.rb', line 4

def parse(arrStr)
	result = {}
	arrStr.each{|s|
		if /\s*(\w+) *\* *(\w+)\s*;\s*/ =~ s then
			result[$2] = object($1)
		elsif /- \((\w+) *\* *\)(\w+);/ =~ s then
			result[$2] = object($1)
		elsif /\s*func\s+(\w+)\(\s*\)\s*->\s*(\w+)\s*\{?\s*/ =~ s then 
			result[$1] = object($2)
		elsif /\s*(var|let)\s+(\w+)\s*:\s*(\w+)\??\s*;?\s*/ =~ s then 
			result[$2] = object($3)
		end
	}
	result.delete("sharedManager")
	result.delete("defaults")
	result
end