string_language 0.0.804 → 0.0.805

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/string_helpers.rb +38 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42555180e99cd23cc538b43574de5af408648e3f
4
- data.tar.gz: 64b9902acde76918dfaddfd7c1910cdce36732d7
3
+ metadata.gz: 253cfbc45fdd4f0309f1ae9cbe6bf33963fdfd9d
4
+ data.tar.gz: 817e4b02bff7ab9dfdc82ec165a92c6eac762f09
5
5
  SHA512:
6
- metadata.gz: 760f6ba5453d8d483723dfd1847f3dac6e3eff4cdc8249a92ff4278fbab7dea04d3a739071651d53fef55fac8b686d770d84c8831d7ab2ccc7309197644e34d4
7
- data.tar.gz: 5ec0f42d8fac89a0a811b2399a26d21920ba954c1cc86f0f8237d9eabf524268e69358dbdfcad44dc98ce538e6ab8a29ca12b415612cd2c3399d3b4154e02c9e
6
+ metadata.gz: f88abec9c7e00f3a46a35872b462e5a80df1183624582503818661fefe85800193ff8c79478084cc7cc27c034c530c5aed3048bf7017098b2f3efba76b8f7ee2
7
+ data.tar.gz: 47620bd58032d3e9b2717cbc230bc5a6a4ab25c1c673a7333ecf428e38dc3db4512d9b437c8389fa3b8a1432959dd260877e8ec29f2835cb334791608b048dda
@@ -35,27 +35,52 @@ module StringHelpers
35
35
  prefix + middle + suffix
36
36
  end
37
37
 
38
+ # Return stringA with spacing around its interpunction equal to that in StringB
39
+ #
40
+ # @example
41
+ # equalize_interpunction( "A test , succes ! ", "Comma, then exclamation!" ) => "A test, succes!"
42
+ #
38
43
  def self.equalize_interpunction stringA, stringB
39
44
 
40
- interpunction = "!?.,:;'@|$%^&*-+={()}\/\\\\\#\"\\\[\\\]"
41
- regex = /(\s*[#{interpunction}]\s*)/
45
+ punctuation_marks = "!?.,:;'@|$%^&*-+={()}\/\\\\\#\"\\\[\\\]"
46
+ space_mark_space = /(\s*[#{punctuation_marks}]\s*)/
47
+ get_mark = /\s*([#{punctuation_marks}])\s*/
48
+
49
+ splitA = stringA.split( space_mark_space ) # "'a' ( bla ) (c )" => ["", "'", "a", "' ", "", "( ", "bla )", " (", "c )"]
50
+ splitB = stringB.split( space_mark_space )
42
51
 
43
- splitA = stringA.split( regex ) # "'a' ( bla ) (c )" => ["", "'", "a", "' ", "", "( ", "bla )", " (", "c )"]
44
- splitB = stringB.split( regex )
52
+ splitB.each_with_index do |b,indexB|
45
53
 
46
- splitA.each_with_index do |item,index|
54
+ next unless b.match( space_mark_space )
47
55
 
48
- a = splitA[ index ] ; b = splitB[ index ]
49
-
50
- if a != nil and b != nil and a.match( regex ) and b.match( regex )
56
+ markB = b.gsub( get_mark, '\1' );
51
57
 
52
- splitA[ index ] = b
53
- end
58
+ indexA = corresponding_index( splitA, markB, indexB )
59
+
60
+ splitA[ indexA ] = b unless indexA == nil
54
61
  end
55
62
 
56
63
  splitA.join('')
57
64
  end
58
65
 
66
+ private
67
+
68
+ # Return index of string in list that contains given mark. Starting search
69
+ # at start_index. Return nil if search fails.
70
+ def self.corresponding_index( strings, mark, start_index )
71
+
72
+ regexp = /#{Regexp.quote( mark )}/
73
+
74
+ tail = strings[ start_index .. -1 ]
75
+
76
+ return nil if tail == nil
77
+
78
+ tail_index = tail.index { |item| item.match( regexp ) }
79
+
80
+ return nil if tail_index == nil
81
+
82
+ start_index + tail_index
83
+ end
59
84
  end
60
85
 
61
86
  # Quick Testing
@@ -63,6 +88,9 @@ end
63
88
  a = " Hallo (Dit is een, enigzins, wel (test) 'van' de spacing)!"
64
89
  b = " hallo ( Deze was niet goed gespaced, en zelfs , zoals ( test) ' van ' dittum) ! "
65
90
 
91
+ a = "Choose this item if you want to add videos, slideshows and weblinks to the publication."
92
+ b = "Kies dit item als u video's , slideshows en weblinks wilt toe voegen aan de publicatie ."
93
+
66
94
  puts "correct: >#{a}<"
67
95
  puts "wrong: >#{b}<"
68
96
  puts "test: >#{StringHelpers::equalize( b, a )}<"
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.804
4
+ version: 0.0.805
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cornelis Adriaan Schippers