module Struggle::StringExtend
Public Instance Methods
htmlClear()
click to toggle source
# File lib/struggle/concerns/string_extend.rb, line 3 def htmlClear self.gsub(/<script.*?<\/script>/, "").gsub(/<iframe.*?<\/iframe>/, "") end
isCn()
click to toggle source
# File lib/struggle/concerns/string_extend.rb, line 7 def isCn (self=~/[\u4e00-\u9fa5]/).nil? ? false : true end
isCnOrEn()
click to toggle source
# File lib/struggle/concerns/string_extend.rb, line 11 def isCnOrEn (self=~/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/).nil? ? false : true end
truncate(length = 30, truncate_string = "...")
click to toggle source
# File lib/struggle/concerns/string_extend.rb, line 15 def truncate(length = 30, truncate_string = "...") l=0 char_array=self.unpack("U*") char_array.each_with_index do |c, i| l = l+ (c<127 ? 0.5 : 1) if l>=length return char_array[0..i].pack("U*")+(i<char_array.length-1 ? truncate_string : "") end end return self end