string_swap 0.0.2 → 0.0.3

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: 9a50af63830a3960921631a1f0e3debbe4a0ca4b
4
- data.tar.gz: e84948eb17344d49d7f798ff61801fc0e3bc9f32
3
+ metadata.gz: 1e242f561b57e01a6d5c526644e8fcc1721d5375
4
+ data.tar.gz: 33d46a2133ce495f8abac1c80e03303a8a23da95
5
5
  SHA512:
6
- metadata.gz: bef4fc61e3dc8ac3d34767e290bd5a1058854e63f348f32531fc0e28c5d16979131f9c6687d27f36ad34f38808f271ad7837d137e86f11110cfb5c10795074a5
7
- data.tar.gz: 82c926d5881d3721735e02711b163e292456b77bf12c24c08a951c9c2e9b24e4c46610a55746926e28252a81a7a864ca26f1db3fa17a29e1c1c9c285e5b3f7e1
6
+ metadata.gz: 751b8b6889bcb3eb82e3d05720c8c1cb9e50a1cd137a835b0a10f1e5d7cb9dd35f5e168cb048abde01d255ec0c103623430e9103b7fb2b05334475976ad76ec5
7
+ data.tar.gz: 5d03aaf60b8983600e75952c89d8b0945d0d51026b7ef2cdd21e778047dbeac9365a32525352479ef2496b9ed607ded2e0ec1c3f3d935ce2d494ce86a9f2ba61
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/lib/string_swap.rb CHANGED
@@ -19,12 +19,13 @@ class String
19
19
  end
20
20
 
21
21
  private def swap_two_substrings this, that
22
- opposite = { this => that, that => this }
22
+ opposite = { this => that, that => this, '' => '' }
23
23
  regex = /#{Regexp.escape this}|#{Regexp.escape that}/
24
24
  matches = scan regex
25
25
  between = split regex
26
- matches.zip(between.reverse).map do |match|
27
- opposite[match[0]] + match[1].to_s
26
+ padding = (between.count - matches.count).abs.times.map { '' }
27
+ (matches + padding).zip(between).map do |match|
28
+ match[1].to_s + opposite[match[0]]
28
29
  end.join
29
30
  end
30
31
  end
@@ -1,3 +1,3 @@
1
1
  module StringSwap
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -19,6 +19,10 @@ describe String do
19
19
  expect('this and that, that and this'.swap 'this', 'that').to eq('that and this, this and that')
20
20
  end
21
21
 
22
+ it 'should replace all occurences of one substring with another and vice versa without reordering surrounding text' do
23
+ expect('abc:def:ghi'.swap ':', '/').to eq('abc/def/ghi')
24
+ end
25
+
22
26
  # I'm not quite sure how to test this yet
23
27
  it 'should work without temporarily replacing one of the substrings with a substring that already exists in the string'
24
28
 
data/string_swap.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1"
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_swap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Habib Alamin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-10 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
41
55
  description: This will monkey patch the String class to provide an instance method
42
56
  that swaps two substrings together.
43
57
  email:
@@ -46,6 +60,7 @@ executables: []
46
60
  extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
63
+ - ".gitignore"
49
64
  - Gemfile
50
65
  - LICENSE.txt
51
66
  - README.md
@@ -59,7 +74,7 @@ homepage: https://github.com/habibalamin-gems/string_swap
59
74
  licenses:
60
75
  - MIT
61
76
  metadata: {}
62
- post_install_message:
77
+ post_install_message:
63
78
  rdoc_options: []
64
79
  require_paths:
65
80
  - lib
@@ -74,9 +89,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
89
  - !ruby/object:Gem::Version
75
90
  version: '0'
76
91
  requirements: []
77
- rubyforge_project:
92
+ rubyforge_project:
78
93
  rubygems_version: 2.2.2
79
- signing_key:
94
+ signing_key:
80
95
  specification_version: 4
81
96
  summary: An instance method on String to swap two substrings together.
82
97
  test_files: