string_language 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49ed3266f212bed603081b98b6fa0112fd2cdec6
4
- data.tar.gz: e955dfed0e10938a089254621dc6449d64094206
3
+ metadata.gz: a7f79d274fd5b4e0c819b7390b8aa6f29fa0cdd6
4
+ data.tar.gz: 61b51ec3f63a8ac7b9ee1b49718ca300f5e06c41
5
5
  SHA512:
6
- metadata.gz: d110dc727ee65999c5fd31b3931689915801e25b048ff0d7a1fa06b68e4545c8fb6747cb1a34b71e4944c9669a33a9d54e2dbba83dcf45db1d39f90a7a6cf922
7
- data.tar.gz: dfb0de7569f2bcffd2cc039b8c52b7407d36b25806e911f9f342c7fae4f25216acd1dec7b508e695a309b4e57688b4450430c4ba5a219cd154de7a0fb534f12d
6
+ metadata.gz: f7001e8ced170b53e154b3054203d36aea7aea5112311e2fbbc6d2d409e7a4b93cc654c63740d1f8fc040ea87057b331e5c04e7c72d12151f2ed5432132a580f
7
+ data.tar.gz: e80b05c84923311e90992767cac8982d34b33db9113b3373c1a5cba8079667afe99b53ebf0fa3f021b21fcc9503520aca83373894d16c2a0252c6bcbfd49984d
@@ -24,7 +24,7 @@ class GoogleTranslator
24
24
  ask_google
25
25
 
26
26
  # return the untranslated input when it is translated to white space only
27
- self.output = translation.match( /^\s*$/ ) ? input : StringHelpers::space_equally( translation, input )
27
+ self.output = translation.match( /^\s*$/ ) ? input : StringHelpers::equalize( translation, input )
28
28
  end
29
29
 
30
30
  def language input
@@ -75,9 +75,9 @@ class GoogleTranslator
75
75
  end
76
76
 
77
77
  # Quick Testing
78
- begin
78
+ =begin
79
79
  english = "'none' and 'ad' Articles"
80
80
  translator = GoogleTranslator.new
81
81
  translation = translator.translate english, 'en', 'nl'
82
82
  puts translation
83
- end
83
+ =end
@@ -1,12 +1,10 @@
1
1
  module StringHelpers
2
2
 
3
- # Make the spacing around the i-th bracket/qoute in stringA equal to that around
4
- # the i-th bracket/quote in stringB
5
- def self.space_equally stringA, stringB
3
+ def self.equalize stringA, stringB
6
4
 
7
- intermediateA = space_equally_quotes_and_brackets( stringA, stringB )
5
+ intermediateA = equalize_interpunction( stringA, stringB )
8
6
 
9
- space_equally_surrounding( intermediateA, stringB )
7
+ equalize_surrounding_space( intermediateA, stringB )
10
8
  end
11
9
 
12
10
  private
@@ -15,7 +13,7 @@ module StringHelpers
15
13
  # @example
16
14
  # space_equally_surrounding( "gnu ", " gnat " ) => " gnu "
17
15
  #
18
- def self.space_equally_surrounding stringA, stringB
16
+ def self.equalize_surrounding_space stringA, stringB
19
17
 
20
18
  prefix = stringB.match( /^\s*/ )[0]
21
19
  suffix = stringB.match( /\s*$/ )[0]
@@ -24,49 +22,35 @@ module StringHelpers
24
22
  prefix + middle + suffix
25
23
  end
26
24
 
27
- def self.space_equally_quotes_and_brackets stringA, stringB
25
+ def self.equalize_interpunction stringA, stringB
28
26
 
29
- brackets_and_quotes = "{(\['\"\])}"
30
- regex = /(\s*[#{brackets_and_quotes}]\s*)/
27
+ interpunction = ".,:;'@|$%^&*-+={()}\/\\\\\#\"\\\[\\\]"
28
+ regex = /(\s*[#{interpunction}]\s*)/
31
29
 
32
30
  splitA = stringA.split( regex ) # "'a' ( bla ) (c )" => ["", "'", "a", "' ", "", "( ", "bla )", " (", "c )"]
33
31
  splitB = stringB.split( regex )
34
32
 
35
- i=0; while space_ith_match( splitA, splitB, regex, i ) do ; i+=1 ; end
33
+ splitA.each_with_index do |item,index|
36
34
 
37
- splitA.join('')
38
- end
39
-
40
- def self.space_ith_match listA, listB, regex, i
35
+ a = splitA[ index ] ; b = splitB[ index ]
36
+
37
+ if a != nil and b != nil and a.match( regex ) and b.match( regex )
41
38
 
42
- matchA, indexA = *ith_match( listA, regex, i )
43
- matchB, indexB = *ith_match( listB, regex, i )
39
+ splitA[ index ] = b
40
+ end
41
+ end
44
42
 
45
- return false if (matchA == nil or matchB == nil)
46
-
47
- listA[ indexA ] = space_equally_surrounding( listA[ indexA ], listB[ indexB ] )
43
+ splitA.join('')
48
44
  end
49
45
 
50
- def self.ith_match list, regex, i
51
-
52
- count = 0
53
-
54
- list.each_with_index do |item,index|
55
-
56
- count+=1 if item.match( regex )
57
- return [item,index] if count == i
58
- end
59
-
60
- return [nil,nil]
61
- end
62
46
  end
63
47
 
64
48
  # Quick Testing
65
- =begin
66
- a = "(Dit is een (test) 'van' de spacing)"
67
- b = "( Deze was niet goed gespaced, zoals ( test) ' van ' dittum)"
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) "
68
52
 
69
53
  puts "correct: >#{a}<"
70
54
  puts "wrong: >#{b}<"
71
- puts "test: >#{StringHelpers::space_equally( b, a )}<"
72
- =end
55
+ puts "test: >#{StringHelpers::equalize( b, a )}<"
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_language
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cornelis Adriaan Schippers