mack_ruby_core_extensions 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +3 -0
- data/doc/classes/Array.html +465 -0
- data/doc/classes/Class.html +181 -0
- data/doc/classes/Dir.html +190 -0
- data/doc/classes/Float.html +148 -0
- data/doc/classes/Hash.html +232 -0
- data/doc/classes/Kernel.html +182 -0
- data/doc/classes/Mack.html +111 -0
- data/doc/classes/Mack/Utils.html +111 -0
- data/doc/classes/Mack/Utils/Inflector.html +422 -0
- data/doc/classes/Math.html +188 -0
- data/doc/classes/MethodNotImplemented.html +155 -0
- data/doc/classes/Module.html +203 -0
- data/doc/classes/NilClass.html +151 -0
- data/doc/classes/Object.html +315 -0
- data/doc/classes/String.html +890 -0
- data/doc/classes/Symbol.html +148 -0
- data/doc/created.rid +1 -0
- data/doc/files/README.html +111 -0
- data/doc/files/lib/extensions/array_rb.html +101 -0
- data/doc/files/lib/extensions/class_rb.html +101 -0
- data/doc/files/lib/extensions/dir_rb.html +101 -0
- data/doc/files/lib/extensions/float_rb.html +101 -0
- data/doc/files/lib/extensions/hash_rb.html +101 -0
- data/doc/files/lib/extensions/kernel_rb.html +109 -0
- data/doc/files/lib/extensions/logger_rb.html +101 -0
- data/doc/files/lib/extensions/math_rb.html +101 -0
- data/doc/files/lib/extensions/method_not_implemented_rb.html +108 -0
- data/doc/files/lib/extensions/module_rb.html +101 -0
- data/doc/files/lib/extensions/nil_rb.html +101 -0
- data/doc/files/lib/extensions/object_rb.html +101 -0
- data/doc/files/lib/extensions/string_rb.html +108 -0
- data/doc/files/lib/extensions/symbol_rb.html +101 -0
- data/doc/files/lib/mack_ruby_core_extensions_rb.html +101 -0
- data/doc/files/lib/utils/inflections_rb.html +101 -0
- data/doc/files/lib/utils/inflector_rb.html +108 -0
- data/doc/fr_class_index.html +42 -0
- data/doc/fr_file_index.html +44 -0
- data/doc/fr_method_index.html +92 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/extensions/array.rb +101 -0
- data/lib/extensions/class.rb +19 -0
- data/lib/extensions/dir.rb +25 -0
- data/lib/extensions/float.rb +5 -0
- data/lib/extensions/hash.rb +47 -0
- data/lib/extensions/kernel.rb +30 -0
- data/lib/extensions/logger.rb +0 -0
- data/lib/extensions/math.rb +15 -0
- data/lib/extensions/method_not_implemented.rb +12 -0
- data/lib/extensions/module.rb +29 -0
- data/lib/extensions/nil.rb +8 -0
- data/lib/extensions/object.rb +103 -0
- data/lib/extensions/string.rb +261 -0
- data/lib/extensions/symbol.rb +7 -0
- data/lib/mack_ruby_core_extensions.rb +7 -0
- data/lib/utils/inflections.rb +62 -0
- data/lib/utils/inflector.rb +129 -0
- data/test/extensions/array_test.rb +15 -0
- data/test/extensions/class_test.rb +28 -0
- data/test/extensions/dir_test.rb +15 -0
- data/test/extensions/float_test.rb +15 -0
- data/test/extensions/hash_test.rb +34 -0
- data/test/extensions/kernel_test.rb +15 -0
- data/test/extensions/logger_test.rb +15 -0
- data/test/extensions/math_test.rb +15 -0
- data/test/extensions/method_not_implemented_test.rb +15 -0
- data/test/extensions/module_test.rb +57 -0
- data/test/extensions/nil_test.rb +15 -0
- data/test/extensions/object_test.rb +15 -0
- data/test/extensions/string_test.rb +104 -0
- data/test/extensions/symbol_test.rb +15 -0
- data/test/test_helper.rb +6 -0
- data/test/utils/inflection_test.rb +32 -0
- metadata +133 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Mack::Utils</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Mack::Utils</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/utils/inflector_rb.html">
|
59
|
+
lib/utils/inflector.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
</div>
|
78
|
+
|
79
|
+
|
80
|
+
</div>
|
81
|
+
|
82
|
+
|
83
|
+
<!-- if includes -->
|
84
|
+
|
85
|
+
<div id="section">
|
86
|
+
|
87
|
+
<div id="class-list">
|
88
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
89
|
+
|
90
|
+
Class <a href="Utils/Inflector.html" class="link">Mack::Utils::Inflector</a><br />
|
91
|
+
|
92
|
+
</div>
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
<!-- if method_list -->
|
101
|
+
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
|
106
|
+
<div id="validator-badges">
|
107
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
108
|
+
</div>
|
109
|
+
|
110
|
+
</body>
|
111
|
+
</html>
|
@@ -0,0 +1,422 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Mack::Utils::Inflector</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Mack::Utils::Inflector</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../../files/lib/utils/inflector_rb.html">
|
59
|
+
lib/utils/inflector.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
<a href="../../Object.html">
|
69
|
+
Object
|
70
|
+
</a>
|
71
|
+
</td>
|
72
|
+
</tr>
|
73
|
+
</table>
|
74
|
+
</div>
|
75
|
+
<!-- banner header -->
|
76
|
+
|
77
|
+
<div id="bodyContent">
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<div id="contextContent">
|
82
|
+
|
83
|
+
<div id="description">
|
84
|
+
<p>
|
85
|
+
This class is used to deal with inflection strings. This means taken a
|
86
|
+
string and make it <a href="Inflector.html#M000055">plural</a>, or <a
|
87
|
+
href="Inflector.html#M000056">singular</a>, etc… Inflection rules can
|
88
|
+
be added very easy, and are checked from the bottom up. This means that the
|
89
|
+
last rule is the first rule to be matched. The exception to this, kind of,
|
90
|
+
is ‘<a href="Inflector.html#M000057">irregular</a>’ and
|
91
|
+
‘<a href="Inflector.html#M000058">uncountable</a>’ rules. The
|
92
|
+
‘<a href="Inflector.html#M000058">uncountable</a>’ rules are
|
93
|
+
always checked first, then the ‘<a
|
94
|
+
href="Inflector.html#M000057">irregular</a>’ rules, and finally
|
95
|
+
either the ‘<a href="Inflector.html#M000056">singular</a>’ or
|
96
|
+
‘<a href="Inflector.html#M000055">plural</a>’ rules, depending
|
97
|
+
on what you‘re trying to do. Within each of these sets of rules, the
|
98
|
+
last rule in is the first rule matched.
|
99
|
+
</p>
|
100
|
+
<p>
|
101
|
+
Example:
|
102
|
+
</p>
|
103
|
+
<pre>
|
104
|
+
Mack::Utils::Inflector.inflections do |inflect|
|
105
|
+
inflect.plural(/$/, 's')
|
106
|
+
inflect.plural(/^(ox)$/i, '\1en')
|
107
|
+
inflect.plural(/(phenomen|criteri)on$/i, '\1a')
|
108
|
+
|
109
|
+
inflect.singular(/s$/i, '')
|
110
|
+
inflect.singular(/(n)ews$/i, '\1ews')
|
111
|
+
inflect.singular(/^(.*)ookies$/, '\1ookie')
|
112
|
+
|
113
|
+
inflect.irregular('person', 'people')
|
114
|
+
inflect.irregular('child', 'children')
|
115
|
+
|
116
|
+
inflect.uncountable(%w(fish sheep deer offspring))
|
117
|
+
end
|
118
|
+
</pre>
|
119
|
+
|
120
|
+
</div>
|
121
|
+
|
122
|
+
|
123
|
+
</div>
|
124
|
+
|
125
|
+
<div id="method-list">
|
126
|
+
<h3 class="section-bar">Methods</h3>
|
127
|
+
|
128
|
+
<div class="name-list">
|
129
|
+
<a href="#M000061">inflections</a>
|
130
|
+
<a href="#M000057">irregular</a>
|
131
|
+
<a href="#M000055">plural</a>
|
132
|
+
<a href="#M000060">pluralize</a>
|
133
|
+
<a href="#M000056">singular</a>
|
134
|
+
<a href="#M000059">singularize</a>
|
135
|
+
<a href="#M000058">uncountable</a>
|
136
|
+
</div>
|
137
|
+
</div>
|
138
|
+
|
139
|
+
</div>
|
140
|
+
|
141
|
+
|
142
|
+
<!-- if includes -->
|
143
|
+
<div id="includes">
|
144
|
+
<h3 class="section-bar">Included Modules</h3>
|
145
|
+
|
146
|
+
<div id="includes-list">
|
147
|
+
<span class="include-name">Singleton</span>
|
148
|
+
</div>
|
149
|
+
</div>
|
150
|
+
|
151
|
+
<div id="section">
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
<!-- if method_list -->
|
161
|
+
<div id="methods">
|
162
|
+
<h3 class="section-bar">Public Class methods</h3>
|
163
|
+
|
164
|
+
<div id="method-M000061" class="method-detail">
|
165
|
+
<a name="M000061"></a>
|
166
|
+
|
167
|
+
<div class="method-heading">
|
168
|
+
<a href="#M000061" class="method-signature">
|
169
|
+
<span class="method-name">inflections</span><span class="method-args">() {|Mack::Utils::Inflector.instance| ...}</span>
|
170
|
+
</a>
|
171
|
+
</div>
|
172
|
+
|
173
|
+
<div class="method-description">
|
174
|
+
<p>
|
175
|
+
Yields up Mack::Utils::Inflector.instance
|
176
|
+
</p>
|
177
|
+
<p><a class="source-toggle" href="#"
|
178
|
+
onclick="toggleCode('M000061-source');return false;">[Source]</a></p>
|
179
|
+
<div class="method-source-code" id="M000061-source">
|
180
|
+
<pre>
|
181
|
+
<span class="ruby-comment cmt"># File lib/utils/inflector.rb, line 121</span>
|
182
|
+
121: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inflections</span>
|
183
|
+
122: <span class="ruby-keyword kw">yield</span> <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>
|
184
|
+
123: <span class="ruby-keyword kw">end</span>
|
185
|
+
</pre>
|
186
|
+
</div>
|
187
|
+
</div>
|
188
|
+
</div>
|
189
|
+
|
190
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
191
|
+
|
192
|
+
<div id="method-M000057" class="method-detail">
|
193
|
+
<a name="M000057"></a>
|
194
|
+
|
195
|
+
<div class="method-heading">
|
196
|
+
<a href="#M000057" class="method-signature">
|
197
|
+
<span class="method-name">irregular</span><span class="method-args">(rule, replacement)</span>
|
198
|
+
</a>
|
199
|
+
</div>
|
200
|
+
|
201
|
+
<div class="method-description">
|
202
|
+
<p>
|
203
|
+
Adds a <a href="Inflector.html#M000057">irregular</a> rule to the system.
|
204
|
+
</p>
|
205
|
+
<p>
|
206
|
+
Example:
|
207
|
+
</p>
|
208
|
+
<pre>
|
209
|
+
Mack::Utils::Inflector.inflections do |inflect|
|
210
|
+
inflect.irregular('person', 'people')
|
211
|
+
inflect.irregular('child', 'children')
|
212
|
+
end
|
213
|
+
</pre>
|
214
|
+
<p><a class="source-toggle" href="#"
|
215
|
+
onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
|
216
|
+
<div class="method-source-code" id="M000057-source">
|
217
|
+
<pre>
|
218
|
+
<span class="ruby-comment cmt"># File lib/utils/inflector.rb, line 66</span>
|
219
|
+
66: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">irregular</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>)
|
220
|
+
67: <span class="ruby-ivar">@irregular_rules</span> <span class="ruby-operator"><<</span> {<span class="ruby-identifier">:rule</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">rule</span>, <span class="ruby-identifier">:replacement</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">replacement</span>}
|
221
|
+
68: <span class="ruby-comment cmt"># do the reverse so you get:</span>
|
222
|
+
69: <span class="ruby-comment cmt"># person => people</span>
|
223
|
+
70: <span class="ruby-comment cmt"># people => person</span>
|
224
|
+
71: <span class="ruby-ivar">@irregular_rules</span> <span class="ruby-operator"><<</span> {<span class="ruby-identifier">:rule</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">replacement</span>, <span class="ruby-identifier">:replacement</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">rule</span>}
|
225
|
+
72: <span class="ruby-keyword kw">end</span>
|
226
|
+
</pre>
|
227
|
+
</div>
|
228
|
+
</div>
|
229
|
+
</div>
|
230
|
+
|
231
|
+
<div id="method-M000055" class="method-detail">
|
232
|
+
<a name="M000055"></a>
|
233
|
+
|
234
|
+
<div class="method-heading">
|
235
|
+
<a href="#M000055" class="method-signature">
|
236
|
+
<span class="method-name">plural</span><span class="method-args">(rule, replacement)</span>
|
237
|
+
</a>
|
238
|
+
</div>
|
239
|
+
|
240
|
+
<div class="method-description">
|
241
|
+
<p>
|
242
|
+
Adds a <a href="Inflector.html#M000055">plural</a> rule to the system.
|
243
|
+
</p>
|
244
|
+
<p>
|
245
|
+
Example:
|
246
|
+
</p>
|
247
|
+
<pre>
|
248
|
+
Mack::Utils::Inflector.inflections do |inflect|
|
249
|
+
inflect.plural(/$/, 's')
|
250
|
+
inflect.plural(/^(ox)$/i, '\1en')
|
251
|
+
inflect.plural(/(phenomen|criteri)on$/i, '\1a')
|
252
|
+
end
|
253
|
+
</pre>
|
254
|
+
<p><a class="source-toggle" href="#"
|
255
|
+
onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
|
256
|
+
<div class="method-source-code" id="M000055-source">
|
257
|
+
<pre>
|
258
|
+
<span class="ruby-comment cmt"># File lib/utils/inflector.rb, line 43</span>
|
259
|
+
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">plural</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>)
|
260
|
+
44: <span class="ruby-ivar">@plural_rules</span> <span class="ruby-operator"><<</span> {<span class="ruby-identifier">:rule</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">rule</span>, <span class="ruby-identifier">:replacement</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">replacement</span>}
|
261
|
+
45: <span class="ruby-keyword kw">end</span>
|
262
|
+
</pre>
|
263
|
+
</div>
|
264
|
+
</div>
|
265
|
+
</div>
|
266
|
+
|
267
|
+
<div id="method-M000060" class="method-detail">
|
268
|
+
<a name="M000060"></a>
|
269
|
+
|
270
|
+
<div class="method-heading">
|
271
|
+
<a href="#M000060" class="method-signature">
|
272
|
+
<span class="method-name">pluralize</span><span class="method-args">(word)</span>
|
273
|
+
</a>
|
274
|
+
</div>
|
275
|
+
|
276
|
+
<div class="method-description">
|
277
|
+
<p>
|
278
|
+
Returns the <a href="Inflector.html#M000056">singular</a> version of the
|
279
|
+
word, if possible.
|
280
|
+
</p>
|
281
|
+
<p>
|
282
|
+
Examples:
|
283
|
+
</p>
|
284
|
+
<pre>
|
285
|
+
Mack::Utils::Inflector.instance.pluralize("army") # => "armies"
|
286
|
+
Mack::Utils::Inflector.instance.pluralize("person") # => "people"
|
287
|
+
Mack::Utils::Inflector.instance.pluralize("boat") # => "boats"
|
288
|
+
</pre>
|
289
|
+
<p><a class="source-toggle" href="#"
|
290
|
+
onclick="toggleCode('M000060-source');return false;">[Source]</a></p>
|
291
|
+
<div class="method-source-code" id="M000060-source">
|
292
|
+
<pre>
|
293
|
+
<span class="ruby-comment cmt"># File lib/utils/inflector.rb, line 102</span>
|
294
|
+
102: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pluralize</span>(<span class="ruby-identifier">word</span>)
|
295
|
+
103: <span class="ruby-identifier">do_work</span>(<span class="ruby-identifier">word</span>, <span class="ruby-ivar">@plural_rules</span>)
|
296
|
+
104: <span class="ruby-keyword kw">end</span>
|
297
|
+
</pre>
|
298
|
+
</div>
|
299
|
+
</div>
|
300
|
+
</div>
|
301
|
+
|
302
|
+
<div id="method-M000056" class="method-detail">
|
303
|
+
<a name="M000056"></a>
|
304
|
+
|
305
|
+
<div class="method-heading">
|
306
|
+
<a href="#M000056" class="method-signature">
|
307
|
+
<span class="method-name">singular</span><span class="method-args">(rule, replacement)</span>
|
308
|
+
</a>
|
309
|
+
</div>
|
310
|
+
|
311
|
+
<div class="method-description">
|
312
|
+
<p>
|
313
|
+
Adds a <a href="Inflector.html#M000056">singular</a> rule to the system.
|
314
|
+
</p>
|
315
|
+
<p>
|
316
|
+
Example:
|
317
|
+
</p>
|
318
|
+
<pre>
|
319
|
+
Mack::Utils::Inflector.inflections do |inflect|
|
320
|
+
inflect.singular(/s$/i, '')
|
321
|
+
inflect.singular(/(n)ews$/i, '\1ews')
|
322
|
+
inflect.singular(/^(.*)ookies$/, '\1ookie')
|
323
|
+
end
|
324
|
+
</pre>
|
325
|
+
<p><a class="source-toggle" href="#"
|
326
|
+
onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
|
327
|
+
<div class="method-source-code" id="M000056-source">
|
328
|
+
<pre>
|
329
|
+
<span class="ruby-comment cmt"># File lib/utils/inflector.rb, line 55</span>
|
330
|
+
55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">singular</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>)
|
331
|
+
56: <span class="ruby-ivar">@singular_rules</span> <span class="ruby-operator"><<</span> {<span class="ruby-identifier">:rule</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">rule</span>, <span class="ruby-identifier">:replacement</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">replacement</span>}
|
332
|
+
57: <span class="ruby-keyword kw">end</span>
|
333
|
+
</pre>
|
334
|
+
</div>
|
335
|
+
</div>
|
336
|
+
</div>
|
337
|
+
|
338
|
+
<div id="method-M000059" class="method-detail">
|
339
|
+
<a name="M000059"></a>
|
340
|
+
|
341
|
+
<div class="method-heading">
|
342
|
+
<a href="#M000059" class="method-signature">
|
343
|
+
<span class="method-name">singularize</span><span class="method-args">(word)</span>
|
344
|
+
</a>
|
345
|
+
</div>
|
346
|
+
|
347
|
+
<div class="method-description">
|
348
|
+
<p>
|
349
|
+
Returns the <a href="Inflector.html#M000056">singular</a> version of the
|
350
|
+
word, if possible.
|
351
|
+
</p>
|
352
|
+
<p>
|
353
|
+
Examples:
|
354
|
+
</p>
|
355
|
+
<pre>
|
356
|
+
Mack::Utils::Inflector.instance.singularize("armies") # => "army"
|
357
|
+
Mack::Utils::Inflector.instance.singularize("people") # => "person"
|
358
|
+
Mack::Utils::Inflector.instance.singularize("boats") # => "boat"
|
359
|
+
</pre>
|
360
|
+
<p><a class="source-toggle" href="#"
|
361
|
+
onclick="toggleCode('M000059-source');return false;">[Source]</a></p>
|
362
|
+
<div class="method-source-code" id="M000059-source">
|
363
|
+
<pre>
|
364
|
+
<span class="ruby-comment cmt"># File lib/utils/inflector.rb, line 92</span>
|
365
|
+
92: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">singularize</span>(<span class="ruby-identifier">word</span>)
|
366
|
+
93: <span class="ruby-identifier">do_work</span>(<span class="ruby-identifier">word</span>, <span class="ruby-ivar">@singular_rules</span>)
|
367
|
+
94: <span class="ruby-keyword kw">end</span>
|
368
|
+
</pre>
|
369
|
+
</div>
|
370
|
+
</div>
|
371
|
+
</div>
|
372
|
+
|
373
|
+
<div id="method-M000058" class="method-detail">
|
374
|
+
<a name="M000058"></a>
|
375
|
+
|
376
|
+
<div class="method-heading">
|
377
|
+
<a href="#M000058" class="method-signature">
|
378
|
+
<span class="method-name">uncountable</span><span class="method-args">(*args)</span>
|
379
|
+
</a>
|
380
|
+
</div>
|
381
|
+
|
382
|
+
<div class="method-description">
|
383
|
+
<p>
|
384
|
+
Adds a <a href="Inflector.html#M000058">uncountable</a> word, or words, to
|
385
|
+
the system.
|
386
|
+
</p>
|
387
|
+
<p>
|
388
|
+
Example:
|
389
|
+
</p>
|
390
|
+
<pre>
|
391
|
+
Mack::Utils::Inflector.inflections do |inflect|
|
392
|
+
inflect.uncountable(%w(fish sheep deer offspring))
|
393
|
+
end
|
394
|
+
</pre>
|
395
|
+
<p><a class="source-toggle" href="#"
|
396
|
+
onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
|
397
|
+
<div class="method-source-code" id="M000058-source">
|
398
|
+
<pre>
|
399
|
+
<span class="ruby-comment cmt"># File lib/utils/inflector.rb, line 80</span>
|
400
|
+
80: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uncountable</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
401
|
+
81: [<span class="ruby-identifier">args</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">word</span><span class="ruby-operator">|</span>
|
402
|
+
82: <span class="ruby-ivar">@uncountable_rules</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">word</span>.<span class="ruby-identifier">downcase</span>
|
403
|
+
83: <span class="ruby-keyword kw">end</span>
|
404
|
+
84: <span class="ruby-keyword kw">end</span>
|
405
|
+
</pre>
|
406
|
+
</div>
|
407
|
+
</div>
|
408
|
+
</div>
|
409
|
+
|
410
|
+
|
411
|
+
</div>
|
412
|
+
|
413
|
+
|
414
|
+
</div>
|
415
|
+
|
416
|
+
|
417
|
+
<div id="validator-badges">
|
418
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
419
|
+
</div>
|
420
|
+
|
421
|
+
</body>
|
422
|
+
</html>
|