finishing_moves 0.16 → 0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/Rakefile +5 -0
- data/lib/finishing_moves/hash.rb +0 -5
- data/lib/finishing_moves/object.rb +0 -12
- data/lib/finishing_moves/string.rb +29 -3
- data/lib/finishing_moves/version.rb +1 -1
- data/spec/string_spec.rb +39 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1828abea212796a7805b0a15e1363ac078904cc3
|
4
|
+
data.tar.gz: 7c178f430b1ebb14f1ca202681af98ede8e279de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0d721dc93276daf8ad46b3aa9ebac6994144b9f588457c04e3301ddc813ed2052effd2442b831b94487453bc2551f7de2406607368d04f035a6d4a210b6bd52
|
7
|
+
data.tar.gz: d8d2005ed176acbc765fac2423170e78b9e8e9cd3bfbf5c8da6e60517ce50f362807a4f08be6a8a1391ed8c55a74c386e5042c4c10224380f6618219214cf005
|
data/README.md
CHANGED
@@ -51,6 +51,7 @@ gem install 'finishing_moves'
|
|
51
51
|
- [`String#nl2br`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringnl2br)
|
52
52
|
- [`String#numeric?`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringnumeric) :boom:
|
53
53
|
- [`String#remove_whitespace`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringremove_whitespace)
|
54
|
+
- [`String#replace_whitespace`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringreplace_whitespace)
|
54
55
|
- [`String#strip_all`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringstrip_all) :boom:
|
55
56
|
|
56
57
|
*Multi-class logic enhancements*
|
data/Rakefile
CHANGED
data/lib/finishing_moves/hash.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
class String
|
2
2
|
|
3
3
|
def nl2br
|
4
|
-
|
4
|
+
gsub _nl_gsub_regex, "<br />\n"
|
5
|
+
end
|
6
|
+
|
7
|
+
def newline_to(rep = ' ')
|
8
|
+
gsub _nl_gsub_regex, rep.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def newline_to!(rep = ' ')
|
12
|
+
gsub! _nl_gsub_regex, rep.to_s
|
5
13
|
end
|
6
14
|
|
7
15
|
def keyify
|
@@ -65,11 +73,19 @@ class String
|
|
65
73
|
str.each_char { |c| gsub! /#{Regexp.escape c}{2,}/, c }
|
66
74
|
end
|
67
75
|
|
68
|
-
def remove_whitespace(
|
76
|
+
def remove_whitespace(_ignored = nil)
|
77
|
+
replace_whitespace('')
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_whitespace!(_ignored = nil)
|
81
|
+
replace_whitespace!('')
|
82
|
+
end
|
83
|
+
|
84
|
+
def replace_whitespace(replace = '')
|
69
85
|
gsub /[ ]/, replace
|
70
86
|
end
|
71
87
|
|
72
|
-
def
|
88
|
+
def replace_whitespace!(replace = '')
|
73
89
|
gsub! /[ ]/, replace
|
74
90
|
end
|
75
91
|
|
@@ -86,8 +102,18 @@ class String
|
|
86
102
|
Float(self) != nil rescue false
|
87
103
|
end
|
88
104
|
|
105
|
+
# TODO
|
106
|
+
# def each_char_index(&block)
|
107
|
+
# how to return enumerator if no block given?
|
108
|
+
# http://blog.arkency.com/2014/01/ruby-to-enum-for-enumerator/
|
109
|
+
# end
|
110
|
+
|
89
111
|
protected
|
90
112
|
|
113
|
+
def _nl_gsub_regex
|
114
|
+
/(?:\n\r?|\r\n?)/
|
115
|
+
end
|
116
|
+
|
91
117
|
def _lstrip_all_regex(expr)
|
92
118
|
/\A[#{expr}]+/
|
93
119
|
end
|
data/spec/string_spec.rb
CHANGED
@@ -99,9 +99,9 @@ describe String do
|
|
99
99
|
expect(' [ foo ] '.remove_whitespace).to eq '[foo]'
|
100
100
|
expect(' '.remove_whitespace).to eq ''
|
101
101
|
expect('. $ ^ { [ ( | ) * + ? \ '.remove_whitespace).to eq '.$^{[(|)*+?\\'
|
102
|
-
expect('a b c d e'.remove_whitespace('+')).to eq '
|
103
|
-
expect('a b c d e'.remove_whitespace('+')).to eq '
|
104
|
-
expect('a b c d e'.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
105
|
end
|
106
106
|
|
107
107
|
it '#remove_whitespace!' do
|
@@ -110,6 +110,19 @@ describe String do
|
|
110
110
|
expect(str).to eq 'abcde'
|
111
111
|
end
|
112
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
|
+
|
113
126
|
it '#nl2br' do
|
114
127
|
expect("\n".nl2br).to eq "<br />\n"
|
115
128
|
expect("\n\r".nl2br).to eq "<br />\n"
|
@@ -125,6 +138,27 @@ describe String do
|
|
125
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"
|
126
139
|
end
|
127
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
|
+
expect("Let's play Global Thermonuclear War.\n\r".newline_to).to eq "Let's play Global Thermonuclear War. "
|
158
|
+
expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".newline_to).
|
159
|
+
to eq "A strange game. The only winning move is not to play. How about a nice game of chess? "
|
160
|
+
end
|
161
|
+
|
128
162
|
it '#keyify' do
|
129
163
|
expect(Integer.keyify).to eq :integer
|
130
164
|
expect(Math::DomainError.keyify).to eq :math_domain_error
|
@@ -155,7 +189,8 @@ describe String do
|
|
155
189
|
end
|
156
190
|
|
157
191
|
it "dedupe + remove_whitespace" do
|
158
|
-
expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '
|
192
|
+
expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '12345'
|
193
|
+
expect('1 2 3 4 5'.dedupe(' ').replace_whitespace('+')).to eq '1+2+3+4+5'
|
159
194
|
end
|
160
195
|
|
161
196
|
it '#slugify' do
|
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.
|
4
|
+
version: '0.17'
|
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: 2017-01-
|
12
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb-readline
|