Class: String
Overview
Overloads the String class.
Instance Method Summary collapse
-
#diff_ratio(other) ⇒ Float
Calculates the difference ratio (at a word level) between
selfandother. -
#rdiff(other) ⇒ String
Gets the reverse diff between self and str on a word level.
- #recode ⇒ Object
- #recode! ⇒ Object
- #repack ⇒ Object
- #substring?(string) ⇒ Boolean
-
#words(strict = false) ⇒ Array<String>
Returns the words in
self.
Instance Method Details
#diff_ratio(other) ⇒ Float
Calculates the difference ratio (at a word level) between self and other.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/arachni/ruby/string.rb', line 64 def diff_ratio( other ) return 0.0 if self == other s_words = self.words( true ) o_words = other.words( true ) common = (s_words & o_words).size.to_f union = (s_words | o_words).size.to_f (union - common)/union end |
#rdiff(other) ⇒ String
Gets the reverse diff between self and str on a word level.
str = "This is the first test.\nNot really sure what else to put here...\n"
str2 = "This is the second test.\nNot really sure what else to put here...\nBoo-Yah!\n"
str.rdiff( str2 )
# => "This is the test.\nNot really sure what else to put here...\n"
47 48 49 50 51 52 53 54 55 |
# File 'lib/arachni/ruby/string.rb', line 47 def rdiff( other ) return self if self == other # get the words of the first text in an array s_words = words # get what hasn't changed (the rdiff, so to speak) as a string (s_words - (s_words - other.words)).join end |
#recode ⇒ Object
106 107 108 |
# File 'lib/arachni/ruby/string.rb', line 106 def recode dup.recode! end |
#recode! ⇒ Object
102 103 104 |
# File 'lib/arachni/ruby/string.rb', line 102 def recode! encode!( 'utf-16be', invalid: :replace, undef: :replace ).encode("utf-8") end |
#repack ⇒ Object
98 99 100 |
# File 'lib/arachni/ruby/string.rb', line 98 def repack unpack( 'C*' ).pack( 'U*' ) end |
#substring?(string) ⇒ Boolean
89 90 91 92 93 94 95 96 |
# File 'lib/arachni/ruby/string.rb', line 89 def substring?( string ) begin cmatch = match( Regexp.new( Regexp.escape( string ) ) ) cmatch && !cmatch.to_s.empty? rescue nil end end |