class String
Public Instance Methods
ascii()
click to toggle source
# File lib/ckfiles/libs.rb, line 118 def ascii # return only ascii characters in array regex = /[A-Za-z0-9\ \%\;\'\@\~\-\(\)\[\]\&\_\{\}\+\.\/\!\,\#]/ self.scan(regex) end
escape_glob()
click to toggle source
# File lib/ckfiles/libs.rb, line 113 def escape_glob # escape any character that will affect Dir.glob self.gsub(/([\[\]\{\}\*\?\\])/, '\\\\\1') end
not_ascii()
click to toggle source
# File lib/ckfiles/libs.rb, line 124 def not_ascii # return only none ascii characters in array regex = /[^A-Za-z0-9\ \%\;\'\@\~\-\(\)\[\]\&\_\{\}\+\.\/\!\,\#]/ self.scan(regex) end
timelength_to_i()
click to toggle source
translate length of time to integer format e.g. 3m -> 180 (seconds)
# File lib/ckfiles/libs.rb, line 91 def timelength_to_i units = { 'm'=>60, 'h'=>60*60, 'd'=>60*60*24, 'w'=>60*60*24*7, 'mo'=>60*60*24*30, 'y'=>60*60*24*365 } u = 1 n = self.to_f for unit, num in units if self =~ /#{unit}$/i u = num break end end return (u*n).to_i end