mack-facets 0.7.0.1 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/classes/Array.html +60 -60
- data/doc/classes/Class.html +18 -18
- data/doc/classes/Hash.html +18 -18
- data/doc/classes/Kernel.html +40 -12
- data/doc/classes/Mack/Facets/DateTime.html +168 -0
- data/doc/classes/Mack/Facets.html +111 -0
- data/doc/classes/Mack/Utils/BlankSlate.html +113 -0
- data/doc/classes/Mack/Utils/Inflector.html +47 -47
- data/doc/classes/Mack/Utils/RegistryList.html +74 -74
- data/doc/classes/Mack/Utils/RegistryMap.html +71 -71
- data/doc/classes/Math.html +18 -18
- data/doc/classes/Module.html +12 -12
- data/doc/classes/NilClass.html +6 -6
- data/doc/classes/Object.html +68 -68
- data/doc/classes/String.html +185 -172
- data/doc/classes/Symbol.html +6 -6
- data/doc/classes/Time.html +204 -0
- data/doc/created.rid +1 -1
- data/doc/files/README.html +1 -1
- data/doc/files/lib/mack-facets/english_extensions/inflect_rb.html +1 -1
- data/doc/files/lib/mack-facets/english_extensions/numerals_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/array_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/class_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/date_time_rb.html +129 -0
- data/doc/files/lib/mack-facets/extensions/hash_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/kernel_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/math_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/module_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/nil_class_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/object_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/string_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/symbol_rb.html +1 -1
- data/doc/files/lib/mack-facets/extensions/time_rb.html +108 -0
- data/doc/files/lib/mack-facets/utils/blank_slate_rb.html +101 -0
- data/doc/files/lib/mack-facets/utils/inflections_rb.html +1 -1
- data/doc/files/lib/mack-facets/utils/inflector_rb.html +1 -1
- data/doc/files/lib/mack-facets/utils/options_merger_rb.html +1 -1
- data/doc/files/lib/mack-facets/utils/registry_list_rb.html +1 -1
- data/doc/files/lib/mack-facets/utils/registry_map_rb.html +1 -1
- data/doc/files/lib/mack-facets_rb.html +3 -3
- data/doc/fr_class_index.html +2 -0
- data/doc/fr_file_index.html +1 -0
- data/doc/fr_method_index.html +75 -71
- data/lib/mack-facets/extensions/date_time.rb +36 -0
- data/lib/mack-facets/extensions/kernel.rb +5 -0
- data/lib/mack-facets/extensions/string.rb +2 -0
- data/lib/mack-facets/extensions/time.rb +5 -0
- data/lib/mack-facets.rb +3 -4
- metadata +12 -4
data/doc/classes/String.html
CHANGED
@@ -88,15 +88,15 @@
|
|
88
88
|
<h3 class="section-bar">Methods</h3>
|
89
89
|
|
90
90
|
<div class="name-list">
|
91
|
-
<a href="#
|
92
|
-
<a href="#
|
93
|
-
<a href="#
|
94
|
-
<a href="#
|
95
|
-
<a href="#
|
96
|
-
<a href="#
|
97
|
-
<a href="#
|
98
|
-
<a href="#
|
99
|
-
<a href="#
|
91
|
+
<a href="#M000035">constantize</a>
|
92
|
+
<a href="#M000036">hexdigest</a>
|
93
|
+
<a href="#M000037">hexdigest!</a>
|
94
|
+
<a href="#M000034">methodize</a>
|
95
|
+
<a href="#M000038">randomize</a>
|
96
|
+
<a href="#M000041">truncate</a>
|
97
|
+
<a href="#M000042">truncate!</a>
|
98
|
+
<a href="#M000039">uri_escape</a>
|
99
|
+
<a href="#M000040">uri_unescape</a>
|
100
100
|
</div>
|
101
101
|
</div>
|
102
102
|
|
@@ -116,6 +116,19 @@
|
|
116
116
|
|
117
117
|
|
118
118
|
|
119
|
+
<div id="aliases-list">
|
120
|
+
<h3 class="section-bar">External Aliases</h3>
|
121
|
+
|
122
|
+
<div class="name-list">
|
123
|
+
<table summary="aliases">
|
124
|
+
<tr class="top-aligned-row context-row">
|
125
|
+
<td class="context-item-name">snakecase</td>
|
126
|
+
<td>-></td>
|
127
|
+
<td class="context-item-value">underscore</td>
|
128
|
+
</tr>
|
129
|
+
</table>
|
130
|
+
</div>
|
131
|
+
</div>
|
119
132
|
|
120
133
|
|
121
134
|
|
@@ -125,27 +138,27 @@
|
|
125
138
|
<div id="methods">
|
126
139
|
<h3 class="section-bar">Public Class methods</h3>
|
127
140
|
|
128
|
-
<div id="method-
|
129
|
-
<a name="
|
141
|
+
<div id="method-M000038" class="method-detail">
|
142
|
+
<a name="M000038"></a>
|
130
143
|
|
131
144
|
<div class="method-heading">
|
132
|
-
<a href="#
|
145
|
+
<a href="#M000038" class="method-signature">
|
133
146
|
<span class="method-name">randomize</span><span class="method-args">(length = 10)</span>
|
134
147
|
</a>
|
135
148
|
</div>
|
136
149
|
|
137
150
|
<div class="method-description">
|
138
151
|
<p><a class="source-toggle" href="#"
|
139
|
-
onclick="toggleCode('
|
140
|
-
<div class="method-source-code" id="
|
152
|
+
onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
|
153
|
+
<div class="method-source-code" id="M000038-source">
|
141
154
|
<pre>
|
142
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
155
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 97</span>
|
156
|
+
97: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">randomize</span>(<span class="ruby-identifier">length</span> = <span class="ruby-value">10</span>)
|
157
|
+
98: <span class="ruby-identifier">chars</span> = (<span class="ruby-value str">"A"</span><span class="ruby-operator">..</span><span class="ruby-value str">"H"</span>).<span class="ruby-identifier">to_a</span> <span class="ruby-operator">+</span> (<span class="ruby-value str">"J"</span><span class="ruby-operator">..</span><span class="ruby-value str">"N"</span>).<span class="ruby-identifier">to_a</span> <span class="ruby-operator">+</span> (<span class="ruby-value str">"P"</span><span class="ruby-operator">..</span><span class="ruby-value str">"T"</span>).<span class="ruby-identifier">to_a</span> <span class="ruby-operator">+</span> (<span class="ruby-value str">"W"</span><span class="ruby-operator">..</span><span class="ruby-value str">"Z"</span>).<span class="ruby-identifier">to_a</span> <span class="ruby-operator">+</span> (<span class="ruby-value str">"3"</span><span class="ruby-operator">..</span><span class="ruby-value str">"9"</span>).<span class="ruby-identifier">to_a</span>
|
158
|
+
99: <span class="ruby-identifier">newpass</span> = <span class="ruby-value str">""</span>
|
159
|
+
100: <span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">length</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">newpass</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">chars</span>[<span class="ruby-identifier">rand</span>(<span class="ruby-identifier">chars</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)] }
|
160
|
+
101: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">newpass</span>.<span class="ruby-identifier">upcase</span>
|
161
|
+
102: <span class="ruby-keyword kw">end</span>
|
149
162
|
</pre>
|
150
163
|
</div>
|
151
164
|
</div>
|
@@ -153,11 +166,11 @@
|
|
153
166
|
|
154
167
|
<h3 class="section-bar">Public Instance methods</h3>
|
155
168
|
|
156
|
-
<div id="method-
|
157
|
-
<a name="
|
169
|
+
<div id="method-M000035" class="method-detail">
|
170
|
+
<a name="M000035"></a>
|
158
171
|
|
159
172
|
<div class="method-heading">
|
160
|
-
<a href="#
|
173
|
+
<a href="#M000035" class="method-signature">
|
161
174
|
<span class="method-name">constantize</span><span class="method-args">()</span>
|
162
175
|
</a>
|
163
176
|
</div>
|
@@ -175,214 +188,214 @@ Examples:
|
|
175
188
|
"Mack::Configuration" # => Mack::Configuration
|
176
189
|
</pre>
|
177
190
|
<p><a class="source-toggle" href="#"
|
178
|
-
onclick="toggleCode('
|
179
|
-
<div class="method-source-code" id="
|
191
|
+
onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
|
192
|
+
<div class="method-source-code" id="M000035-source">
|
180
193
|
<pre>
|
181
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
182
|
-
|
183
|
-
|
184
|
-
|
194
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 85</span>
|
195
|
+
85: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">constantize</span>
|
196
|
+
86: <span class="ruby-constant">Module</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-node">"::#{self}"</span>)
|
197
|
+
87: <span class="ruby-keyword kw">end</span>
|
185
198
|
</pre>
|
186
199
|
</div>
|
187
200
|
</div>
|
188
201
|
</div>
|
189
202
|
|
190
|
-
<div id="method-
|
191
|
-
<a name="
|
203
|
+
<div id="method-M000036" class="method-detail">
|
204
|
+
<a name="M000036"></a>
|
192
205
|
|
193
206
|
<div class="method-heading">
|
194
|
-
<a href="#
|
207
|
+
<a href="#M000036" class="method-signature">
|
195
208
|
<span class="method-name">hexdigest</span><span class="method-args">()</span>
|
196
209
|
</a>
|
197
210
|
</div>
|
198
211
|
|
199
212
|
<div class="method-description">
|
200
213
|
<p><a class="source-toggle" href="#"
|
201
|
-
onclick="toggleCode('
|
202
|
-
<div class="method-source-code" id="
|
214
|
+
onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
|
215
|
+
<div class="method-source-code" id="M000036-source">
|
203
216
|
<pre>
|
204
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
205
|
-
|
206
|
-
|
207
|
-
|
217
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 89</span>
|
218
|
+
89: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hexdigest</span>
|
219
|
+
90: <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">SHA1</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-keyword kw">self</span>)
|
220
|
+
91: <span class="ruby-keyword kw">end</span>
|
208
221
|
</pre>
|
209
222
|
</div>
|
210
223
|
</div>
|
211
224
|
</div>
|
212
225
|
|
213
|
-
<div id="method-
|
214
|
-
<a name="
|
226
|
+
<div id="method-M000037" class="method-detail">
|
227
|
+
<a name="M000037"></a>
|
215
228
|
|
216
229
|
<div class="method-heading">
|
217
|
-
<a href="#
|
230
|
+
<a href="#M000037" class="method-signature">
|
218
231
|
<span class="method-name">hexdigest!</span><span class="method-args">()</span>
|
219
232
|
</a>
|
220
233
|
</div>
|
221
234
|
|
222
235
|
<div class="method-description">
|
223
236
|
<p><a class="source-toggle" href="#"
|
224
|
-
onclick="toggleCode('
|
225
|
-
<div class="method-source-code" id="
|
237
|
+
onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
|
238
|
+
<div class="method-source-code" id="M000037-source">
|
226
239
|
<pre>
|
227
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
228
|
-
|
229
|
-
|
230
|
-
|
240
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 93</span>
|
241
|
+
93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hexdigest!</span>
|
242
|
+
94: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">hexdigest</span>)
|
243
|
+
95: <span class="ruby-keyword kw">end</span>
|
231
244
|
</pre>
|
232
245
|
</div>
|
233
246
|
</div>
|
234
247
|
</div>
|
235
248
|
|
236
|
-
<div id="method-
|
237
|
-
<a name="
|
249
|
+
<div id="method-M000034" class="method-detail">
|
250
|
+
<a name="M000034"></a>
|
238
251
|
|
239
252
|
<div class="method-heading">
|
240
|
-
<a href="#
|
253
|
+
<a href="#M000034" class="method-signature">
|
241
254
|
<span class="method-name">methodize</span><span class="method-args">()</span>
|
242
255
|
</a>
|
243
256
|
</div>
|
244
257
|
|
245
258
|
<div class="method-description">
|
246
259
|
<p><a class="source-toggle" href="#"
|
247
|
-
onclick="toggleCode('
|
248
|
-
<div class="method-source-code" id="
|
260
|
+
onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
|
261
|
+
<div class="method-source-code" id="M000034-source">
|
249
262
|
<pre>
|
250
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
15:
|
263
|
-
16: <span class="ruby-identifier">x</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">underscore</span>
|
263
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 6</span>
|
264
|
+
6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">methodize</span>
|
265
|
+
7: <span class="ruby-identifier">x</span> = <span class="ruby-keyword kw">self</span>
|
266
|
+
8:
|
267
|
+
9: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
268
|
+
10: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{self} cannot be converted to a valid method name!"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
|
269
|
+
11:
|
270
|
+
12: <span class="ruby-comment cmt"># get rid of the big stuff in the front/back</span>
|
271
|
+
13: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">strip!</span>
|
272
|
+
14:
|
273
|
+
15: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
274
|
+
16: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{self} cannot be converted to a valid method name!"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
|
264
275
|
17:
|
265
|
-
18: <span class="ruby-
|
266
|
-
19:
|
267
|
-
20: <span class="ruby-comment cmt"># get rid of
|
268
|
-
21: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-
|
269
|
-
22:
|
270
|
-
23: <span class="ruby-
|
271
|
-
24:
|
272
|
-
25:
|
273
|
-
26: <span class="ruby-
|
274
|
-
27:
|
275
|
-
28:
|
276
|
-
29:
|
277
|
-
30: <span class="ruby-keyword kw">
|
278
|
-
31:
|
279
|
-
32: <span class="ruby-
|
280
|
-
33:
|
281
|
-
34:
|
282
|
-
35: <span class="ruby-
|
283
|
-
36:
|
284
|
-
37:
|
285
|
-
38: <span class="ruby-
|
286
|
-
39:
|
287
|
-
40:
|
288
|
-
41:
|
289
|
-
42: <span class="ruby-
|
290
|
-
43:
|
291
|
-
44:
|
292
|
-
45:
|
293
|
-
46: <span class="ruby-
|
294
|
-
47:
|
295
|
-
48: <span class="ruby-comment cmt"># bad
|
296
|
-
49: <span class="ruby-
|
297
|
-
50:
|
298
|
-
51: <span class="ruby-
|
299
|
-
52:
|
300
|
-
53:
|
301
|
-
54:
|
302
|
-
55: <span class="ruby-identifier">
|
303
|
-
56:
|
304
|
-
57:
|
305
|
-
58: <span class="ruby-
|
306
|
-
59:
|
307
|
-
60:
|
308
|
-
61: <span class="ruby-
|
309
|
-
62:
|
310
|
-
63: <span class="ruby-
|
311
|
-
64:
|
312
|
-
65:
|
313
|
-
66:
|
314
|
-
67: <span class="ruby-keyword kw">
|
315
|
-
68:
|
316
|
-
69: <span class="ruby-
|
317
|
-
70:
|
318
|
-
71:
|
319
|
-
72: <span class="ruby-identifier">
|
320
|
-
73:
|
321
|
-
74: <span class="ruby-identifier">x</span>
|
322
|
-
75:
|
276
|
+
18: <span class="ruby-identifier">x</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">underscore</span>
|
277
|
+
19:
|
278
|
+
20: <span class="ruby-comment cmt"># get rid of spaces and make the _</span>
|
279
|
+
21: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">' '</span>, <span class="ruby-value str">'_'</span>)
|
280
|
+
22: <span class="ruby-comment cmt"># get rid of everything that isn't 'safe' a-z, 0-9, ?, !, =, _</span>
|
281
|
+
23: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/([^ a-zA-Z0-9\_\?\!\=]+)/n</span>, <span class="ruby-value str">'_'</span>)
|
282
|
+
24:
|
283
|
+
25: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
284
|
+
26: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{self} cannot be converted to a valid method name!"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
|
285
|
+
27:
|
286
|
+
28: <span class="ruby-comment cmt"># condense multiple 'safe' non a-z chars to just one.</span>
|
287
|
+
29: <span class="ruby-comment cmt"># ie. ___ becomes _ !!!! becomes ! etc...</span>
|
288
|
+
30: [<span class="ruby-value str">' '</span>, <span class="ruby-value str">'_'</span>, <span class="ruby-value str">'?'</span>, <span class="ruby-value str">'!'</span>, <span class="ruby-value str">"="</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
289
|
+
31: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">squeeze!</span>(<span class="ruby-identifier">c</span>)
|
290
|
+
32: <span class="ruby-keyword kw">end</span>
|
291
|
+
33:
|
292
|
+
34: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
293
|
+
35: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{self} cannot be converted to a valid method name!"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
|
294
|
+
36:
|
295
|
+
37: <span class="ruby-comment cmt">#down case the whole thing</span>
|
296
|
+
38: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">downcase!</span>
|
297
|
+
39:
|
298
|
+
40: <span class="ruby-comment cmt"># get rid of any characters at the beginning that aren't a-z</span>
|
299
|
+
41: <span class="ruby-keyword kw">while</span> <span class="ruby-operator">!</span><span class="ruby-identifier">x</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/^[a-z]/</span>)
|
300
|
+
42: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span>)
|
301
|
+
43:
|
302
|
+
44: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
303
|
+
45: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{self} cannot be converted to a valid method name!"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
|
304
|
+
46: <span class="ruby-keyword kw">end</span>
|
305
|
+
47:
|
306
|
+
48: <span class="ruby-comment cmt"># let's trim this bad boy down a bit now that we've cleaned it up, somewhat.</span>
|
307
|
+
49: <span class="ruby-comment cmt"># we should do this before cleaning up the end character, because it's possible to end up with a </span>
|
308
|
+
50: <span class="ruby-comment cmt"># bad char at the end if you trim too late.</span>
|
309
|
+
51: <span class="ruby-identifier">x</span> = <span class="ruby-identifier">x</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">100</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">></span> <span class="ruby-value">100</span>
|
310
|
+
52:
|
311
|
+
53: <span class="ruby-comment cmt"># get rid of any characters at the end that aren't safe</span>
|
312
|
+
54: <span class="ruby-keyword kw">while</span> <span class="ruby-operator">!</span><span class="ruby-identifier">x</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/[a-z0-9\?\!\=]$/</span>)
|
313
|
+
55: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-identifier">x</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
|
314
|
+
56: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
315
|
+
57: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{self} cannot be converted to a valid method name!"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
|
316
|
+
58: <span class="ruby-keyword kw">end</span>
|
317
|
+
59:
|
318
|
+
60: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
319
|
+
61: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{self} cannot be converted to a valid method name!"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
|
320
|
+
62:
|
321
|
+
63: <span class="ruby-comment cmt"># let's get rid of characters that don't belong in the 'middle' of the method.</span>
|
322
|
+
64: <span class="ruby-identifier">orig_middle</span> = <span class="ruby-identifier">x</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">x</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">2</span>)]
|
323
|
+
65: <span class="ruby-identifier">n_middle</span> = <span class="ruby-identifier">orig_middle</span>.<span class="ruby-identifier">dup</span>
|
324
|
+
66:
|
325
|
+
67: [<span class="ruby-value str">'?'</span>, <span class="ruby-value str">'!'</span>, <span class="ruby-value str">"="</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
326
|
+
68: <span class="ruby-identifier">n_middle</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">c</span>, <span class="ruby-value str">"_"</span>)
|
327
|
+
69: <span class="ruby-keyword kw">end</span>
|
328
|
+
70:
|
329
|
+
71: <span class="ruby-comment cmt"># the previous gsub can leave us with multiple underscores that need cleaning up.</span>
|
330
|
+
72: <span class="ruby-identifier">n_middle</span>.<span class="ruby-identifier">squeeze!</span>(<span class="ruby-value str">"_"</span>)
|
331
|
+
73:
|
332
|
+
74: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">orig_middle</span>, <span class="ruby-identifier">n_middle</span>)
|
333
|
+
75: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">"_="</span>, <span class="ruby-value str">"="</span>)
|
334
|
+
76: <span class="ruby-identifier">x</span>
|
335
|
+
77: <span class="ruby-keyword kw">end</span>
|
323
336
|
</pre>
|
324
337
|
</div>
|
325
338
|
</div>
|
326
339
|
</div>
|
327
340
|
|
328
|
-
<div id="method-
|
329
|
-
<a name="
|
341
|
+
<div id="method-M000041" class="method-detail">
|
342
|
+
<a name="M000041"></a>
|
330
343
|
|
331
344
|
<div class="method-heading">
|
332
|
-
<a href="#
|
345
|
+
<a href="#M000041" class="method-signature">
|
333
346
|
<span class="method-name">truncate</span><span class="method-args">(length = 30, truncate_string = "...")</span>
|
334
347
|
</a>
|
335
348
|
</div>
|
336
349
|
|
337
350
|
<div class="method-description">
|
338
351
|
<p><a class="source-toggle" href="#"
|
339
|
-
onclick="toggleCode('
|
340
|
-
<div class="method-source-code" id="
|
352
|
+
onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
|
353
|
+
<div class="method-source-code" id="M000041-source">
|
341
354
|
<pre>
|
342
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
355
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 120</span>
|
356
|
+
120: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">truncate</span>(<span class="ruby-identifier">length</span> = <span class="ruby-value">30</span>, <span class="ruby-identifier">truncate_string</span> = <span class="ruby-value str">"..."</span>)
|
357
|
+
121: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">then</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">end</span>
|
358
|
+
122: <span class="ruby-identifier">l</span> = <span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">truncate_string</span>.<span class="ruby-identifier">length</span>
|
359
|
+
123: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$KCODE</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"NONE"</span>
|
360
|
+
124: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">></span> <span class="ruby-identifier">length</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">l</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">truncate_string</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>
|
361
|
+
125: <span class="ruby-keyword kw">else</span>
|
362
|
+
126: <span class="ruby-identifier">chars</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">//</span>)
|
363
|
+
127: <span class="ruby-identifier">chars</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">></span> <span class="ruby-identifier">length</span> <span class="ruby-value">? </span><span class="ruby-identifier">chars</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">l</span>].<span class="ruby-identifier">join</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">truncate_string</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>
|
364
|
+
128: <span class="ruby-keyword kw">end</span>
|
365
|
+
129: <span class="ruby-keyword kw">end</span>
|
353
366
|
</pre>
|
354
367
|
</div>
|
355
368
|
</div>
|
356
369
|
</div>
|
357
370
|
|
358
|
-
<div id="method-
|
359
|
-
<a name="
|
371
|
+
<div id="method-M000042" class="method-detail">
|
372
|
+
<a name="M000042"></a>
|
360
373
|
|
361
374
|
<div class="method-heading">
|
362
|
-
<a href="#
|
375
|
+
<a href="#M000042" class="method-signature">
|
363
376
|
<span class="method-name">truncate!</span><span class="method-args">(length = 30, truncate_string = "...")</span>
|
364
377
|
</a>
|
365
378
|
</div>
|
366
379
|
|
367
380
|
<div class="method-description">
|
368
381
|
<p><a class="source-toggle" href="#"
|
369
|
-
onclick="toggleCode('
|
370
|
-
<div class="method-source-code" id="
|
382
|
+
onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
|
383
|
+
<div class="method-source-code" id="M000042-source">
|
371
384
|
<pre>
|
372
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
373
|
-
|
374
|
-
|
375
|
-
|
385
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 131</span>
|
386
|
+
131: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">truncate!</span>(<span class="ruby-identifier">length</span> = <span class="ruby-value">30</span>, <span class="ruby-identifier">truncate_string</span> = <span class="ruby-value str">"..."</span>)
|
387
|
+
132: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">truncate</span>(<span class="ruby-identifier">length</span>, <span class="ruby-identifier">truncate_string</span>))
|
388
|
+
133: <span class="ruby-keyword kw">end</span>
|
376
389
|
</pre>
|
377
390
|
</div>
|
378
391
|
</div>
|
379
392
|
</div>
|
380
393
|
|
381
|
-
<div id="method-
|
382
|
-
<a name="
|
394
|
+
<div id="method-M000039" class="method-detail">
|
395
|
+
<a name="M000039"></a>
|
383
396
|
|
384
397
|
<div class="method-heading">
|
385
|
-
<a href="#
|
398
|
+
<a href="#M000039" class="method-signature">
|
386
399
|
<span class="method-name">uri_escape</span><span class="method-args">()</span>
|
387
400
|
</a>
|
388
401
|
</div>
|
@@ -394,25 +407,25 @@ faster. Use this rather than the cgi.rb version since it‘s faster.
|
|
394
407
|
(Stolen from Camping).
|
395
408
|
</p>
|
396
409
|
<p><a class="source-toggle" href="#"
|
397
|
-
onclick="toggleCode('
|
398
|
-
<div class="method-source-code" id="
|
410
|
+
onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
|
411
|
+
<div class="method-source-code" id="M000039-source">
|
399
412
|
<pre>
|
400
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
413
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 107</span>
|
414
|
+
107: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uri_escape</span>
|
415
|
+
108: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/([^ a-zA-Z0-9_.-]+)/n</span>) {
|
416
|
+
109: <span class="ruby-value str">'%'</span><span class="ruby-operator">+</span><span class="ruby-identifier">$1</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'H2'</span><span class="ruby-operator">*</span><span class="ruby-identifier">$1</span>.<span class="ruby-identifier">size</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">'%'</span>).<span class="ruby-identifier">upcase</span>
|
417
|
+
110: }.<span class="ruby-identifier">tr</span>(<span class="ruby-value str">' '</span>, <span class="ruby-value str">'+'</span>)
|
418
|
+
111: <span class="ruby-keyword kw">end</span>
|
406
419
|
</pre>
|
407
420
|
</div>
|
408
421
|
</div>
|
409
422
|
</div>
|
410
423
|
|
411
|
-
<div id="method-
|
412
|
-
<a name="
|
424
|
+
<div id="method-M000040" class="method-detail">
|
425
|
+
<a name="M000040"></a>
|
413
426
|
|
414
427
|
<div class="method-heading">
|
415
|
-
<a href="#
|
428
|
+
<a href="#M000040" class="method-signature">
|
416
429
|
<span class="method-name">uri_unescape</span><span class="method-args">()</span>
|
417
430
|
</a>
|
418
431
|
</div>
|
@@ -422,15 +435,15 @@ faster. Use this rather than the cgi.rb version since it‘s faster.
|
|
422
435
|
Unescapes a URI escaped string. (Stolen from Camping).
|
423
436
|
</p>
|
424
437
|
<p><a class="source-toggle" href="#"
|
425
|
-
onclick="toggleCode('
|
426
|
-
<div class="method-source-code" id="
|
438
|
+
onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
|
439
|
+
<div class="method-source-code" id="M000040-source">
|
427
440
|
<pre>
|
428
|
-
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
441
|
+
<span class="ruby-comment cmt"># File lib/mack-facets/extensions/string.rb, line 114</span>
|
442
|
+
114: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uri_unescape</span>
|
443
|
+
115: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-value str">'+'</span>, <span class="ruby-value str">' '</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/((?:%[0-9a-fA-F]{2})+)/n</span>){
|
444
|
+
116: [<span class="ruby-identifier">$1</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'%'</span>)].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'H*'</span>)
|
445
|
+
117: }
|
446
|
+
118: <span class="ruby-keyword kw">end</span>
|
434
447
|
</pre>
|
435
448
|
</div>
|
436
449
|
</div>
|