Module: Qs

Includes:
Test::Unit::Assertions
Defined in:
lib/function/sfunction.rb

Instance Method Summary collapse

Instance Method Details

#cutEndline(text) ⇒ Object

0.0.8



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/function/sfunction.rb', line 93

def cutEndline(text) #0.0.8
	if RUBY_VERSION <= '1.8.6' then
 if text[text.length - 1] < 32 then
		return text[0,text.length - 1]
 else return text[0,text.length]
 end
	else
 if text[text.length - 1] < ' ' then
		return text[0,text.length - 1]
 else return text[0,text.length]
 end
	end
end

#decoder(n) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/function/sfunction.rb', line 3

def decoder(n)
	str = [" ","!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";",
 "<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
 "[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x",
 "y","z","{","|","}","~" ]
	for i in 32..126
 if n == i then return "#{str[i-32]}"
 end
	end
end

#getDir(file, type = 1) ⇒ Object



136
137
138
139
140
141
# File 'lib/function/sfunction.rb', line 136

def getDir(file,type = 1)
	if type == 1 then
 return File.dirname(file).gsub('/', '\\') + "\\"
	else return File.dirname(file).gsub('/', '\\')
	end
end

#getFile(name) ⇒ Object



121
122
123
124
125
# File 'lib/function/sfunction.rb', line 121

def getFile(name)
	if File.exist?(name) then return true
	else return false
	end
end

#getPathExe(default_dir) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/function/sfunction.rb', line 127

def getPathExe(default_dir)
	if ENV['OCRA_EXECUTABLE'].nil?
 root_dir = File.dirname(default_dir).gsub('/', '\\') #0.0.7
	else
 root_dir = File.expand_path(File.dirname(ENV['OCRA_EXECUTABLE'])).gsub('/', '\\')
	end
	return root_dir + "\\"
end

#getRandomString(n, i) ⇒ Object

i=1: 0-9,a-z,A-Z
i=2: -_
i=3: a-z,A-Z
i=4: 0-9
i=41: 0-9
i=5: @domain
i=10: Ho va Ten



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/function/sfunction.rb', line 21

def getRandomString(n,i)
	str = ""

	str1 = ["0","1","2","3","4","5","6","7","8","9",
 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
 "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x",
 "y","z"]

	str2 = ["-","","_",""]

	str3 = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

	str4 = ["0","1","2","3","4","5","6","7","8","9"]
	str41 = ["0","1","2","3","4","5","6","7","8","9","","","","","","","","","",""]

	str5 = ["@yahoo.com.vn","@gmail.com","@yahoo.com","@msn.com","@hotmail.com","@zing.vn","@google.com.vn","@dantri.com",
 "@vnexpress.net","@mail.com","@abc.com","@live.com","@mailinator.com"]

	strHo = ["Nguyen","Dinh","Dang","Huynh","Mai","Tran","Le","Hoang","Pham","Phan","Vu","Bui","Do","Ho","Ngo",
 "Duong","Ly","Vuong","Trinh","Truong","Dinh","Doan","Lam","Phung"]

	strTenDem = ["Thi","Hong","Van","","Duc","Thuy","Ngoc","Ly","Bac","Hien"]

	strTen = ["Trai","Xi","Truc","Tu","Bat","Thanh","Luong","Khuong","Quyen","Quang",
 "Hoang","Ky","Thai","Chinh","Trinh","Kien","Hao","Hung","Quynh","Phuong","Hoa","Hop","Dung","Thang","Van","Tu","Ninh","Vinh","Loc","Khanh","Thuy","Ha",
 "Hang","Lam","Hai","Vu","Na","Duyen","Minh","Tuan","Hien","Anh","An","Be","Binh","Canh"]
	case i
	when i == 1 then
 for i in 1..n
		str = "#{str}#{str1[rand(str1.length)]}"
 end
 return str
	when i == 2 then
 for i in 1..n
		str = "#{str}#{str2[rand(str2.length)]}"
 end
 return str
	when i == 3 then
 for i in 1..n
		str = "#{str}#{str3[rand(str3.length)]}"
 end
 return str
	when i == 4 then
 for i in 1..n
		str = "#{str}#{str4[rand(10)]}"
 end
 return str
	when i == 41 then
 for i in 1..n
		str = "#{str}#{str41[rand(str41.length)]}"
 end
 return str
	when i == 5 then
 for i in 1..n
		str = "#{str}#{str5[rand(str5.length)]}"
 end
 return str
	when i == 10 then
 str = "#{strHo[rand(strHo.length)]} #{strTenDem[rand(strTenDem.length)]} #{strTen[rand(strTen.length)]}"
 return str
	end
end

#randfromto(a, b) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/function/sfunction.rb', line 85

def randfromto(a,b)
	x = rand(b)
	while x < a do
 x = rand(b)
	end
	return x
end

#readExcel(dir, sheet = 1) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/function/sfunction.rb', line 107

def readExcel(dir,sheet=1)
	$excel = WIN32OLE.new("excel.application")
	$excel.visible = true
	$workbook = $excel.workbooks.open(dir)
	$ws=$workbook.worksheets(sheet)
	$workbook = $excel.ActiveWorkbook
end

#saveExcelObject



115
116
117
118
119
# File 'lib/function/sfunction.rb', line 115

def saveExcel
	$workbook.Save
	$workbook.Close
	$excel.Quit
end

#send_Mail_on_Gmail(nickname, pass, to, subject, content) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/function/sfunction.rb', line 143

def send_Mail_on_Gmail(nickname,pass,to,subject,content)
	g = GmailSender.new(nickname, pass)
	g.send(:to => to,
 :subject => subject,
 :content => content,
 :content_type => 'text/html')
end