hash_magic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +78 -0
- data/doc/classes/Hash.html +177 -0
- data/doc/classes/Hash.src/M000012.html +18 -0
- data/doc/classes/Hash.src/M000013.html +18 -0
- data/doc/classes/OrderedHash.html +208 -0
- data/doc/classes/OrderedHash.src/M000014.html +18 -0
- data/doc/classes/OrderedHash.src/M000015.html +19 -0
- data/doc/classes/OrderedHash.src/M000016.html +18 -0
- data/doc/classes/OrderedHash.src/M000017.html +18 -0
- data/doc/classes/OrderedHash.src/M000018.html +18 -0
- data/doc/classes/SlashedHash.html +373 -0
- data/doc/classes/SlashedHash.src/M000001.html +20 -0
- data/doc/classes/SlashedHash.src/M000002.html +25 -0
- data/doc/classes/SlashedHash.src/M000003.html +25 -0
- data/doc/classes/SlashedHash.src/M000004.html +21 -0
- data/doc/classes/SlashedHash.src/M000005.html +18 -0
- data/doc/classes/SlashedHash.src/M000006.html +18 -0
- data/doc/classes/SlashedHash.src/M000007.html +18 -0
- data/doc/classes/SlashedHash.src/M000008.html +18 -0
- data/doc/classes/SlashedHash.src/M000009.html +18 -0
- data/doc/classes/SlashedHash.src/M000010.html +18 -0
- data/doc/classes/SlashedHash.src/M000011.html +21 -0
- data/doc/created.rid +1 -0
- data/doc/files/lib/hash_magic_rb.html +126 -0
- data/doc/fr_class_index.html +29 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +44 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/hash_magic.rb +359 -0
- metadata +88 -0
@@ -0,0 +1,373 @@
|
|
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: SlashedHash</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">SlashedHash</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/hash_magic_rb.html">
|
59
|
+
lib/hash_magic.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="Hash.html">
|
69
|
+
Hash
|
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
|
+
A <a href="SlashedHash.html">SlashedHash</a> is a hash whose values can be
|
86
|
+
accessed in the normal manner, or with <a
|
87
|
+
href="SlashedHash.html#M000006">keys</a> that are
|
88
|
+
slash(’/’)-separated strings. To get the whole hash as a single
|
89
|
+
flattened level, call <a
|
90
|
+
href="SlashedHash.html#M000007">SlashedHash#flat</a>. All <a
|
91
|
+
href="SlashedHash.html#M000006">keys</a> are converted to strings. All
|
92
|
+
end-of-the-chain values are kept in whatever value they are.
|
93
|
+
</p>
|
94
|
+
<pre>
|
95
|
+
s = {'a' => 'b', 'c' => {'d' => :e}}.slashed
|
96
|
+
s['a'] #=> 'b'
|
97
|
+
s['c'] #=> {slashed: 'd'=>:e}
|
98
|
+
s['c']['d'] #=> :e
|
99
|
+
s['c/d'] #=> :e
|
100
|
+
</pre>
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
<div id="method-list">
|
108
|
+
<h3 class="section-bar">Methods</h3>
|
109
|
+
|
110
|
+
<div class="name-list">
|
111
|
+
<a href="#M000002">[]</a>
|
112
|
+
<a href="#M000003">[]=</a>
|
113
|
+
<a href="#M000004">delete</a>
|
114
|
+
<a href="#M000008">expand</a>
|
115
|
+
<a href="#M000007">flat</a>
|
116
|
+
<a href="#M000005">index</a>
|
117
|
+
<a href="#M000006">keys</a>
|
118
|
+
<a href="#M000001">new</a>
|
119
|
+
<a href="#M000010">ordered</a>
|
120
|
+
<a href="#M000011">ordered!</a>
|
121
|
+
<a href="#M000009">to_string_array</a>
|
122
|
+
</div>
|
123
|
+
</div>
|
124
|
+
|
125
|
+
</div>
|
126
|
+
|
127
|
+
|
128
|
+
<!-- if includes -->
|
129
|
+
<div id="includes">
|
130
|
+
<h3 class="section-bar">Included Modules</h3>
|
131
|
+
|
132
|
+
<div id="includes-list">
|
133
|
+
<span class="include-name">StandardHashMethodsInRuby</span>
|
134
|
+
</div>
|
135
|
+
</div>
|
136
|
+
|
137
|
+
<div id="section">
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
<!-- if method_list -->
|
147
|
+
<div id="methods">
|
148
|
+
<h3 class="section-bar">Public Class methods</h3>
|
149
|
+
|
150
|
+
<div id="method-M000001" class="method-detail">
|
151
|
+
<a name="M000001"></a>
|
152
|
+
|
153
|
+
<div class="method-heading">
|
154
|
+
<a href="SlashedHash.src/M000001.html" target="Code" class="method-signature"
|
155
|
+
onclick="popupCode('SlashedHash.src/M000001.html');return false;">
|
156
|
+
<span class="method-name">new</span><span class="method-args">(hsh={})</span>
|
157
|
+
</a>
|
158
|
+
</div>
|
159
|
+
|
160
|
+
<div class="method-description">
|
161
|
+
</div>
|
162
|
+
</div>
|
163
|
+
|
164
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
165
|
+
|
166
|
+
<div id="method-M000002" class="method-detail">
|
167
|
+
<a name="M000002"></a>
|
168
|
+
|
169
|
+
<div class="method-heading">
|
170
|
+
<a href="SlashedHash.src/M000002.html" target="Code" class="method-signature"
|
171
|
+
onclick="popupCode('SlashedHash.src/M000002.html');return false;">
|
172
|
+
<span class="method-name">[]</span><span class="method-args">(key)</span>
|
173
|
+
</a>
|
174
|
+
</div>
|
175
|
+
|
176
|
+
<div class="method-description">
|
177
|
+
<p>
|
178
|
+
Behaves like the usual <a href="Hash.html">Hash</a>#[] method, but you can
|
179
|
+
access nested hash values by composing a single key of the traversing <a
|
180
|
+
href="SlashedHash.html#M000006">keys</a> joined by ’/’:
|
181
|
+
</p>
|
182
|
+
<pre>
|
183
|
+
hash['c']['d'] # is the same as:
|
184
|
+
hash['c/d']
|
185
|
+
</pre>
|
186
|
+
</div>
|
187
|
+
</div>
|
188
|
+
|
189
|
+
<div id="method-M000003" class="method-detail">
|
190
|
+
<a name="M000003"></a>
|
191
|
+
|
192
|
+
<div class="method-heading">
|
193
|
+
<a href="SlashedHash.src/M000003.html" target="Code" class="method-signature"
|
194
|
+
onclick="popupCode('SlashedHash.src/M000003.html');return false;">
|
195
|
+
<span class="method-name">[]=</span><span class="method-args">(key,value)</span>
|
196
|
+
</a>
|
197
|
+
</div>
|
198
|
+
|
199
|
+
<div class="method-description">
|
200
|
+
<p>
|
201
|
+
Same as above, except sets value rather than retrieving it.
|
202
|
+
</p>
|
203
|
+
</div>
|
204
|
+
</div>
|
205
|
+
|
206
|
+
<div id="method-M000004" class="method-detail">
|
207
|
+
<a name="M000004"></a>
|
208
|
+
|
209
|
+
<div class="method-heading">
|
210
|
+
<a href="SlashedHash.src/M000004.html" target="Code" class="method-signature"
|
211
|
+
onclick="popupCode('SlashedHash.src/M000004.html');return false;">
|
212
|
+
<span class="method-name">delete</span><span class="method-args">(key,&block)</span>
|
213
|
+
</a>
|
214
|
+
</div>
|
215
|
+
|
216
|
+
<div class="method-description">
|
217
|
+
<p>
|
218
|
+
You can use slashed <a href="SlashedHash.html#M000006">keys</a> here, too.
|
219
|
+
</p>
|
220
|
+
</div>
|
221
|
+
</div>
|
222
|
+
|
223
|
+
<div id="method-M000008" class="method-detail">
|
224
|
+
<a name="M000008"></a>
|
225
|
+
|
226
|
+
<div class="method-heading">
|
227
|
+
<a href="SlashedHash.src/M000008.html" target="Code" class="method-signature"
|
228
|
+
onclick="popupCode('SlashedHash.src/M000008.html');return false;">
|
229
|
+
<span class="method-name">expand</span><span class="method-args">()</span>
|
230
|
+
</a>
|
231
|
+
</div>
|
232
|
+
|
233
|
+
<div class="method-description">
|
234
|
+
<p>
|
235
|
+
Expands the whole hash to <a href="Hash.html">Hash</a> objects … not
|
236
|
+
useful very often, it seems.
|
237
|
+
</p>
|
238
|
+
</div>
|
239
|
+
</div>
|
240
|
+
|
241
|
+
<div id="method-M000007" class="method-detail">
|
242
|
+
<a name="M000007"></a>
|
243
|
+
|
244
|
+
<div class="method-heading">
|
245
|
+
<a href="SlashedHash.src/M000007.html" target="Code" class="method-signature"
|
246
|
+
onclick="popupCode('SlashedHash.src/M000007.html');return false;">
|
247
|
+
<span class="method-name">flat</span><span class="method-args">()</span>
|
248
|
+
</a>
|
249
|
+
</div>
|
250
|
+
|
251
|
+
<div class="method-description">
|
252
|
+
<p>
|
253
|
+
Gives a list of all <a href="SlashedHash.html#M000006">keys</a> in all
|
254
|
+
levels in the multi-level hash, joined by slashes.
|
255
|
+
</p>
|
256
|
+
<pre>
|
257
|
+
{'a'=>{'b'=>'c', 'c'=>'d'}, 'b'=>'c'}.slashed.flat.keys
|
258
|
+
=> ['a/b', 'a/c', 'b']
|
259
|
+
</pre>
|
260
|
+
</div>
|
261
|
+
</div>
|
262
|
+
|
263
|
+
<div id="method-M000005" class="method-detail">
|
264
|
+
<a name="M000005"></a>
|
265
|
+
|
266
|
+
<div class="method-heading">
|
267
|
+
<a href="SlashedHash.src/M000005.html" target="Code" class="method-signature"
|
268
|
+
onclick="popupCode('SlashedHash.src/M000005.html');return false;">
|
269
|
+
<span class="method-name">index</span><span class="method-args">(value)</span>
|
270
|
+
</a>
|
271
|
+
</div>
|
272
|
+
|
273
|
+
<div class="method-description">
|
274
|
+
<p>
|
275
|
+
This gives you the slashed key of the value, no matter where the value is
|
276
|
+
in the tree.
|
277
|
+
</p>
|
278
|
+
</div>
|
279
|
+
</div>
|
280
|
+
|
281
|
+
<div id="method-M000006" class="method-detail">
|
282
|
+
<a name="M000006"></a>
|
283
|
+
|
284
|
+
<div class="method-heading">
|
285
|
+
<a href="SlashedHash.src/M000006.html" target="Code" class="method-signature"
|
286
|
+
onclick="popupCode('SlashedHash.src/M000006.html');return false;">
|
287
|
+
<span class="method-name">keys</span><span class="method-args">()</span>
|
288
|
+
</a>
|
289
|
+
</div>
|
290
|
+
|
291
|
+
<div class="method-description">
|
292
|
+
<p>
|
293
|
+
This gives you only the top-level <a
|
294
|
+
href="SlashedHash.html#M000006">keys</a>, no slashes. To get the list of
|
295
|
+
slashed <a href="SlashedHash.html#M000006">keys</a>, do hash.flat.<a
|
296
|
+
href="SlashedHash.html#M000006">keys</a>
|
297
|
+
</p>
|
298
|
+
</div>
|
299
|
+
</div>
|
300
|
+
|
301
|
+
<div id="method-M000010" class="method-detail">
|
302
|
+
<a name="M000010"></a>
|
303
|
+
|
304
|
+
<div class="method-heading">
|
305
|
+
<a href="SlashedHash.src/M000010.html" target="Code" class="method-signature"
|
306
|
+
onclick="popupCode('SlashedHash.src/M000010.html');return false;">
|
307
|
+
<span class="method-name">ordered</span><span class="method-args">(*keys_in_order)</span>
|
308
|
+
</a>
|
309
|
+
</div>
|
310
|
+
|
311
|
+
<div class="method-description">
|
312
|
+
<p>
|
313
|
+
Same as <a href="SlashedHash.html#M000011">ordered!</a> but returns a <a
|
314
|
+
href="SlashedHash.html#M000001">new</a> <a
|
315
|
+
href="SlashedHash.html">SlashedHash</a> object instead of modifying the
|
316
|
+
same.
|
317
|
+
</p>
|
318
|
+
</div>
|
319
|
+
</div>
|
320
|
+
|
321
|
+
<div id="method-M000011" class="method-detail">
|
322
|
+
<a name="M000011"></a>
|
323
|
+
|
324
|
+
<div class="method-heading">
|
325
|
+
<a href="SlashedHash.src/M000011.html" target="Code" class="method-signature"
|
326
|
+
onclick="popupCode('SlashedHash.src/M000011.html');return false;">
|
327
|
+
<span class="method-name">ordered!</span><span class="method-args">(*keys_in_order)</span>
|
328
|
+
</a>
|
329
|
+
</div>
|
330
|
+
|
331
|
+
<div class="method-description">
|
332
|
+
<p>
|
333
|
+
Sets the SlashedArray as <a href="SlashedHash.html#M000010">ordered</a>.
|
334
|
+
The *keys_in_order must be a <a href="SlashedHash.html#M000007">flat</a>
|
335
|
+
array of slashed <a href="SlashedHash.html#M000006">keys</a> that specify
|
336
|
+
the order for each level:
|
337
|
+
</p>
|
338
|
+
<pre>
|
339
|
+
s = {'a'=>{'b'=>'c', 'c'=>'d'}, 'b'=>'c'}.slashed
|
340
|
+
s.ordered!('b', 'a/c', 'a/b')
|
341
|
+
s.expand # => {'b'=>'c', 'a'=>{'c'=>'d', 'b'=>'c'}}
|
342
|
+
# Note that the expanded hashes will *still* be ordered!
|
343
|
+
</pre>
|
344
|
+
</div>
|
345
|
+
</div>
|
346
|
+
|
347
|
+
<div id="method-M000009" class="method-detail">
|
348
|
+
<a name="M000009"></a>
|
349
|
+
|
350
|
+
<div class="method-heading">
|
351
|
+
<a href="SlashedHash.src/M000009.html" target="Code" class="method-signature"
|
352
|
+
onclick="popupCode('SlashedHash.src/M000009.html');return false;">
|
353
|
+
<span class="method-name">to_string_array</span><span class="method-args">()</span>
|
354
|
+
</a>
|
355
|
+
</div>
|
356
|
+
|
357
|
+
<div class="method-description">
|
358
|
+
</div>
|
359
|
+
</div>
|
360
|
+
|
361
|
+
|
362
|
+
</div>
|
363
|
+
|
364
|
+
|
365
|
+
</div>
|
366
|
+
|
367
|
+
|
368
|
+
<div id="validator-badges">
|
369
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
370
|
+
</div>
|
371
|
+
|
372
|
+
</body>
|
373
|
+
</html>
|
@@ -0,0 +1,20 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>new (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 171</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">hsh</span>={})
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"must be a hash or array of slashed values"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">hsh</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">hsh</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
|
16
|
+
<span class="ruby-ivar">@constructor</span> = <span class="ruby-identifier">hsh</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">hsh</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">:</span> <span class="ruby-constant">Hash</span>
|
17
|
+
<span class="ruby-ivar">@flat</span> = <span class="ruby-identifier">flatten_to_hash</span>(<span class="ruby-identifier">hsh</span>)
|
18
|
+
<span class="ruby-keyword kw">end</span></pre>
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>[] (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 182</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">key</span>)
|
15
|
+
<span class="ruby-identifier">rg</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"^#{key}/?"</span>)
|
16
|
+
<span class="ruby-identifier">start_obj</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@constructor</span> <span class="ruby-operator">==</span> <span class="ruby-constant">OrderedHash</span>
|
17
|
+
<span class="ruby-ivar">@constructor</span>.<span class="ruby-identifier">new</span>((<span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">:@keys_in_order</span>) <span class="ruby-operator">||</span> []).<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-identifier">rg</span>,<span class="ruby-value str">''</span>)})
|
18
|
+
<span class="ruby-keyword kw">else</span>
|
19
|
+
<span class="ruby-ivar">@constructor</span>.<span class="ruby-identifier">new</span>
|
20
|
+
<span class="ruby-keyword kw">end</span>
|
21
|
+
<span class="ruby-identifier">v</span> = <span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">key</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@flat</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">reject</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">rg</span>)}.<span class="ruby-identifier">inject</span>(<span class="ruby-identifier">start_obj</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,(<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-identifier">rg</span>,<span class="ruby-value str">''</span>)] = <span class="ruby-identifier">v</span>; <span class="ruby-identifier">h</span>})
|
22
|
+
<span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">v</span>
|
23
|
+
<span class="ruby-keyword kw">end</span></pre>
|
24
|
+
</body>
|
25
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>[]= (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 193</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">key</span>,<span class="ruby-identifier">value</span>)
|
15
|
+
<span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">reject!</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"^#{key}/"</span>)}
|
16
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
17
|
+
<span class="ruby-identifier">flatten_to_hash</span>(<span class="ruby-identifier">value</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hk</span>,<span class="ruby-identifier">hv</span><span class="ruby-operator">|</span>
|
18
|
+
<span class="ruby-ivar">@flat</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">'/'</span><span class="ruby-operator">+</span><span class="ruby-identifier">hk</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">hv</span>
|
19
|
+
<span class="ruby-keyword kw">end</span>
|
20
|
+
<span class="ruby-keyword kw">else</span>
|
21
|
+
<span class="ruby-ivar">@flat</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">value</span>
|
22
|
+
<span class="ruby-keyword kw">end</span>
|
23
|
+
<span class="ruby-keyword kw">end</span></pre>
|
24
|
+
</body>
|
25
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>delete (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 224</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>,<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
15
|
+
<span class="ruby-identifier">value</span> = <span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">key</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@flat</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">reject</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"^#{key}/"</span>))}.<span class="ruby-identifier">inject</span>({}) {<span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,(<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'/'</span>,<span class="ruby-value">2</span>)[<span class="ruby-value">1</span>]] = <span class="ruby-identifier">v</span>; <span class="ruby-identifier">h</span>})
|
16
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">key</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">block_given?</span>
|
17
|
+
<span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">reject</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">k</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">k</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"^#{key}/"</span>))}.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">k</span>)}
|
18
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">value</span>
|
19
|
+
<span class="ruby-keyword kw">end</span></pre>
|
20
|
+
</body>
|
21
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>index (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 234</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">index</span>(<span class="ruby-identifier">value</span>)
|
15
|
+
<span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">value</span>)
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>keys (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 241</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">keys</span>
|
15
|
+
<span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">inject</span>([]) {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>,(<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">k</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'/'</span>,<span class="ruby-value">2</span>)].<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]; <span class="ruby-identifier">a</span>}.<span class="ruby-identifier">uniq</span>
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>flat (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 253</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">flat</span>
|
15
|
+
<span class="ruby-ivar">@flat</span>
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>expand (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 257</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expand</span>
|
15
|
+
<span class="ruby-identifier">inject</span>({}) {<span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,(<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">SlashedHash</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">expand</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">v</span>; <span class="ruby-identifier">h</span>}
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>to_string_array (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 260</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_string_array</span>
|
15
|
+
<span class="ruby-identifier">flatten_to_array</span>(<span class="ruby-identifier">flat</span>,[])
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>ordered (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 267</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ordered</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">keys_in_order</span>)
|
15
|
+
<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">ordered!</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">keys_in_order</span>)
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
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>
|
7
|
+
<head>
|
8
|
+
<title>ordered! (SlashedHash)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/hash_magic.rb, line 275</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ordered!</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">keys_in_order</span>)
|
15
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@constructor</span> <span class="ruby-operator">==</span> <span class="ruby-constant">OrderedHash</span>
|
16
|
+
<span class="ruby-ivar">@constructor</span> = <span class="ruby-constant">OrderedHash</span>
|
17
|
+
<span class="ruby-ivar">@flat</span> = <span class="ruby-ivar">@flat</span>.<span class="ruby-identifier">ordered</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">keys_in_order</span>)
|
18
|
+
<span class="ruby-keyword kw">self</span>
|
19
|
+
<span class="ruby-keyword kw">end</span></pre>
|
20
|
+
</body>
|
21
|
+
</html>
|
data/doc/created.rid
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Mon, 31 Mar 2008 16:48:09 -0400
|