Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/seqtrimnext/utils/recover_mid.rb,
lib/seqtrimnext/utils/string_utils.rb

Instance Method Summary collapse

Instance Method Details

#decamelizeObject



17
18
19
20
21
22
23
24
25
# 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?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
# 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) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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