mack_ruby_core_extensions 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/classes/Array.html +74 -74
- data/doc/classes/Class.html +40 -27
- data/doc/classes/Float.html +6 -6
- data/doc/classes/Hash.html +18 -18
- data/doc/classes/Kernel.html +12 -12
- data/doc/classes/Mack/Utils/Inflector.html +56 -56
- data/doc/classes/Math.html +18 -18
- data/doc/classes/MethodNotImplemented.html +6 -6
- data/doc/classes/Module.html +12 -12
- data/doc/classes/NilClass.html +6 -6
- data/doc/classes/Object.html +42 -42
- data/doc/classes/String.html +402 -375
- data/doc/created.rid +1 -1
- data/doc/files/lib/extensions/class_rb.html +1 -1
- data/doc/files/lib/extensions/string_rb.html +1 -1
- data/doc/fr_class_index.html +0 -1
- data/doc/fr_file_index.html +0 -1
- data/doc/fr_method_index.html +65 -66
- data/lib/extensions/class.rb +8 -3
- data/lib/extensions/string.rb +5 -0
- data/test/extensions/class_test.rb +7 -15
- data/test/extensions/string_test.rb +5 -4
- data/test/test_helper.rb +15 -1
- metadata +1 -5
- data/doc/classes/Dir.html +0 -190
- data/doc/files/lib/extensions/dir_rb.html +0 -101
- data/lib/extensions/dir.rb +0 -25
- data/test/extensions/dir_test.rb +0 -15
data/doc/classes/String.html
CHANGED
@@ -88,30 +88,31 @@
|
|
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="#
|
100
|
-
<a href="#
|
101
|
-
<a href="#
|
102
|
-
<a href="#
|
103
|
-
<a href="#
|
104
|
-
<a href="#
|
105
|
-
<a href="#
|
106
|
-
<a href="#
|
107
|
-
<a href="#
|
108
|
-
<a href="#
|
109
|
-
<a href="#
|
110
|
-
<a href="#
|
111
|
-
<a href="#
|
112
|
-
<a href="#
|
113
|
-
<a href="#
|
114
|
-
<a href="#
|
91
|
+
<a href="#M000033">blank?</a>
|
92
|
+
<a href="#M000044">breakify</a>
|
93
|
+
<a href="#M000045">breakify!</a>
|
94
|
+
<a href="#M000031">camelcase</a>
|
95
|
+
<a href="#M000051">capitalize_all_words</a>
|
96
|
+
<a href="#M000052">capitalize_all_words!</a>
|
97
|
+
<a href="#M000032">constantize</a>
|
98
|
+
<a href="#M000040">ends_with?</a>
|
99
|
+
<a href="#M000046">hexdigest</a>
|
100
|
+
<a href="#M000047">hexdigest!</a>
|
101
|
+
<a href="#M000036">linkify</a>
|
102
|
+
<a href="#M000037">methodize</a>
|
103
|
+
<a href="#M000034">plural</a>
|
104
|
+
<a href="#M000041">pluralize_word</a>
|
105
|
+
<a href="#M000048">randomize</a>
|
106
|
+
<a href="#M000042">remove</a>
|
107
|
+
<a href="#M000043">remove!</a>
|
108
|
+
<a href="#M000035">singular</a>
|
109
|
+
<a href="#M000053">sql_safe_str</a>
|
110
|
+
<a href="#M000054">sql_safe_str!</a>
|
111
|
+
<a href="#M000039">starts_with?</a>
|
112
|
+
<a href="#M000030">to_instance</a>
|
113
|
+
<a href="#M000049">truncate</a>
|
114
|
+
<a href="#M000050">truncate!</a>
|
115
|
+
<a href="#M000038">underscore</a>
|
115
116
|
</div>
|
116
117
|
</div>
|
117
118
|
|
@@ -133,11 +134,11 @@
|
|
133
134
|
<div id="methods">
|
134
135
|
<h3 class="section-bar">Public Class methods</h3>
|
135
136
|
|
136
|
-
<div id="method-
|
137
|
-
<a name="
|
137
|
+
<div id="method-M000041" class="method-detail">
|
138
|
+
<a name="M000041"></a>
|
138
139
|
|
139
140
|
<div class="method-heading">
|
140
|
-
<a href="#
|
141
|
+
<a href="#M000041" class="method-signature">
|
141
142
|
<span class="method-name">pluralize_word</span><span class="method-args">(num, vals = ["is", "are"])</span>
|
142
143
|
</a>
|
143
144
|
</div>
|
@@ -148,40 +149,40 @@ Returns "is" or "are" based on the number, i.e.
|
|
148
149
|
"i=6; There #{isare(i)} #{i} topics here."
|
149
150
|
</p>
|
150
151
|
<p><a class="source-toggle" href="#"
|
151
|
-
onclick="toggleCode('
|
152
|
-
<div class="method-source-code" id="
|
152
|
+
onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
|
153
|
+
<div class="method-source-code" id="M000041-source">
|
153
154
|
<pre>
|
154
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
155
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 170</span>
|
156
|
+
170: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pluralize_word</span>(<span class="ruby-identifier">num</span>, <span class="ruby-identifier">vals</span> = [<span class="ruby-value str">"is"</span>, <span class="ruby-value str">"are"</span>])
|
157
|
+
171: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">vals</span>[<span class="ruby-value">0</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">num</span>.<span class="ruby-identifier">to_i</span><span class="ruby-operator">==</span><span class="ruby-value">1</span>
|
158
|
+
172: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">vals</span>[<span class="ruby-value">1</span>]
|
159
|
+
173: <span class="ruby-keyword kw">end</span>
|
159
160
|
</pre>
|
160
161
|
</div>
|
161
162
|
</div>
|
162
163
|
</div>
|
163
164
|
|
164
|
-
<div id="method-
|
165
|
-
<a name="
|
165
|
+
<div id="method-M000048" class="method-detail">
|
166
|
+
<a name="M000048"></a>
|
166
167
|
|
167
168
|
<div class="method-heading">
|
168
|
-
<a href="#
|
169
|
+
<a href="#M000048" class="method-signature">
|
169
170
|
<span class="method-name">randomize</span><span class="method-args">(length = 10)</span>
|
170
171
|
</a>
|
171
172
|
</div>
|
172
173
|
|
173
174
|
<div class="method-description">
|
174
175
|
<p><a class="source-toggle" href="#"
|
175
|
-
onclick="toggleCode('
|
176
|
-
<div class="method-source-code" id="
|
176
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
177
|
+
<div class="method-source-code" id="M000048-source">
|
177
178
|
<pre>
|
178
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
179
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 224</span>
|
180
|
+
224: <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>)
|
181
|
+
225: <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>
|
182
|
+
226: <span class="ruby-identifier">newpass</span> = <span class="ruby-value str">""</span>
|
183
|
+
227: <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>)] }
|
184
|
+
228: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">newpass</span>.<span class="ruby-identifier">upcase</span>
|
185
|
+
229: <span class="ruby-keyword kw">end</span>
|
185
186
|
</pre>
|
186
187
|
</div>
|
187
188
|
</div>
|
@@ -189,11 +190,11 @@ Returns "is" or "are" based on the number, i.e.
|
|
189
190
|
|
190
191
|
<h3 class="section-bar">Public Instance methods</h3>
|
191
192
|
|
192
|
-
<div id="method-
|
193
|
-
<a name="
|
193
|
+
<div id="method-M000033" class="method-detail">
|
194
|
+
<a name="M000033"></a>
|
194
195
|
|
195
196
|
<div class="method-heading">
|
196
|
-
<a href="#
|
197
|
+
<a href="#M000033" class="method-signature">
|
197
198
|
<span class="method-name">blank?</span><span class="method-args">()</span>
|
198
199
|
</a>
|
199
200
|
</div>
|
@@ -203,23 +204,23 @@ Returns "is" or "are" based on the number, i.e.
|
|
203
204
|
If the string is empty, this will return true.
|
204
205
|
</p>
|
205
206
|
<p><a class="source-toggle" href="#"
|
206
|
-
onclick="toggleCode('
|
207
|
-
<div class="method-source-code" id="
|
207
|
+
onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
|
208
|
+
<div class="method-source-code" id="M000033-source">
|
208
209
|
<pre>
|
209
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
210
|
-
|
211
|
-
|
212
|
-
|
210
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 30</span>
|
211
|
+
30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">blank?</span>
|
212
|
+
31: <span class="ruby-keyword kw">self</span> <span class="ruby-operator">==</span> <span class="ruby-value str">""</span>
|
213
|
+
32: <span class="ruby-keyword kw">end</span>
|
213
214
|
</pre>
|
214
215
|
</div>
|
215
216
|
</div>
|
216
217
|
</div>
|
217
218
|
|
218
|
-
<div id="method-
|
219
|
-
<a name="
|
219
|
+
<div id="method-M000044" class="method-detail">
|
220
|
+
<a name="M000044"></a>
|
220
221
|
|
221
222
|
<div class="method-heading">
|
222
|
-
<a href="#
|
223
|
+
<a href="#M000044" class="method-signature">
|
223
224
|
<span class="method-name">breakify</span><span class="method-args">(every = 30)</span>
|
224
225
|
</a>
|
225
226
|
</div>
|
@@ -237,66 +238,66 @@ note: if the txt has spaces, this will only try to break up runs of
|
|
237
238
|
non-space characters longer than "every" characters
|
238
239
|
</p>
|
239
240
|
<p><a class="source-toggle" href="#"
|
240
|
-
onclick="toggleCode('
|
241
|
-
<div class="method-source-code" id="
|
241
|
+
onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
|
242
|
+
<div class="method-source-code" id="M000044-source">
|
242
243
|
<pre>
|
243
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
244
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 188</span>
|
245
|
+
188: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">breakify</span>(<span class="ruby-identifier">every</span> = <span class="ruby-value">30</span>)
|
246
|
+
189: <span class="ruby-identifier">every</span> = <span class="ruby-value">1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">every</span> <span class="ruby-operator"><</span> <span class="ruby-value">1</span>
|
247
|
+
190: <span class="ruby-identifier">text</span> = <span class="ruby-keyword kw">self</span>
|
248
|
+
191: <span class="ruby-identifier">textile_regex</span> = <span class="ruby-regexp re">/\"([^\"]+)\":([^:]*:[\/\/]{0,1}[^ ]*)/</span>
|
249
|
+
192: <span class="ruby-identifier">long_regex</span> = <span class="ruby-node">/\S{#{every},}/</span>
|
250
|
+
193: <span class="ruby-identifier">brokentxt</span> = <span class="ruby-identifier">text</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-identifier">long_regex</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">longword</span><span class="ruby-operator">|</span>
|
251
|
+
194: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">longword</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">textile_regex</span> <span class="ruby-comment cmt">#if the longword is a textile link...ignore and recheck for the link text only</span>
|
252
|
+
195: <span class="ruby-identifier">textile_link</span> = <span class="ruby-identifier">textile_regex</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">longword</span>)[<span class="ruby-value">0</span>]
|
253
|
+
196: <span class="ruby-identifier">link_text</span> = <span class="ruby-identifier">textile_regex</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">longword</span>)[<span class="ruby-value">1</span>]
|
254
|
+
197: <span class="ruby-identifier">longword</span> = <span class="ruby-identifier">link_text</span>
|
255
|
+
198: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">longword</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">long_regex</span> <span class="ruby-comment cmt">#link text is long...allow break</span>
|
256
|
+
199: <span class="ruby-identifier">textile_link</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-node">/.{1,#{every}}/</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">"<wbr/>"</span>)
|
257
|
+
200: <span class="ruby-keyword kw">else</span>
|
258
|
+
201: <span class="ruby-identifier">textile_link</span> <span class="ruby-comment cmt">#the url is what triggered the match...so leave it alone</span>
|
259
|
+
202: <span class="ruby-keyword kw">end</span>
|
260
|
+
203: <span class="ruby-keyword kw">else</span>
|
261
|
+
204: <span class="ruby-identifier">longword</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-node">/.{1,#{every}}/</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">"<wbr/>"</span>) <span class="ruby-comment cmt">#no textile link matched</span>
|
262
|
+
205: <span class="ruby-keyword kw">end</span>
|
263
|
+
206: <span class="ruby-keyword kw">end</span>
|
264
|
+
207: <span class="ruby-comment cmt">#text = %Q[<span style='word-wrap:break-word;wbr:after{content:"\\00200B"}'>#{brokentxt}</span>]</span>
|
265
|
+
208: <span class="ruby-comment cmt">#brokentxt.gsub("<wbr/>", "<br />")</span>
|
266
|
+
209: <span class="ruby-identifier">brokentxt</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"<wbr/>"</span>, <span class="ruby-value str">" "</span>)
|
267
|
+
210: <span class="ruby-keyword kw">end</span>
|
267
268
|
</pre>
|
268
269
|
</div>
|
269
270
|
</div>
|
270
271
|
</div>
|
271
272
|
|
272
|
-
<div id="method-
|
273
|
-
<a name="
|
273
|
+
<div id="method-M000045" class="method-detail">
|
274
|
+
<a name="M000045"></a>
|
274
275
|
|
275
276
|
<div class="method-heading">
|
276
|
-
<a href="#
|
277
|
+
<a href="#M000045" class="method-signature">
|
277
278
|
<span class="method-name">breakify!</span><span class="method-args">(every = 30)</span>
|
278
279
|
</a>
|
279
280
|
</div>
|
280
281
|
|
281
282
|
<div class="method-description">
|
282
283
|
<p><a class="source-toggle" href="#"
|
283
|
-
onclick="toggleCode('
|
284
|
-
<div class="method-source-code" id="
|
284
|
+
onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
|
285
|
+
<div class="method-source-code" id="M000045-source">
|
285
286
|
<pre>
|
286
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
287
|
-
|
288
|
-
|
289
|
-
|
287
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 212</span>
|
288
|
+
212: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">breakify!</span>(<span class="ruby-identifier">every</span> = <span class="ruby-value">30</span>)
|
289
|
+
213: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">breakify</span>(<span class="ruby-identifier">every</span>))
|
290
|
+
214: <span class="ruby-keyword kw">end</span>
|
290
291
|
</pre>
|
291
292
|
</div>
|
292
293
|
</div>
|
293
294
|
</div>
|
294
295
|
|
295
|
-
<div id="method-
|
296
|
-
<a name="
|
296
|
+
<div id="method-M000031" class="method-detail">
|
297
|
+
<a name="M000031"></a>
|
297
298
|
|
298
299
|
<div class="method-heading">
|
299
|
-
<a href="#
|
300
|
+
<a href="#M000031" class="method-signature">
|
300
301
|
<span class="method-name">camelcase</span><span class="method-args">()</span>
|
301
302
|
</a>
|
302
303
|
</div>
|
@@ -314,69 +315,69 @@ Examples:
|
|
314
315
|
"my/blog".camelcase # => My::Blog
|
315
316
|
</pre>
|
316
317
|
<p><a class="source-toggle" href="#"
|
317
|
-
onclick="toggleCode('
|
318
|
-
<div class="method-source-code" id="
|
318
|
+
onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
|
319
|
+
<div class="method-source-code" id="M000031-source">
|
319
320
|
<pre>
|
320
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
321
|
-
|
322
|
-
|
323
|
-
|
321
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 15</span>
|
322
|
+
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">camelcase</span>
|
323
|
+
16: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\/(.?)/</span>) { <span class="ruby-value str">"::"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">upcase</span> }.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/(^|_)(.)/</span>) { <span class="ruby-identifier">$2</span>.<span class="ruby-identifier">upcase</span> }
|
324
|
+
17: <span class="ruby-keyword kw">end</span>
|
324
325
|
</pre>
|
325
326
|
</div>
|
326
327
|
</div>
|
327
328
|
</div>
|
328
329
|
|
329
|
-
<div id="method-
|
330
|
-
<a name="
|
330
|
+
<div id="method-M000051" class="method-detail">
|
331
|
+
<a name="M000051"></a>
|
331
332
|
|
332
333
|
<div class="method-heading">
|
333
|
-
<a href="#
|
334
|
+
<a href="#M000051" class="method-signature">
|
334
335
|
<span class="method-name">capitalize_all_words</span><span class="method-args">()</span>
|
335
336
|
</a>
|
336
337
|
</div>
|
337
338
|
|
338
339
|
<div class="method-description">
|
339
340
|
<p><a class="source-toggle" href="#"
|
340
|
-
onclick="toggleCode('
|
341
|
-
<div class="method-source-code" id="
|
341
|
+
onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
|
342
|
+
<div class="method-source-code" id="M000051-source">
|
342
343
|
<pre>
|
343
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
344
|
-
|
345
|
-
|
346
|
-
|
344
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 246</span>
|
345
|
+
246: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">capitalize_all_words</span>
|
346
|
+
247: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\b\w/</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">upcase</span>}
|
347
|
+
248: <span class="ruby-keyword kw">end</span>
|
347
348
|
</pre>
|
348
349
|
</div>
|
349
350
|
</div>
|
350
351
|
</div>
|
351
352
|
|
352
|
-
<div id="method-
|
353
|
-
<a name="
|
353
|
+
<div id="method-M000052" class="method-detail">
|
354
|
+
<a name="M000052"></a>
|
354
355
|
|
355
356
|
<div class="method-heading">
|
356
|
-
<a href="#
|
357
|
+
<a href="#M000052" class="method-signature">
|
357
358
|
<span class="method-name">capitalize_all_words!</span><span class="method-args">()</span>
|
358
359
|
</a>
|
359
360
|
</div>
|
360
361
|
|
361
362
|
<div class="method-description">
|
362
363
|
<p><a class="source-toggle" href="#"
|
363
|
-
onclick="toggleCode('
|
364
|
-
<div class="method-source-code" id="
|
364
|
+
onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
|
365
|
+
<div class="method-source-code" id="M000052-source">
|
365
366
|
<pre>
|
366
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
367
|
-
|
368
|
-
|
369
|
-
|
367
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 250</span>
|
368
|
+
250: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">capitalize_all_words!</span>
|
369
|
+
251: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">capitalize_all_words</span>)
|
370
|
+
252: <span class="ruby-keyword kw">end</span>
|
370
371
|
</pre>
|
371
372
|
</div>
|
372
373
|
</div>
|
373
374
|
</div>
|
374
375
|
|
375
|
-
<div id="method-
|
376
|
-
<a name="
|
376
|
+
<div id="method-M000032" class="method-detail">
|
377
|
+
<a name="M000032"></a>
|
377
378
|
|
378
379
|
<div class="method-heading">
|
379
|
-
<a href="#
|
380
|
+
<a href="#M000032" class="method-signature">
|
380
381
|
<span class="method-name">constantize</span><span class="method-args">()</span>
|
381
382
|
</a>
|
382
383
|
</div>
|
@@ -394,238 +395,238 @@ Examples:
|
|
394
395
|
"Mack::Configuration" # => Mack::Configuration
|
395
396
|
</pre>
|
396
397
|
<p><a class="source-toggle" href="#"
|
397
|
-
onclick="toggleCode('
|
398
|
-
<div class="method-source-code" id="
|
398
|
+
onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
|
399
|
+
<div class="method-source-code" id="M000032-source">
|
399
400
|
<pre>
|
400
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
401
|
-
|
402
|
-
|
403
|
-
|
401
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 25</span>
|
402
|
+
25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">constantize</span>
|
403
|
+
26: <span class="ruby-constant">Module</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-node">"::#{self}"</span>)
|
404
|
+
27: <span class="ruby-keyword kw">end</span>
|
404
405
|
</pre>
|
405
406
|
</div>
|
406
407
|
</div>
|
407
408
|
</div>
|
408
409
|
|
409
|
-
<div id="method-
|
410
|
-
<a name="
|
410
|
+
<div id="method-M000040" class="method-detail">
|
411
|
+
<a name="M000040"></a>
|
411
412
|
|
412
413
|
<div class="method-heading">
|
413
|
-
<a href="#
|
414
|
+
<a href="#M000040" class="method-signature">
|
414
415
|
<span class="method-name">ends_with?</span><span class="method-args">(x)</span>
|
415
416
|
</a>
|
416
417
|
</div>
|
417
418
|
|
418
419
|
<div class="method-description">
|
419
420
|
<p><a class="source-toggle" href="#"
|
420
|
-
onclick="toggleCode('
|
421
|
-
<div class="method-source-code" id="
|
421
|
+
onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
|
422
|
+
<div class="method-source-code" id="M000040-source">
|
422
423
|
<pre>
|
423
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
424
|
-
|
425
|
-
|
426
|
-
|
424
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 165</span>
|
425
|
+
165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ends_with?</span>(<span class="ruby-identifier">x</span>)
|
426
|
+
166: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/#{x}$/</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
|
427
|
+
167: <span class="ruby-keyword kw">end</span>
|
427
428
|
</pre>
|
428
429
|
</div>
|
429
430
|
</div>
|
430
431
|
</div>
|
431
432
|
|
432
|
-
<div id="method-
|
433
|
-
<a name="
|
433
|
+
<div id="method-M000046" class="method-detail">
|
434
|
+
<a name="M000046"></a>
|
434
435
|
|
435
436
|
<div class="method-heading">
|
436
|
-
<a href="#
|
437
|
+
<a href="#M000046" class="method-signature">
|
437
438
|
<span class="method-name">hexdigest</span><span class="method-args">()</span>
|
438
439
|
</a>
|
439
440
|
</div>
|
440
441
|
|
441
442
|
<div class="method-description">
|
442
443
|
<p><a class="source-toggle" href="#"
|
443
|
-
onclick="toggleCode('
|
444
|
-
<div class="method-source-code" id="
|
444
|
+
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
445
|
+
<div class="method-source-code" id="M000046-source">
|
445
446
|
<pre>
|
446
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
447
|
-
|
448
|
-
|
449
|
-
|
447
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 216</span>
|
448
|
+
216: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hexdigest</span>
|
449
|
+
217: <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>.<span class="ruby-identifier">downcase</span>)
|
450
|
+
218: <span class="ruby-keyword kw">end</span>
|
450
451
|
</pre>
|
451
452
|
</div>
|
452
453
|
</div>
|
453
454
|
</div>
|
454
455
|
|
455
|
-
<div id="method-
|
456
|
-
<a name="
|
456
|
+
<div id="method-M000047" class="method-detail">
|
457
|
+
<a name="M000047"></a>
|
457
458
|
|
458
459
|
<div class="method-heading">
|
459
|
-
<a href="#
|
460
|
+
<a href="#M000047" class="method-signature">
|
460
461
|
<span class="method-name">hexdigest!</span><span class="method-args">()</span>
|
461
462
|
</a>
|
462
463
|
</div>
|
463
464
|
|
464
465
|
<div class="method-description">
|
465
466
|
<p><a class="source-toggle" href="#"
|
466
|
-
onclick="toggleCode('
|
467
|
-
<div class="method-source-code" id="
|
467
|
+
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
468
|
+
<div class="method-source-code" id="M000047-source">
|
468
469
|
<pre>
|
469
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
470
|
-
|
471
|
-
|
472
|
-
|
470
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 220</span>
|
471
|
+
220: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hexdigest!</span>
|
472
|
+
221: <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>)
|
473
|
+
222: <span class="ruby-keyword kw">end</span>
|
473
474
|
</pre>
|
474
475
|
</div>
|
475
476
|
</div>
|
476
477
|
</div>
|
477
478
|
|
478
|
-
<div id="method-
|
479
|
-
<a name="
|
479
|
+
<div id="method-M000036" class="method-detail">
|
480
|
+
<a name="M000036"></a>
|
480
481
|
|
481
482
|
<div class="method-heading">
|
482
|
-
<a href="#
|
483
|
+
<a href="#M000036" class="method-signature">
|
483
484
|
<span class="method-name">linkify</span><span class="method-args">(enabled = true, options = {}) {|t, url, options| ...}</span>
|
484
485
|
</a>
|
485
486
|
</div>
|
486
487
|
|
487
488
|
<div class="method-description">
|
488
489
|
<p><a class="source-toggle" href="#"
|
489
|
-
onclick="toggleCode('
|
490
|
-
<div class="method-source-code" id="
|
490
|
+
onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
|
491
|
+
<div class="method-source-code" id="M000036-source">
|
491
492
|
<pre>
|
492
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
493
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 44</span>
|
494
|
+
44: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">linkify</span>(<span class="ruby-identifier">enabled</span> = <span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
495
|
+
45: <span class="ruby-identifier">text</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>
|
496
|
+
46: <span class="ruby-identifier">m</span> = <span class="ruby-identifier">text</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/\"([^"]+)\"\:([^:]+\:\S+)/</span>)
|
497
|
+
47: <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">nil?</span>
|
498
|
+
48: <span class="ruby-identifier">y</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">to_s</span>
|
499
|
+
49: <span class="ruby-identifier">t</span> = <span class="ruby-identifier">m</span>[<span class="ruby-value">1</span>]
|
500
|
+
50: <span class="ruby-identifier">url</span> = <span class="ruby-identifier">m</span>[<span class="ruby-value">2</span>]
|
501
|
+
51:
|
502
|
+
52: <span class="ruby-comment cmt"># The code below handles punctuation or p tags being mistakenly added to the url when the link is at the end of a sentence or body</span>
|
503
|
+
53: <span class="ruby-identifier">url_punct_match</span> = <span class="ruby-regexp re">/\W*[&nbsp;]*[\<\/p\>]*$/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">url</span>)
|
504
|
+
54: <span class="ruby-identifier">punct</span> = <span class="ruby-value str">''</span>
|
505
|
+
55: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">url_punct_match</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">url_punct_match</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">!=</span> <span class="ruby-value str">""</span>
|
506
|
+
56: <span class="ruby-identifier">url</span>.<span class="ruby-identifier">chomp!</span>(<span class="ruby-identifier">url_punct_match</span>[<span class="ruby-value">0</span>])
|
507
|
+
57: <span class="ruby-identifier">punct</span> = <span class="ruby-identifier">url_punct_match</span>[<span class="ruby-value">0</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">url_punct_match</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"="</span>
|
508
|
+
58: <span class="ruby-keyword kw">end</span>
|
509
|
+
59:
|
510
|
+
60: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
511
|
+
61: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">enabled</span>
|
512
|
+
62: <span class="ruby-identifier">ret</span> = <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">t</span>, <span class="ruby-identifier">url</span>, <span class="ruby-identifier">options</span>
|
513
|
+
63: <span class="ruby-identifier">text</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">y</span>, <span class="ruby-identifier">ret</span>)
|
514
|
+
64: <span class="ruby-keyword kw">else</span>
|
515
|
+
65: <span class="ruby-identifier">text</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">y</span>, <span class="ruby-identifier">t</span>.<span class="ruby-identifier">to_s</span>)
|
516
|
+
66: <span class="ruby-keyword kw">end</span>
|
517
|
+
67: <span class="ruby-keyword kw">else</span>
|
518
|
+
68: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">enabled</span>
|
519
|
+
69: <span class="ruby-identifier">text</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">y</span>, <span class="ruby-node">"<a href=\"#{url}\" #{options.join("%s=\"%s\"", " ")}>#{t}</a>#{punct}"</span>)<span class="ruby-comment cmt"># punct places punctuation back into proper place</span>
|
520
|
+
70: <span class="ruby-keyword kw">else</span>
|
521
|
+
71: <span class="ruby-identifier">text</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">y</span>, <span class="ruby-identifier">t</span>.<span class="ruby-identifier">to_s</span>)
|
522
|
+
72: <span class="ruby-keyword kw">end</span>
|
523
|
+
73: <span class="ruby-keyword kw">end</span>
|
524
|
+
74: <span class="ruby-identifier">m</span> = <span class="ruby-identifier">text</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/\"([^"]+)\"\:([^:]+\:\S+)/</span>)
|
525
|
+
75: <span class="ruby-keyword kw">end</span>
|
526
|
+
76: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">text</span>
|
527
|
+
77: <span class="ruby-keyword kw">end</span>
|
527
528
|
</pre>
|
528
529
|
</div>
|
529
530
|
</div>
|
530
531
|
</div>
|
531
532
|
|
532
|
-
<div id="method-
|
533
|
-
<a name="
|
533
|
+
<div id="method-M000037" class="method-detail">
|
534
|
+
<a name="M000037"></a>
|
534
535
|
|
535
536
|
<div class="method-heading">
|
536
|
-
<a href="#
|
537
|
+
<a href="#M000037" class="method-signature">
|
537
538
|
<span class="method-name">methodize</span><span class="method-args">()</span>
|
538
539
|
</a>
|
539
540
|
</div>
|
540
541
|
|
541
542
|
<div class="method-description">
|
542
543
|
<p><a class="source-toggle" href="#"
|
543
|
-
onclick="toggleCode('
|
544
|
-
<div class="method-source-code" id="
|
544
|
+
onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
|
545
|
+
<div class="method-source-code" id="M000037-source">
|
545
546
|
<pre>
|
546
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
82:
|
556
|
-
83: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
557
|
-
84: <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>
|
558
|
-
85:
|
559
|
-
86: <span class="ruby-identifier">x</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">underscore</span>
|
547
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 79</span>
|
548
|
+
79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">methodize</span>
|
549
|
+
80: <span class="ruby-identifier">x</span> = <span class="ruby-keyword kw">self</span>
|
550
|
+
81:
|
551
|
+
82: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
552
|
+
83: <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>
|
553
|
+
84:
|
554
|
+
85: <span class="ruby-comment cmt"># get rid of the big stuff in the front/back</span>
|
555
|
+
86: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">strip!</span>
|
560
556
|
87:
|
561
|
-
88: <span class="ruby-comment cmt"># get
|
562
|
-
89: <span class="ruby-identifier">
|
563
|
-
90:
|
564
|
-
91: <span class="ruby-identifier">x</span
|
557
|
+
88: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
558
|
+
89: <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>
|
559
|
+
90:
|
560
|
+
91: <span class="ruby-identifier">x</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">underscore</span>
|
565
561
|
92:
|
566
|
-
93: <span class="ruby-comment cmt">#
|
567
|
-
94: <span class="ruby-identifier">
|
568
|
-
95:
|
569
|
-
96: <span class="ruby-
|
570
|
-
97:
|
571
|
-
98:
|
572
|
-
99:
|
573
|
-
100:
|
574
|
-
101:
|
575
|
-
102: <span class="ruby-comment cmt">#
|
576
|
-
103: <span class="ruby-
|
577
|
-
104:
|
578
|
-
105: <span class="ruby-
|
579
|
-
106:
|
580
|
-
107:
|
581
|
-
108: <span class="ruby-
|
582
|
-
109:
|
583
|
-
110:
|
584
|
-
111:
|
585
|
-
112:
|
586
|
-
113:
|
587
|
-
114: <span class="ruby-keyword kw">
|
588
|
-
115:
|
589
|
-
116:
|
590
|
-
117:
|
591
|
-
118:
|
592
|
-
119: <span class="ruby-
|
562
|
+
93: <span class="ruby-comment cmt"># get rid of spaces and make the _</span>
|
563
|
+
94: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">' '</span>, <span class="ruby-value str">'_'</span>)
|
564
|
+
95: <span class="ruby-comment cmt"># get rid of everything that isn't 'safe' a-z, 0-9, ?, !, =, _</span>
|
565
|
+
96: <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>)
|
566
|
+
97:
|
567
|
+
98: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
568
|
+
99: <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>
|
569
|
+
100:
|
570
|
+
101: <span class="ruby-comment cmt"># condense multiple 'safe' non a-z chars to just one.</span>
|
571
|
+
102: <span class="ruby-comment cmt"># ie. ___ becomes _ !!!! becomes ! etc...</span>
|
572
|
+
103: [<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>
|
573
|
+
104: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">squeeze!</span>(<span class="ruby-identifier">c</span>)
|
574
|
+
105: <span class="ruby-keyword kw">end</span>
|
575
|
+
106:
|
576
|
+
107: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
577
|
+
108: <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>
|
578
|
+
109:
|
579
|
+
110: <span class="ruby-comment cmt">#down case the whole thing</span>
|
580
|
+
111: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">downcase!</span>
|
581
|
+
112:
|
582
|
+
113: <span class="ruby-comment cmt"># get rid of any characters at the beginning that aren't a-z</span>
|
583
|
+
114: <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>)
|
584
|
+
115: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span>)
|
585
|
+
116:
|
586
|
+
117: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
587
|
+
118: <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>
|
588
|
+
119: <span class="ruby-keyword kw">end</span>
|
593
589
|
120:
|
594
|
-
121: <span class="ruby-comment cmt">#
|
595
|
-
122: <span class="ruby-
|
596
|
-
123:
|
597
|
-
124:
|
598
|
-
125:
|
599
|
-
126: <span class="ruby-
|
600
|
-
127:
|
601
|
-
128:
|
602
|
-
129:
|
603
|
-
130:
|
604
|
-
131: <span class="ruby-
|
605
|
-
132:
|
606
|
-
133: <span class="ruby-
|
607
|
-
134:
|
608
|
-
135:
|
609
|
-
136:
|
610
|
-
137: <span class="ruby-
|
611
|
-
138:
|
612
|
-
139:
|
613
|
-
140: <span class="ruby-
|
614
|
-
141:
|
615
|
-
142: <span class="ruby-
|
616
|
-
143:
|
617
|
-
144: <span class="ruby-
|
618
|
-
145:
|
590
|
+
121: <span class="ruby-comment cmt"># let's trim this bad boy down a bit now that we've cleaned it up, somewhat.</span>
|
591
|
+
122: <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>
|
592
|
+
123: <span class="ruby-comment cmt"># bad char at the end if you trim too late.</span>
|
593
|
+
124: <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>
|
594
|
+
125:
|
595
|
+
126: <span class="ruby-comment cmt"># get rid of any characters at the end that aren't safe</span>
|
596
|
+
127: <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>)
|
597
|
+
128: <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>)
|
598
|
+
129: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
599
|
+
130: <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>
|
600
|
+
131: <span class="ruby-keyword kw">end</span>
|
601
|
+
132:
|
602
|
+
133: <span class="ruby-comment cmt"># if we get down to a nil or an empty string raise an exception! </span>
|
603
|
+
134: <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>
|
604
|
+
135:
|
605
|
+
136: <span class="ruby-comment cmt"># let's get rid of characters that don't belong in the 'middle' of the method.</span>
|
606
|
+
137: <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>)]
|
607
|
+
138: <span class="ruby-identifier">n_middle</span> = <span class="ruby-identifier">orig_middle</span>.<span class="ruby-identifier">dup</span>
|
608
|
+
139:
|
609
|
+
140: [<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>
|
610
|
+
141: <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>)
|
611
|
+
142: <span class="ruby-keyword kw">end</span>
|
612
|
+
143:
|
613
|
+
144: <span class="ruby-comment cmt"># the previous gsub can leave us with multiple underscores that need cleaning up.</span>
|
614
|
+
145: <span class="ruby-identifier">n_middle</span>.<span class="ruby-identifier">squeeze!</span>(<span class="ruby-value str">"_"</span>)
|
615
|
+
146:
|
616
|
+
147: <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>)
|
617
|
+
148: <span class="ruby-identifier">x</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">"_="</span>, <span class="ruby-value str">"="</span>)
|
618
|
+
149: <span class="ruby-identifier">x</span>
|
619
|
+
150: <span class="ruby-keyword kw">end</span>
|
619
620
|
</pre>
|
620
621
|
</div>
|
621
622
|
</div>
|
622
623
|
</div>
|
623
624
|
|
624
|
-
<div id="method-
|
625
|
-
<a name="
|
625
|
+
<div id="method-M000034" class="method-detail">
|
626
|
+
<a name="M000034"></a>
|
626
627
|
|
627
628
|
<div class="method-heading">
|
628
|
-
<a href="#
|
629
|
+
<a href="#M000034" class="method-signature">
|
629
630
|
<span class="method-name">plural</span><span class="method-args">()</span>
|
630
631
|
</a>
|
631
632
|
</div>
|
@@ -635,69 +636,69 @@ Examples:
|
|
635
636
|
Maps to Mack::Utils::Inflector.instance.pluralize
|
636
637
|
</p>
|
637
638
|
<p><a class="source-toggle" href="#"
|
638
|
-
onclick="toggleCode('
|
639
|
-
<div class="method-source-code" id="
|
639
|
+
onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
|
640
|
+
<div class="method-source-code" id="M000034-source">
|
640
641
|
<pre>
|
641
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
642
|
-
|
643
|
-
|
644
|
-
|
642
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 35</span>
|
643
|
+
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">plural</span>
|
644
|
+
36: <span class="ruby-constant">Mack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span><span class="ruby-operator">::</span><span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">pluralize</span>(<span class="ruby-keyword kw">self</span>)
|
645
|
+
37: <span class="ruby-keyword kw">end</span>
|
645
646
|
</pre>
|
646
647
|
</div>
|
647
648
|
</div>
|
648
649
|
</div>
|
649
650
|
|
650
|
-
<div id="method-
|
651
|
-
<a name="
|
651
|
+
<div id="method-M000042" class="method-detail">
|
652
|
+
<a name="M000042"></a>
|
652
653
|
|
653
654
|
<div class="method-heading">
|
654
|
-
<a href="#
|
655
|
+
<a href="#M000042" class="method-signature">
|
655
656
|
<span class="method-name">remove</span><span class="method-args">(val)</span>
|
656
657
|
</a>
|
657
658
|
</div>
|
658
659
|
|
659
660
|
<div class="method-description">
|
660
661
|
<p><a class="source-toggle" href="#"
|
661
|
-
onclick="toggleCode('
|
662
|
-
<div class="method-source-code" id="
|
662
|
+
onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
|
663
|
+
<div class="method-source-code" id="M000042-source">
|
663
664
|
<pre>
|
664
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
665
|
-
|
666
|
-
|
667
|
-
|
665
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 175</span>
|
666
|
+
175: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove</span>(<span class="ruby-identifier">val</span>)
|
667
|
+
176: <span class="ruby-identifier">gsub</span>(<span class="ruby-identifier">val</span>, <span class="ruby-value str">''</span>)
|
668
|
+
177: <span class="ruby-keyword kw">end</span>
|
668
669
|
</pre>
|
669
670
|
</div>
|
670
671
|
</div>
|
671
672
|
</div>
|
672
673
|
|
673
|
-
<div id="method-
|
674
|
-
<a name="
|
674
|
+
<div id="method-M000043" class="method-detail">
|
675
|
+
<a name="M000043"></a>
|
675
676
|
|
676
677
|
<div class="method-heading">
|
677
|
-
<a href="#
|
678
|
+
<a href="#M000043" class="method-signature">
|
678
679
|
<span class="method-name">remove!</span><span class="method-args">(val)</span>
|
679
680
|
</a>
|
680
681
|
</div>
|
681
682
|
|
682
683
|
<div class="method-description">
|
683
684
|
<p><a class="source-toggle" href="#"
|
684
|
-
onclick="toggleCode('
|
685
|
-
<div class="method-source-code" id="
|
685
|
+
onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
|
686
|
+
<div class="method-source-code" id="M000043-source">
|
686
687
|
<pre>
|
687
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
688
|
-
|
689
|
-
|
690
|
-
|
688
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 179</span>
|
689
|
+
179: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove!</span>(<span class="ruby-identifier">val</span>)
|
690
|
+
180: <span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">val</span>, <span class="ruby-value str">''</span>)
|
691
|
+
181: <span class="ruby-keyword kw">end</span>
|
691
692
|
</pre>
|
692
693
|
</div>
|
693
694
|
</div>
|
694
695
|
</div>
|
695
696
|
|
696
|
-
<div id="method-
|
697
|
-
<a name="
|
697
|
+
<div id="method-M000035" class="method-detail">
|
698
|
+
<a name="M000035"></a>
|
698
699
|
|
699
700
|
<div class="method-heading">
|
700
|
-
<a href="#
|
701
|
+
<a href="#M000035" class="method-signature">
|
701
702
|
<span class="method-name">singular</span><span class="method-args">()</span>
|
702
703
|
</a>
|
703
704
|
</div>
|
@@ -707,23 +708,23 @@ Maps to Mack::Utils::Inflector.instance.pluralize
|
|
707
708
|
Maps to Mack::Utils::Inflector.instance.singularize
|
708
709
|
</p>
|
709
710
|
<p><a class="source-toggle" href="#"
|
710
|
-
onclick="toggleCode('
|
711
|
-
<div class="method-source-code" id="
|
711
|
+
onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
|
712
|
+
<div class="method-source-code" id="M000035-source">
|
712
713
|
<pre>
|
713
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
714
|
-
|
715
|
-
|
716
|
-
|
714
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 40</span>
|
715
|
+
40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">singular</span>
|
716
|
+
41: <span class="ruby-constant">Mack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span><span class="ruby-operator">::</span><span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">singularize</span>(<span class="ruby-keyword kw">self</span>)
|
717
|
+
42: <span class="ruby-keyword kw">end</span>
|
717
718
|
</pre>
|
718
719
|
</div>
|
719
720
|
</div>
|
720
721
|
</div>
|
721
722
|
|
722
|
-
<div id="method-
|
723
|
-
<a name="
|
723
|
+
<div id="method-M000053" class="method-detail">
|
724
|
+
<a name="M000053"></a>
|
724
725
|
|
725
726
|
<div class="method-heading">
|
726
|
-
<a href="#
|
727
|
+
<a href="#M000053" class="method-signature">
|
727
728
|
<span class="method-name">sql_safe_str</span><span class="method-args">()</span>
|
728
729
|
</a>
|
729
730
|
</div>
|
@@ -734,142 +735,168 @@ keep adding on to this whenever it becomes apparent that unsafe strings
|
|
734
735
|
could get passed through into the database
|
735
736
|
</p>
|
736
737
|
<p><a class="source-toggle" href="#"
|
737
|
-
onclick="toggleCode('
|
738
|
-
<div class="method-source-code" id="
|
738
|
+
onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
|
739
|
+
<div class="method-source-code" id="M000053-source">
|
739
740
|
<pre>
|
740
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
741
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 256</span>
|
742
|
+
256: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sql_safe_str</span>
|
743
|
+
257: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">nil?</span>
|
744
|
+
258: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[\']/</span>, <span class="ruby-value str">"\'\'"</span>)
|
745
|
+
259: <span class="ruby-keyword kw">end</span>
|
746
|
+
260: <span class="ruby-keyword kw">end</span>
|
746
747
|
</pre>
|
747
748
|
</div>
|
748
749
|
</div>
|
749
750
|
</div>
|
750
751
|
|
751
|
-
<div id="method-
|
752
|
-
<a name="
|
752
|
+
<div id="method-M000054" class="method-detail">
|
753
|
+
<a name="M000054"></a>
|
753
754
|
|
754
755
|
<div class="method-heading">
|
755
|
-
<a href="#
|
756
|
+
<a href="#M000054" class="method-signature">
|
756
757
|
<span class="method-name">sql_safe_str!</span><span class="method-args">()</span>
|
757
758
|
</a>
|
758
759
|
</div>
|
759
760
|
|
760
761
|
<div class="method-description">
|
761
762
|
<p><a class="source-toggle" href="#"
|
762
|
-
onclick="toggleCode('
|
763
|
-
<div class="method-source-code" id="
|
763
|
+
onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
|
764
|
+
<div class="method-source-code" id="M000054-source">
|
764
765
|
<pre>
|
765
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
766
|
-
|
767
|
-
|
768
|
-
|
766
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 262</span>
|
767
|
+
262: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sql_safe_str!</span>
|
768
|
+
263: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">sql_safe_str</span>)
|
769
|
+
264: <span class="ruby-keyword kw">end</span>
|
769
770
|
</pre>
|
770
771
|
</div>
|
771
772
|
</div>
|
772
773
|
</div>
|
773
774
|
|
774
|
-
<div id="method-
|
775
|
-
<a name="
|
775
|
+
<div id="method-M000039" class="method-detail">
|
776
|
+
<a name="M000039"></a>
|
776
777
|
|
777
778
|
<div class="method-heading">
|
778
|
-
<a href="#
|
779
|
+
<a href="#M000039" class="method-signature">
|
779
780
|
<span class="method-name">starts_with?</span><span class="method-args">(x)</span>
|
780
781
|
</a>
|
781
782
|
</div>
|
782
783
|
|
783
784
|
<div class="method-description">
|
784
785
|
<p><a class="source-toggle" href="#"
|
785
|
-
onclick="toggleCode('
|
786
|
-
<div class="method-source-code" id="
|
786
|
+
onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
|
787
|
+
<div class="method-source-code" id="M000039-source">
|
787
788
|
<pre>
|
788
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
789
|
-
|
790
|
-
|
791
|
-
|
789
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 161</span>
|
790
|
+
161: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">starts_with?</span>(<span class="ruby-identifier">x</span>)
|
791
|
+
162: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/^#{x}/</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
|
792
|
+
163: <span class="ruby-keyword kw">end</span>
|
792
793
|
</pre>
|
793
794
|
</div>
|
794
795
|
</div>
|
795
796
|
</div>
|
796
797
|
|
797
|
-
<div id="method-
|
798
|
-
<a name="
|
798
|
+
<div id="method-M000030" class="method-detail">
|
799
|
+
<a name="M000030"></a>
|
799
800
|
|
800
801
|
<div class="method-heading">
|
801
|
-
<a href="#
|
802
|
+
<a href="#M000030" class="method-signature">
|
803
|
+
<span class="method-name">to_instance</span><span class="method-args">()</span>
|
804
|
+
</a>
|
805
|
+
</div>
|
806
|
+
|
807
|
+
<div class="method-description">
|
808
|
+
<p>
|
809
|
+
See <a href="Class.html">Class</a> new_instance_of for more details.
|
810
|
+
</p>
|
811
|
+
<p><a class="source-toggle" href="#"
|
812
|
+
onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
|
813
|
+
<div class="method-source-code" id="M000030-source">
|
814
|
+
<pre>
|
815
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 5</span>
|
816
|
+
5: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_instance</span>
|
817
|
+
6: <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new_instance_of</span>(<span class="ruby-keyword kw">self</span>)
|
818
|
+
7: <span class="ruby-keyword kw">end</span>
|
819
|
+
</pre>
|
820
|
+
</div>
|
821
|
+
</div>
|
822
|
+
</div>
|
823
|
+
|
824
|
+
<div id="method-M000049" class="method-detail">
|
825
|
+
<a name="M000049"></a>
|
826
|
+
|
827
|
+
<div class="method-heading">
|
828
|
+
<a href="#M000049" class="method-signature">
|
802
829
|
<span class="method-name">truncate</span><span class="method-args">(length = 30, truncate_string = "...")</span>
|
803
830
|
</a>
|
804
831
|
</div>
|
805
832
|
|
806
833
|
<div class="method-description">
|
807
834
|
<p><a class="source-toggle" href="#"
|
808
|
-
onclick="toggleCode('
|
809
|
-
<div class="method-source-code" id="
|
835
|
+
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
836
|
+
<div class="method-source-code" id="M000049-source">
|
810
837
|
<pre>
|
811
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
838
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 231</span>
|
839
|
+
231: <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>)
|
840
|
+
232: <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>
|
841
|
+
233: <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>
|
842
|
+
234: <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>
|
843
|
+
235: <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>
|
844
|
+
236: <span class="ruby-keyword kw">else</span>
|
845
|
+
237: <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>)
|
846
|
+
238: <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>
|
847
|
+
239: <span class="ruby-keyword kw">end</span>
|
848
|
+
240: <span class="ruby-keyword kw">end</span>
|
822
849
|
</pre>
|
823
850
|
</div>
|
824
851
|
</div>
|
825
852
|
</div>
|
826
853
|
|
827
|
-
<div id="method-
|
828
|
-
<a name="
|
854
|
+
<div id="method-M000050" class="method-detail">
|
855
|
+
<a name="M000050"></a>
|
829
856
|
|
830
857
|
<div class="method-heading">
|
831
|
-
<a href="#
|
858
|
+
<a href="#M000050" class="method-signature">
|
832
859
|
<span class="method-name">truncate!</span><span class="method-args">(length = 30, truncate_string = "...")</span>
|
833
860
|
</a>
|
834
861
|
</div>
|
835
862
|
|
836
863
|
<div class="method-description">
|
837
864
|
<p><a class="source-toggle" href="#"
|
838
|
-
onclick="toggleCode('
|
839
|
-
<div class="method-source-code" id="
|
865
|
+
onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
|
866
|
+
<div class="method-source-code" id="M000050-source">
|
840
867
|
<pre>
|
841
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
842
|
-
|
843
|
-
|
844
|
-
|
868
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 242</span>
|
869
|
+
242: <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>)
|
870
|
+
243: <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>))
|
871
|
+
244: <span class="ruby-keyword kw">end</span>
|
845
872
|
</pre>
|
846
873
|
</div>
|
847
874
|
</div>
|
848
875
|
</div>
|
849
876
|
|
850
|
-
<div id="method-
|
851
|
-
<a name="
|
877
|
+
<div id="method-M000038" class="method-detail">
|
878
|
+
<a name="M000038"></a>
|
852
879
|
|
853
880
|
<div class="method-heading">
|
854
|
-
<a href="#
|
881
|
+
<a href="#M000038" class="method-signature">
|
855
882
|
<span class="method-name">underscore</span><span class="method-args">()</span>
|
856
883
|
</a>
|
857
884
|
</div>
|
858
885
|
|
859
886
|
<div class="method-description">
|
860
887
|
<p><a class="source-toggle" href="#"
|
861
|
-
onclick="toggleCode('
|
862
|
-
<div class="method-source-code" id="
|
888
|
+
onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
|
889
|
+
<div class="method-source-code" id="M000038-source">
|
863
890
|
<pre>
|
864
|
-
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
891
|
+
<span class="ruby-comment cmt"># File lib/extensions/string.rb, line 152</span>
|
892
|
+
152: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">underscore</span>
|
893
|
+
153: <span class="ruby-identifier">camel_cased_word</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>
|
894
|
+
154: <span class="ruby-identifier">camel_cased_word</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/::/</span>, <span class="ruby-value str">'/'</span>).
|
895
|
+
155: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/([A-Z]+)([A-Z][a-z])/</span>,<span class="ruby-value str">'\1_\2'</span>).
|
896
|
+
156: <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/([a-z\d])([A-Z])/</span>,<span class="ruby-value str">'\1_\2'</span>).
|
897
|
+
157: <span class="ruby-identifier">tr</span>(<span class="ruby-value str">"-"</span>, <span class="ruby-value str">"_"</span>).
|
898
|
+
158: <span class="ruby-identifier">downcase</span>
|
899
|
+
159: <span class="ruby-keyword kw">end</span>
|
873
900
|
</pre>
|
874
901
|
</div>
|
875
902
|
</div>
|