class String

Public Instance Methods

decamelize() click to toggle source
# File lib/seqtrimnext/utils/string_utils.rb, line 17
def decamelize 
     self.to_s. 
       gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'). 
       gsub(/([a-z]+)([A-Z\d])/, '\1_\2'). 
       gsub(/([A-Z]{2,})(\d+)/i, '\1_\2'). 
       gsub(/(\d+)([a-z])/i, '\1_\2'). 
       gsub(/(.+?)\&(.+?)/, '\1_&_\2'). 
       gsub(/\s/, '_').downcase 
end
integer?() click to toggle source
# File lib/seqtrimnext/utils/string_utils.rb, line 4
def integer?
                  
  res = true
   
  begin
    r=Integer(self)
  rescue
    res=false
  end
  
  return res
end
lcs(s2) click to toggle source
# File lib/seqtrimnext/utils/recover_mid.rb, line 66
def lcs(s2)
        s1=self
        res="" 
        num=Array.new(s1.size){Array.new(s2.size)}
        len,ans=0
        lastsub=0
        s1.scan(/./).each_with_index do |l1,i |
                s2.scan(/./).each_with_index do |l2,j |
                  unless l1==l2
                    num[i][j]=0
                  else
                    (i==0 || j==0)? num[i][j]=1 : num[i][j]=1 + num[i-1][j-1]
                    if num[i][j] > len
                      len = ans = num[i][j]
                      thissub = i
                      thissub -= num[i-1][j-1] unless num[i-1][j-1].nil?  
                      if lastsub==thissub
                        res+=s1[i,1]
                      else
                        lastsub=thissub
                        res=s1[lastsub, (i+1)-lastsub]
                      end
                    end
                  end
                end
        end
        res
end