Module: KaveRestApi::StringHelper

Included in:
String
Defined in:
lib/kave_rest_api/helpers/convertor.rb,
lib/kave_rest_api/helpers/validator.rb

Instance Method Summary collapse

Instance Method Details

#ctpdObject



16
17
18
# File 'lib/kave_rest_api/helpers/convertor.rb', line 16

def ctpd
    return self.to_s.tr('01123456789,','۰١۱۲۳۴۵۶۷۸۹،')
end

#ctsdObject



12
13
14
# File 'lib/kave_rest_api/helpers/convertor.rb', line 12

def ctsd
    return self.to_s.tr('۰١۱۲۳۴۵۶۷۸۹،١٢٣٤٥٦٧٨٩٠','01123456789,1234567890')
end

#is_phone?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/kave_rest_api/helpers/validator.rb', line 17

def is_phone?
    return !!self.ctsd.match(/^(09{1})+([1-3]{1})+(\d{8})$/)
end

#multibyte?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/kave_rest_api/helpers/validator.rb', line 13

def multibyte?
  chars.count < bytes.count
end

#strip_emojiObject



20
21
22
23
24
25
26
27
# File 'lib/kave_rest_api/helpers/convertor.rb', line 20

def strip_emoji
   str = self.force_encoding('utf-8').encode
		arr_regex=[/[\u{1f600}-\u{1f64f}]/,/[\u{2702}-\u{27b0}]/,/[\u{1f680}-\u{1f6ff}]/,/[\u{24C2}-\u{1F251}]/,/[\u{1f300}-\u{1f5ff}]/]
		arr_regex.each do |regex|
			str = str.gsub regex, ''
		end
		return str
end