finishing_moves 0.20 → 1.0

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: e4efbdd6bdfc892e6ae09dc64b5617da8413ccf3
4
- data.tar.gz: 340d5694613b94e1d7d3cea866d75e47525f1c64
3
+ metadata.gz: d37ca4693b6a2a3120e8ee286ab7d201e489473b
4
+ data.tar.gz: 71f81d5815febb3bd3944fbd74c8ba374afd37bd
5
5
  SHA512:
6
- metadata.gz: ac8ce0578d278efa3b827aa7694e858bf1ff8cc2528af711a75da099aa0edf05aef6c126222c902796fe94a662ee01efc0600070a58b28001525bd20c8d27cdb
7
- data.tar.gz: b0b454beb0eb14676f4100e01ef03cf4ce01b9d5b57f8b99a9a3f9e6648aa844b69c88e7009559ac52ffc300a33c86acdd32c4264f6bcea27d3330a96a50a592
6
+ metadata.gz: e0cdbe53527bf2fb84106d50768ef3c28e630b81ba28bdb58f1f8aaa3cda1e5792165e95127b4ceda23a49119ba8f0116369ee16a1b9d69fc750d0a294d2f93a
7
+ data.tar.gz: b6afe08d894be6a022974b0859bd36d41d5de628e62be9c0df015f90e10c804d2df93fba445c06445251c015aa6d5738dfd53505cf56ffefbd4ebb8c1e7c8d48
@@ -8,6 +8,7 @@ rvm:
8
8
  - 2.2.0
9
9
  - 2.3.0
10
10
  - 2.4.0
11
+ - 2.5.0
11
12
  - ruby-head
12
13
 
13
14
  script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Finishing Moves
