finishing_moves 0.15 → 0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/lib/finishing_moves/string.rb +3 -29
- data/lib/finishing_moves/version.rb +1 -1
- data/spec/string_spec.rb +4 -39
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a1eb69dc879d8b4af5acecf3fcc1713a7a57b34
|
4
|
+
data.tar.gz: 19530406deb74bd1e5bf75eda64b4700298fef7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a422ae85c7db779e2b27732c609a69f4abedca3dc5ff4111db1ebdfd205e4a50603bc6861cf83f32ad63d7ee8f04bedc08a379f914647f9b63bfbb706c11be3d
|
7
|
+
data.tar.gz: dbbb324d10de76afb224f9188e2324fbff896ec037514f66bd5da6c51e8bb0131a55de546c3f829c69dbdf32a251795bb42fc57d5b91c3ea1381eab2657106af
|
data/README.md
CHANGED
@@ -51,7 +51,6 @@ 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)
|
55
54
|
- [`String#strip_all`](https://github.com/forgecrafted/finishing_moves/wiki/String#stringstrip_all) :boom:
|
56
55
|
|
57
56
|
*Multi-class logic enhancements*
|
@@ -1,15 +1,7 @@
|
|
1
1
|
class String
|
2
2
|
|
3
3
|
def nl2br
|
4
|
-
gsub
|
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
|
4
|
+
self.gsub(/(?:\n\r?|\r\n?)/, "<br />\n")
|
13
5
|
end
|
14
6
|
|
15
7
|
def keyify
|
@@ -73,19 +65,11 @@ class String
|
|
73
65
|
str.each_char { |c| gsub! /#{Regexp.escape c}{2,}/, c }
|
74
66
|
end
|
75
67
|
|
76
|
-
def remove_whitespace(
|
77
|
-
replace_whitespace('')
|
78
|
-
end
|
79
|
-
|
80
|
-
def remove_whitespace!(_ignored = nil)
|
81
|
-
replace_whitespace!('')
|
82
|
-
end
|
83
|
-
|
84
|
-
def replace_whitespace(replace = '')
|
68
|
+
def remove_whitespace(replace = '')
|
85
69
|
gsub /[ ]/, replace
|
86
70
|
end
|
87
71
|
|
88
|
-
def
|
72
|
+
def remove_whitespace!(replace = '')
|
89
73
|
gsub! /[ ]/, replace
|
90
74
|
end
|
91
75
|
|
@@ -102,18 +86,8 @@ class String
|
|
102
86
|
Float(self) != nil rescue false
|
103
87
|
end
|
104
88
|
|
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
|
-
|
111
89
|
protected
|
112
90
|
|
113
|
-
def _nl_gsub_regex
|
114
|
-
/(?:\n\r?|\r\n?)/
|
115
|
-
end
|
116
|
-
|
117
91
|
def _lstrip_all_regex(expr)
|
118
92
|
/\A[#{expr}]+/
|
119
93
|
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 'a+b+c+d+e'
|
103
|
+
expect('a b c d e'.remove_whitespace('+')).to eq 'a++b+c+d+e'
|
104
|
+
expect('a b c d e'.remove_whitespace('__')).to eq 'a__b__c__d__e'
|
105
105
|
end
|
106
106
|
|
107
107
|
it '#remove_whitespace!' do
|
@@ -110,19 +110,6 @@ 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
|
-
|
126
113
|
it '#nl2br' do
|
127
114
|
expect("\n".nl2br).to eq "<br />\n"
|
128
115
|
expect("\n\r".nl2br).to eq "<br />\n"
|
@@ -138,27 +125,6 @@ describe String do
|
|
138
125
|
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
126
|
end
|
140
127
|
|
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
|
-
|
162
128
|
it '#keyify' do
|
163
129
|
expect(Integer.keyify).to eq :integer
|
164
130
|
expect(Math::DomainError.keyify).to eq :math_domain_error
|
@@ -189,8 +155,7 @@ describe String do
|
|
189
155
|
end
|
190
156
|
|
191
157
|
it "dedupe + remove_whitespace" do
|
192
|
-
expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '
|
193
|
-
expect('1 2 3 4 5'.dedupe(' ').replace_whitespace('+')).to eq '1+2+3+4+5'
|
158
|
+
expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '1+2+3+4+5'
|
194
159
|
end
|
195
160
|
|
196
161
|
it '#slugify' do
|