string_language 0.0.8 → 0.0.801
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/string_helpers.rb +18 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af94783f6fbd58cc10b4296c9725d8de40934a9f
|
4
|
+
data.tar.gz: 203184262a806d02c44182b2ac783c38a2a5729e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a8c1ee225c009b252a29fb856a58efff43aecb02faba87c5fa80dc6c88dacdc38697eb59f3b631adb4383c30b4580958069f2df6799b85825eb90aaa6d7ba5
|
7
|
+
data.tar.gz: 476e9502c9b4a1852fc75333b385c64d9abd9c1a95c7d24b80b0f05bc4a36e2737abd2b444ad5fcc837feb233ae1f9e5a3a8b9786f057ce432ba044189451a97
|
data/lib/string_helpers.rb
CHANGED
@@ -2,13 +2,23 @@ module StringHelpers
|
|
2
2
|
|
3
3
|
def self.equalize stringA, stringB
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
step1 = equalize_interpunction( stringA, stringB )
|
6
|
+
step2 = equalize_surrounding_space( step1, stringB )
|
7
|
+
step3 = equalize_capitalization( step1, stringB )
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
+
def self.equalize_capitalization stringA, stringB
|
13
|
+
|
14
|
+
if stringB.match( /^[A-Z]/ ) and stringA.match( /^[a-z]/ )
|
15
|
+
|
16
|
+
return stringA.capitalize
|
17
|
+
else
|
18
|
+
return stringA
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
# Return second string, with outer surrounding spacing like first string
|
13
23
|
# @example
|
14
24
|
# space_equally_surrounding( "gnu ", " gnat " ) => " gnu "
|
@@ -24,7 +34,7 @@ module StringHelpers
|
|
24
34
|
|
25
35
|
def self.equalize_interpunction stringA, stringB
|
26
36
|
|
27
|
-
interpunction = "
|
37
|
+
interpunction = "!?.,:;'@|$%^&*-+={()}\/\\\\\#\"\\\[\\\]"
|
28
38
|
regex = /(\s*[#{interpunction}]\s*)/
|
29
39
|
|
30
40
|
splitA = stringA.split( regex ) # "'a' ( bla ) (c )" => ["", "'", "a", "' ", "", "( ", "bla )", " (", "c )"]
|
@@ -46,11 +56,11 @@ module StringHelpers
|
|
46
56
|
end
|
47
57
|
|
48
58
|
# Quick Testing
|
49
|
-
begin
|
50
|
-
a = "(Dit is een, enigzins, wel (test) 'van' de spacing)"
|
51
|
-
b = " ( Deze was niet goed gespaced, en zelfs , zoals ( test) ' van ' dittum) "
|
59
|
+
=begin
|
60
|
+
a = "Hallo (Dit is een, enigzins, wel (test) 'van' de spacing)!"
|
61
|
+
b = "hallo ( Deze was niet goed gespaced, en zelfs , zoals ( test) ' van ' dittum) ! "
|
52
62
|
|
53
63
|
puts "correct: >#{a}<"
|
54
64
|
puts "wrong: >#{b}<"
|
55
65
|
puts "test: >#{StringHelpers::equalize( b, a )}<"
|
56
|
-
end
|
66
|
+
=end
|