2
2
  [![Gem Version](https://badge.fury.io/rb/finishing_moves.svg)](https://rubygems.org/gems/finishing_moves)
3
- [![Build Status](https://travis-ci.org/forgecrafted/finishing_moves.svg?branch=master)](https://travis-ci.org/forgecrafted/finishing_moves)
4
- [![Coverage Status](https://coveralls.io/repos/forgecrafted/finishing_moves/badge.svg?branch=master)](https://coveralls.io/r/forgecrafted/finishing_moves?branch=master)
3
+ [![Build Status](https://travis-ci.org/BattleBrisket/rails-force-reload.svg?branch=master)](https://travis-ci.org/BattleBrisket/rails-force-reload)
5
4
 
6
5
  Ruby includes a huge amount of default awesomeness that tackles most common development challenges. But every now and then, you find yourself performing contortions to achieve results that, honestly, **should feel more natural** given the language's design elegance. Finishing Moves is a collection of methods designed to assist in those "why is this awkward?" scenarios.
7
6
 
@@ -26,6 +25,8 @@ gem install 'finishing_moves'
26
25
  - [`Array#to_hash_values`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_hash_values) :boom:
27
26
  - [`Array#to_indexed_hash`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_indexed_hash)
28
27
  - [`Array#to_hash_keys`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_hash_keys)
28
+ - [`Array#to_sym`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym)
29
+ - [`Array#to_sym_soft`](https://github.com/forgecrafted/finishing_moves/wiki/Array#arrayto_sym_soft)
29
30
  - [`Enumerable#key_map`](https://github.com/forgecrafted/finishing_moves/wiki/Enumerable#enumerablekey_map) :boom:
30
31
  - [`Enumerable#key_map_reduce`](https://github.com/forgecrafted/finishing_moves/wiki/Enumerable#enumerablekey_map_reduce)
31
32
  - [`Hash#delete!`](https://github.com/forgecrafted/finishing_moves/wiki/Hash#hashdelete)
@@ -58,10 +59,10 @@ gem install 'finishing_moves'
58
59
  - [`String#replace_whitespace`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringreplace_whitespace)
59
60
  - [`String#strip_all`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringstrip_all) :boom:
60
61
 
61
- *Multi-class logic enhancements*
62
+ *Multi-class enhancement*
62
63
 
63
- - ~Fiscal Calendar Calculations~ Moved to its own gem! [Check out Fiscally.](https://github.com/forgecrafted/fiscally)
64
64
  - [Boolean Typecasting](https://github.com/forgecrafted/finishing_moves/wiki/Boolean-Typecasting)
65
+ - ~Fiscal Calendar Calculations~ Moved to its own gem! [Check out Fiscally.](https://github.com/forgecrafted/fiscally)
65
66
 
66
67
  ### Ruby Version
67
68
 
@@ -73,7 +74,6 @@ Tested against **`2.0.0` and above**. Probably works in `1.9.3`.
73
74
  - Follow the Unix philosophy of *"Do one job really well."*
74
75
  - Minimize assumptions, e.g. avoid formatting output, mutating values, and conditional logic flows.
75
76
  - Play nice with major Ruby players like Rake, Rails, and Sinatra.
76
- - Never duplicate existing methods from Rails and the like.
77
77
  - Test all the things.
78
78
 
79
79
  ## Bug Reports
@@ -27,13 +27,38 @@ class Array
27
27
  end
28
28
  alias_method :to_hash_as_keys, :to_hash_keys
29
29
 
30
- # remove all nil's and empty strings
31
- def crush
32
- reject { |item| item.nil? || bool_chain{item.strip.empty?} }
30
+ def to_sym
31
+ map { |x| x.to_sym }
33
32
  end
33
+ alias_method :to_sym_hard, :to_sym
34
34
 
35
- def crush!
36
- reject! { |item| item.nil? || bool_chain{item.strip.empty?} }
35
+ def to_sym!
36
+ map! { |x| x.to_sym }
37
+ end
38
+ alias_method :to_sym_hard!, :to_sym!
39
+
40
+ def to_sym_soft
41
+ map do |x|
42
+ begin
43
+ x.to_sym
44
+ rescue NoMethodError => e
45
+ x
46
+ rescue Exception
47
+ raise
48
+ end
49
+ end
50
+ end
51
+
52
+ def to_sym_soft!
53
+ map! do |x|
54
+ begin
55
+ x.to_sym
56
+ rescue NoMethodError => e
57
+ x
58
+ rescue Exception
59
+ raise
60
+ end
61
+ end
37
62
  end
38
63
 
39
64
  end
@@ -24,13 +24,4 @@ class Hash
24
24
  return self
25
25
  end
26
26
 
27
- # remove all nil's and empty strings
28
- def crush
29
- reject { |item| item.nil? || bool_chain{item.strip.empty?} }
30
- end
31
-
32
- def crush!
33
- reject! { |item| item.nil? || bool_chain{item.strip.empty?} }
34
- end
35
-
36
27
  end
@@ -1,3 +1,3 @@
1
1
  module FinishingMoves
2
- VERSION = "0.20"
2
+ VERSION = "1.0"
3
3
  end
@@ -99,6 +99,48 @@ describe Array do
99
99
  end
100
100
  end
101
101
 
102
+ it '#to_sym' do
103
+ test = ['FOO', 'bar', :baz]
104
+ expect(test.to_sym).to eq [:FOO, :bar, :baz]
105
+ expect(test).to eq ['FOO', 'bar', :baz]
106
+ expect{ [1].to_sym }.to raise_error NoMethodError
107
+ # FinishingMoves::FalseClass#to_sym
108
+ expect([false].to_sym).to eq [:false]
109
+ end
110
+
111
+ it '#to_sym!' do
112
+ test = ['FOO', 'bar', :baz]
113
+ expect(test.to_sym!).to eq [:FOO, :bar, :baz]
114
+ expect(test).to eq [:FOO, :bar, :baz]
115
+ expect{ [1].to_sym! }.to raise_error NoMethodError
116
+ end
117
+
118
+ it '#to_sym_hard' do
119
+ test = ['FOO', 'bar', :baz]
120
+ expect(test.to_sym_hard).to eq [:FOO, :bar, :baz]
121
+ expect(test).to eq ['FOO', 'bar', :baz]
122
+ expect{ [1].to_sym_hard }.to raise_error NoMethodError
123
+ end
124
+
125
+ it '#to_sym_hard!' do
126
+ test = ['FOO', 'bar', :baz]
127
+ expect(test.to_sym_hard!).to eq [:FOO, :bar, :baz]
128
+ expect(test).to eq [:FOO, :bar, :baz]
129
+ expect{ [1].to_sym_hard! }.to raise_error NoMethodError
130
+ end
131
+
132
+ it '#to_sym_soft' do
133
+ test = ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
134
+ expect(test.to_sym_soft).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
135
+ expect(test).to eq ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
136
+ end
137
+
138
+ it '#to_sym_soft!' do
139
+ test = ['FOO', 'bar', :baz, 1, {bat: 'bat'}, /hay/]
140
+ expect(test.to_sym_soft!).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
141
+ expect(test).to eq [:FOO, :bar, :baz, 1, {bat: 'bat'}, /hay/]
142
+ end
143
+
102
144
  end
103
145
 
104
146
  class SageElements
@@ -1,259 +1,259 @@
1
- require 'spec_helper'
2
-
3
- describe String do
4
-
5
- it '#dedupe' do
6
- expect('___foo___'.dedupe('_')).to eq '_foo_'
7
- expect('---foo---'.dedupe('-')).to eq '-foo-'
8
- expect('___foo---'.dedupe('_-')).to eq '_foo-'
9
- expect('___foo__bar_baz--bing'.dedupe('_')).to eq '_foo_bar_baz--bing'
10
- expect('foo'.dedupe('o')).to eq 'fo'
11
- expect('foo'.dedupe('O')).to eq 'foo'
12
- expect('[[foo]]]'.dedupe('[]')).to eq '[foo]'
13
- expect('/crazy//concatenated////file/path'.dedupe('/')).to eq '/crazy/concatenated/file/path'
14
-
15
- # make sure our use of gsub! isn't screwing us over
16
- orig = '___foo___'
17
- modified = orig.dedupe('_')
18
- expect(modified).to eq '_foo_'
19
- expect(orig).to eq '___foo___'
20
- end
21
-
22
- it '#dedupe!' do
23
- str = '___foo___'
24
- str.dedupe!('_')
25
- expect(str).to eq '_foo_'
26
- end
27
-
28
- it '#strip_all (incl _strip_all_prep)' do
29
- expect('___foo___'.strip_all).to eq 'foo'
30
- expect('---foo---'.strip_all).to eq 'foo'
31
- expect('-_-foo-_-'.strip_all).to eq 'foo'
32
- expect('_-_8-foo-8_-_'.strip_all).to eq '8-foo-8'
33
- expect('0123456789-foo-9876543210'.strip_all('0-9')).to eq '-foo-'
34
- expect('0123-foo-3210'.strip_all('0-9-')).to eq 'foo'
35
- expect('0123-foo-3210'.strip_all('a-z')).to eq '0123-foo-3210'
36
- expect('foo-314-foo'.strip_all('a-z')).to eq '-314-'
37
- expect('foo-314-foo'.strip_all('a-z-')).to eq '314'
38
- expect('foo-314-foo'.strip_all('A-Z')).to eq 'foo-314-foo'
39
- expect('FOO-314-FOO'.strip_all('A-Z')).to eq '-314-'
40
- expect('FOO 314 FOO'.strip_all('A-Z')).to eq '314'
41
-
42
- expect('abcdefghijklmnopqrstuvwxyz'.strip_all('a-z')).to eq ''
43
- expect('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.strip_all('A-Z')).to eq ''
44
- expect('ABCDEFGHIJKLM FOO NOPQRSTUVWXYZ'.strip_all('A-Z')).to eq ''
45
-
46
- expect('000000'.strip_all('0')).to eq ''
47
- expect('[[000]]'.strip_all('[0]')).to eq ''
48
- expect('. $ ^ { [ ( | ) * + ? \ '.strip_all('. $ ^ { [ ( | ) * + ? \ ')).to eq ''
49
- expect('/[a|valid|regex]+/'.strip_all('/[]+')).to eq 'a|valid|regex'
50
-
51
- expect('_1 0__spaces_incl__0 1_'.strip_all('0-9_')).to eq 'spaces_incl'
52
- expect(' _spaces_incl_ '.strip_all).to eq 'spaces_incl'
53
-
54
- expect("__'''foo__'".strip_all('_\'') ).to eq 'foo'
55
- expect('abcdefghijklm foo123 nopqrstuvwxyz'.strip_all('a-z0-9')).to eq ''
56
- expect('hello world'.strip_all('a-z')).to eq ''
57
-
58
- expect{'bad call'.strip_all(101)}.to raise_error(ArgumentError)
59
- end
60
-
61
- it '#strip_all!' do
62
- str = '___foo___'
63
- str.strip_all!
64
- expect(str).to eq 'foo'
65
- end
66
-
67
- it '#lstrip_all' do
68
- expect('___foo___'.lstrip_all).to eq 'foo___'
69
- end
70
-
71
- it '#lstrip_all!' do
72
- str = '___foo___'
73
- str.lstrip_all!
74
- expect(str).to eq 'foo___'
75
- end
76
-
77
- it '#rstrip_all' do
78
- expect('___foo___'.rstrip_all).to eq '___foo'
79
- end
80
-
81
- it '#rstrip_all!' do
82
- str = '___foo___'
83
- str.rstrip_all!
84
- expect(str).to eq '___foo'
85
- end
86
-
87
- it '#match?' do
88
- expect('hello'.match?('he')).to be true
89
- expect('hello'.match?('he', 1)).to be false
90
- expect('hello'.match?('o')).to be true
91
- expect('hello'.match?('ol')).to be false
92
- expect('hello'.match?('(.)')).to be true
93
- expect('hello'.match?(/(.)/)).to be true
94
- expect('hello'.match?('xx')).to be false
95
- end
96
-
97
- it '#remove_whitespace' do
98
- expect(' a b c d e'.remove_whitespace).to eq 'abcde'
99
- expect(' [ foo ] '.remove_whitespace).to eq '[foo]'
100
- expect(' '.remove_whitespace).to eq ''
101
- expect('. $ ^ { [ ( | ) * + ? \ '.remove_whitespace).to eq '.$^{[(|)*+?\\'
102
- expect('a b c d e'.remove_whitespace('+')).to eq 'abcde'
103
- expect('a b c d e'.remove_whitespace('+')).to eq 'abcde'
104
- expect('a b c d e'.remove_whitespace('__')).to eq 'abcde'
105
- end
106
-
107
- it '#remove_whitespace!' do
108
- str = ' a b c d e'
109
- str.remove_whitespace!
110
- expect(str).to eq 'abcde'
111
- end
112
-
113
- it '#replace_whitespace' do
114
- expect(' a b c d e'.replace_whitespace).to eq 'abcde'
115
- expect('a b c d e'.replace_whitespace('+')).to eq 'a+b+c+d+e'
116
- expect('a b c d e'.replace_whitespace('+')).to eq 'a++b+c+d+e'
117
- expect('a b c d e'.replace_whitespace('__')).to eq 'a__b__c__d__e'
118
- end
119
-
120
- it '#replace_whitespace!' do
121
- str = 'a b c d e'
122
- str.replace_whitespace!('-')
123
- expect(str).to eq 'a-b-c-d-e'
124
- end
125
-
126
- it '#nl2br' do
127
- expect("\n".nl2br).to eq "<br />\n"
128
- expect("\n\r".nl2br).to eq "<br />\n"
129
- expect("\r\n".nl2br).to eq "<br />\n"
130
- expect("\n\r\n".nl2br).to eq "<br />\n<br />\n"
131
- expect("\r\n\r\n".nl2br).to eq "<br />\n<br />\n"
132
- expect("\r\r\n".nl2br).to eq "<br />\n<br />\n"
133
- expect("\r\r".nl2br).to eq "<br />\n<br />\n"
134
- expect("\n\r\r".nl2br).to eq "<br />\n<br />\n"
135
-
136
- expect("Let's play Global Thermonuclear War.\n\r".nl2br).to eq "Let's play Global Thermonuclear War.<br />\n"
137
- expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".nl2br).
138
- to eq "A strange game.<br />\n<br />\nThe only winning move is not to play.<br />\nHow about a nice game of chess?<br />\n"
139
- end
140
-
141
- it "#newline_to" do
142
- expect("\n".newline_to).to eq " "
143
- expect("\n\r".newline_to).to eq " "
144
- expect("\r\n".newline_to).to eq " "
145
- expect("\n\r\n".newline_to).to eq " "
146
- expect("\r\n\r\n".newline_to).to eq " "
147
- expect("\r\r\n".newline_to).to eq " "
148
- expect("\r\r".newline_to).to eq " "
149
- expect("\n\r\r".newline_to).to eq " "
150
-
151
- # replacements should end up as strings
152
- expect("\n".newline_to(:bar)).to eq 'bar'
153
- expect("\n\n".newline_to('+')).to eq '++'
154
- expect("\n\n".newline_to(0)).to eq '00'
155
- expect("\n\n".newline_to(true)).to eq 'truetrue'
156
-
157
- # should return a modified object, leaving original intact
158
- newline = "\n"
159
- bar = newline.newline_to(:bar)
160
- expect(newline).to eq "\n"
161
- expect(bar).to eq 'bar'
162
-
163
- expect("Let's play Global Thermonuclear War.\n\r".newline_to).to eq "Let's play Global Thermonuclear War. "
164
- expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".newline_to).
165
- to eq "A strange game. The only winning move is not to play. How about a nice game of chess? "
166
- end
167
-
168
- it "#newline_to!" do
169
- var = "\n"
170
- var.newline_to! :foo
171
- expect(var).to eq 'foo'
172
- end
173
-
174
- keyify_sets = [
175
- [Integer, :integer],
176
- [Math::DomainError, :math_domain_error],
177
- ['FooBarBaz', :foo_bar_baz],
178
- [:FooBarBaz, :foo_bar_baz],
179
- ["Foo-Bar'Baz", :foo_bar_baz],
180
- ['(Foo*&Bar!Baz?', :foo_bar_baz],
181
- ['1234FooBAR', :foo_bar],
182
- ['!@#$Foo0987', :foo0987],
183
- ["Bill O'Shea", :bill_o_shea],
184
- ["Bill O Shea", :bill_o_shea],
185
- ["Bill O Shea", :bill_o_shea],
186
- ]
187
-
188
- it '#keyify' do
189
- keyify_sets.each do |set|
190
- inc, out = set
191
- expect(inc.keyify).to eq out
192
- end
193
- expect('!@#$%^'.keyify).to eq nil
194
- expect('12345678'.keyify).to eq nil
195
- # make sure we're not performing in place
196
- str = 'FooBarBaz'
197
- expect(str.keyify).to eq :foo_bar_baz
198
- expect(str).to eq 'FooBarBaz'
199
- # should work on frozen values
200
- expect('FooBarBaz'.freeze.keyify).to eq :foo_bar_baz
201
- end
202
-
203
- it '#keyify!' do
204
- keyify_sets.each do |set|
205
- inc, out = set
206
- expect(inc.keyify!).to eq out
207
- end
208
- expect{ '!@#$%^'.keyify! }.to raise_error(ArgumentError)
209
- expect{ '12345678'.keyify! }.to raise_error(ArgumentError)
210
- end
211
-
212
- it "dedupe + remove_whitespace" do
213
- expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '12345'
214
- expect('1 2 3 4 5'.dedupe(' ').replace_whitespace('+')).to eq '1+2+3+4+5'
215
- end
216
-
217
- slugify_sets = [
218
- [Integer, 'integer'],
219
- [Math::DomainError, 'math-domain-error'],
220
- ['FooBarBaz', 'foo-bar-baz'],
221
- [:FooBarBaz, 'foo-bar-baz'],
222
- ["Foo-Bar'Baz", 'foo-bar-baz'],
223
- ['(Foo*&Bar!Baz?', 'foo-bar-baz'],
224
- ["Bill O'Shea", 'bill-o-shea'],
225
- ["Bill O Shea", 'bill-o-shea'],
226
- ["Bill O Shea", 'bill-o-shea'],
227
- ]
228
-
229
- it '#slugify' do
230
- slugify_sets.each do |set|
231
- inc, out = set
232
- expect(inc.slugify).to eq out
233
- end
234
- expect('!@#$Foo0987'.slugify).to eq 'foo0987'
235
- expect('!@#$%^'.slugify).to eq nil
236
- # make sure we're not performing in place
237
- str = 'FooBarBaz'
238
- expect(str.slugify).to eq 'foo-bar-baz'
239
- expect(str).to eq 'FooBarBaz'
240
-
241
- # we permit leading numbers, unlike keyify
242
- expect('!1234FooBAR'.slugify).to eq '1234-foo-bar'
243
- expect('1234FooBAR'.slugify).to eq '1234-foo-bar'
244
- expect('12345678'.slugify).to eq '12345678'
245
-
246
- # should work on frozen values
247
- expect('FooBarBaz'.freeze.slugify).to eq 'foo-bar-baz'
248
- end
249
-
250
- it '#slugify!' do
251
- slugify_sets.each do |set|
252
- inc, out = set
253
- expect(inc.slugify!).to eq out
254
- end
255
- expect{ '!@#$%^'.slugify! }.to raise_error(ArgumentError)
256
- expect{ '12345678'.slugify! }.not_to raise_error
257
- end
258
-
259
- end
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+
5
+ it '#dedupe' do
6
+ expect('___foo___'.dedupe('_')).to eq '_foo_'
7
+ expect('---foo---'.dedupe('-')).to eq '-foo-'
8
+ expect('___foo---'.dedupe('_-')).to eq '_foo-'
9
+ expect('___foo__bar_baz--bing'.dedupe('_')).to eq '_foo_bar_baz--bing'
10
+ expect('foo'.dedupe('o')).to eq 'fo'
11
+ expect('foo'.dedupe('O')).to eq 'foo'
12
+ expect('[[foo]]]'.dedupe('[]')).to eq '[foo]'
13
+ expect('/crazy//concatenated////file/path'.dedupe('/')).to eq '/crazy/concatenated/file/path'
14
+
15
+ # make sure our use of gsub! isn't screwing us over
16
+ orig = '___foo___'
17
+ modified = orig.dedupe('_')
18
+ expect(modified).to eq '_foo_'
19
+ expect(orig).to eq '___foo___'
20
+ end
21
+
22
+ it '#dedupe!' do
23
+ str = '___foo___'
24
+ str.dedupe!('_')
25
+ expect(str).to eq '_foo_'
26
+ end
27
+
28
+ it '#strip_all (incl _strip_all_prep)' do
29
+ expect('___foo___'.strip_all).to eq 'foo'
30
+ expect('---foo---'.strip_all).to eq 'foo'
31
+ expect('-_-foo-_-'.strip_all).to eq 'foo'
32
+ expect('_-_8-foo-8_-_'.strip_all).to eq '8-foo-8'
33
+ expect('0123456789-foo-9876543210'.strip_all('0-9')).to eq '-foo-'
34
+ expect('0123-foo-3210'.strip_all('0-9-')).to eq 'foo'
35
+ expect('0123-foo-3210'.strip_all('a-z')).to eq '0123-foo-3210'
36
+ expect('foo-314-foo'.strip_all('a-z')).to eq '-314-'
37
+ expect('foo-314-foo'.strip_all('a-z-')).to eq '314'
38
+ expect('foo-314-foo'.strip_all('A-Z')).to eq 'foo-314-foo'
39
+ expect('FOO-314-FOO'.strip_all('A-Z')).to eq '-314-'
40
+ expect('FOO 314 FOO'.strip_all('A-Z')).to eq '314'
41
+
42
+ expect('abcdefghijklmnopqrstuvwxyz'.strip_all('a-z')).to eq ''
43
+ expect('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.strip_all('A-Z')).to eq ''
44
+ expect('ABCDEFGHIJKLM FOO NOPQRSTUVWXYZ'.strip_all('A-Z')).to eq ''
45
+
46
+ expect('000000'.strip_all('0')).to eq ''
47
+ expect('[[000]]'.strip_all('[0]')).to eq ''
48
+ expect('. $ ^ { [ ( | ) * + ? \ '.strip_all('. $ ^ { [ ( | ) * + ? \ ')).to eq ''
49
+ expect('/[a|valid|regex]+/'.strip_all('/[]+')).to eq 'a|valid|regex'
50
+
51
+ expect('_1 0__spaces_incl__0 1_'.strip_all('0-9_')).to eq 'spaces_incl'
52
+ expect(' _spaces_incl_ '.strip_all).to eq 'spaces_incl'
53
+
54
+ expect("__'''foo__'".strip_all('_\'') ).to eq 'foo'
55
+ expect('abcdefghijklm foo123 nopqrstuvwxyz'.strip_all('a-z0-9')).to eq ''
56
+ expect('hello world'.strip_all('a-z')).to eq ''
57
+
58
+ expect{'bad call'.strip_all(101)}.to raise_error(ArgumentError)
59
+ end
60
+
61
+ it '#strip_all!' do
62
+ str = '___foo___'
63
+ str.strip_all!
64
+ expect(str).to eq 'foo'
65
+ end
66
+
67
+ it '#lstrip_all' do
68
+ expect('___foo___'.lstrip_all).to eq 'foo___'
69
+ end
70
+
71
+ it '#lstrip_all!' do
72
+ str = '___foo___'
73
+ str.lstrip_all!
74
+ expect(str).to eq 'foo___'
75
+ end
76
+
77
+ it '#rstrip_all' do
78
+ expect('___foo___'.rstrip_all).to eq '___foo'
79
+ end
80
+
81
+ it '#rstrip_all!' do
82
+ str = '___foo___'
83
+ str.rstrip_all!
84
+ expect(str).to eq '___foo'
85
+ end
86
+
87
+ it '#match?' do
88
+ expect('hello'.match?('he')).to be true
89
+ expect('hello'.match?('he', 1)).to be false
90
+ expect('hello'.match?('o')).to be true
91
+ expect('hello'.match?('ol')).to be false
92
+ expect('hello'.match?('(.)')).to be true
93
+ expect('hello'.match?(/(.)/)).to be true
94
+ expect('hello'.match?('xx')).to be false
95
+ end
96
+
97
+ it '#remove_whitespace' do
98
+ expect(' a b c d e'.remove_whitespace).to eq 'abcde'
99
+ expect(' [ foo ] '.remove_whitespace).to eq '[foo]'
100
+ expect(' '.remove_whitespace).to eq ''
101
+ expect('. $ ^ { [ ( | ) * + ? \ '.remove_whitespace).to eq '.$^{[(|)*+?\\'
102
+ expect('a b c d e'.remove_whitespace('+')).to eq 'abcde'
103
+ expect('a b c d e'.remove_whitespace('+')).to eq 'abcde'
104
+ expect('a b c d e'.remove_whitespace('__')).to eq 'abcde'
105
+ end
106
+
107
+ it '#remove_whitespace!' do
108
+ str = ' a b c d e'
109
+ str.remove_whitespace!
110
+ expect(str).to eq 'abcde'
111
+ end
112
+
113
+ it '#replace_whitespace' do
114
+ expect(' a b c d e'.replace_whitespace).to eq 'abcde'
115
+ expect('a b c d e'.replace_whitespace('+')).to eq 'a+b+c+d+e'
116
+ expect('a b c d e'.replace_whitespace('+')).to eq 'a++b+c+d+e'
117
+ expect('a b c d e'.replace_whitespace('__')).to eq 'a__b__c__d__e'
118
+ end
119
+
120
+ it '#replace_whitespace!' do
121
+ str = 'a b c d e'
122
+ str.replace_whitespace!('-')
123
+ expect(str).to eq 'a-b-c-d-e'
124
+ end
125
+
126
+ it '#nl2br' do
127
+ expect("\n".nl2br).to eq "<br />\n"
128
+ expect("\n\r".nl2br).to eq "<br />\n"
129
+ expect("\r\n".nl2br).to eq "<br />\n"
130
+ expect("\n\r\n".nl2br).to eq "<br />\n<br />\n"
131
+ expect("\r\n\r\n".nl2br).to eq "<br />\n<br />\n"
132
+ expect("\r\r\n".nl2br).to eq "<br />\n<br />\n"
133
+ expect("\r\r".nl2br).to eq "<br />\n<br />\n"
134
+ expect("\n\r\r".nl2br).to eq "<br />\n<br />\n"
135
+
136
+ expect("Let's play Global Thermonuclear War.\n\r".nl2br).to eq "Let's play Global Thermonuclear War.<br />\n"
137
+ expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".nl2br).
138
+ to eq "A strange game.<br />\n<br />\nThe only winning move is not to play.<br />\nHow about a nice game of chess?<br />\n"
139
+ end
140
+
141
+ it "#newline_to" do
142
+ expect("\n".newline_to).to eq " "
143
+ expect("\n\r".newline_to).to eq " "
144
+ expect("\r\n".newline_to).to eq " "
145
+ expect("\n\r\n".newline_to).to eq " "
146
+ expect("\r\n\r\n".newline_to).to eq " "
147
+ expect("\r\r\n".newline_to).to eq " "
148
+ expect("\r\r".newline_to).to eq " "
149
+ expect("\n\r\r".newline_to).to eq " "
150
+
151
+ # replacements should end up as strings
152
+ expect("\n".newline_to(:bar)).to eq 'bar'
153
+ expect("\n\n".newline_to('+')).to eq '++'
154
+ expect("\n\n".newline_to(0)).to eq '00'
155
+ expect("\n\n".newline_to(true)).to eq 'truetrue'
156
+
157
+ # should return a modified object, leaving original intact
158
+ newline = "\n"
159
+ bar = newline.newline_to(:bar)
160
+ expect(newline).to eq "\n"
161
+ expect(bar).to eq 'bar'
162
+
163
+ expect("Let's play Global Thermonuclear War.\n\r".newline_to).to eq "Let's play Global Thermonuclear War. "
164
+ expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".newline_to).
165
+ to eq "A strange game. The only winning move is not to play. How about a nice game of chess? "
166
+ end
167
+
168
+ it "#newline_to!" do
169
+ var = "\n"
170
+ var.newline_to! :foo
171
+ expect(var).to eq 'foo'
172
+ end
173
+
174
+ keyify_sets = [
175
+ [Integer, :integer],
176
+ [Math::DomainError, :math_domain_error],
177
+ ['FooBarBaz', :foo_bar_baz],
178
+ [:FooBarBaz, :foo_bar_baz],
179
+ ["Foo-Bar'Baz", :foo_bar_baz],
180
+ ['(Foo*&Bar!Baz?', :foo_bar_baz],
181
+ ['1234FooBAR', :foo_bar],
182
+ ['!@#$Foo0987', :foo0987],
183
+ ["Bill O'Shea", :bill_o_shea],
184
+ ["Bill O Shea", :bill_o_shea],
185
+ ["Bill O Shea", :bill_o_shea],
186
+ ]
187
+
188
+ it '#keyify' do
189
+ keyify_sets.each do |set|
190
+ inc, out = set
191
+ expect(inc.keyify).to eq out
192
+ end
193
+ expect('!@#$%^'.keyify).to eq nil
194
+ expect('12345678'.keyify).to eq nil
195
+ # make sure we're not performing in place
196
+ str = 'FooBarBaz'
197
+ expect(str.keyify).to eq :foo_bar_baz
198
+ expect(str).to eq 'FooBarBaz'
199
+ # should work on frozen values
200
+ expect('FooBarBaz'.freeze.keyify).to eq :foo_bar_baz
201
+ end
202
+
203
+ it '#keyify!' do
204
+ keyify_sets.each do |set|
205
+ inc, out = set
206
+ expect(inc.keyify!).to eq out
207
+ end
208
+ expect{ '!@#$%^'.keyify! }.to raise_error(ArgumentError)
209
+ expect{ '12345678'.keyify! }.to raise_error(ArgumentError)
210
+ end
211
+
212
+ it "dedupe + remove_whitespace" do
213
+ expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '12345'
214
+ expect('1 2 3 4 5'.dedupe(' ').replace_whitespace('+')).to eq '1+2+3+4+5'
215
+ end
216
+
217
+ slugify_sets = [
218
+ [Integer, 'integer'],
219
+ [Math::DomainError, 'math-domain-error'],
220
+ ['FooBarBaz', 'foo-bar-baz'],
221
+ [:FooBarBaz, 'foo-bar-baz'],
222
+ ["Foo-Bar'Baz", 'foo-bar-baz'],
223
+ ['(Foo*&Bar!Baz?', 'foo-bar-baz'],
224
+ ["Bill O'Shea", 'bill-o-shea'],
225
+ ["Bill O Shea", 'bill-o-shea'],
226
+ ["Bill O Shea", 'bill-o-shea'],
227
+ ]
228
+
229
+ it '#slugify' do
230
+ slugify_sets.each do |set|
231
+ inc, out = set
232
+ expect(inc.slugify).to eq out
233
+ end
234
+ expect('!@#$Foo0987'.slugify).to eq 'foo0987'
235
+ expect('!@#$%^'.slugify).to eq nil
236
+ # make sure we're not performing in place
237
+ str = 'FooBarBaz'
238
+ expect(str.slugify).to eq 'foo-bar-baz'
239
+ expect(str).to eq 'FooBarBaz'
240
+
241
+ # we permit leading numbers, unlike keyify
242
+ expect('!1234FooBAR'.slugify).to eq '1234-foo-bar'
243
+ expect('1234FooBAR'.slugify).to eq '1234-foo-bar'
244
+ expect('12345678'.slugify).to eq '12345678'
245
+
246
+ # should work on frozen values
247
+ expect('FooBarBaz'.freeze.slugify).to eq 'foo-bar-baz'
248
+ end
249
+
250
+ it '#slugify!' do
251
+ slugify_sets.each do |set|
252
+ inc, out = set
253
+ expect(inc.slugify!).to eq out
254
+ end
255
+ expect{ '!@#$%^'.slugify! }.to raise_error(ArgumentError)
256
+ expect{ '12345678'.slugify! }.not_to raise_error
257
+ end
258
+
259
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finishing_moves
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.20'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Koehl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-23 00:00:00.000000000 Z
12
+ date: 2018-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-readline