cartesian 0.6.5 → 0.6.6

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.
@@ -1,3 +1,9 @@
1
+ === 0.6.6 2012-04-15
2
+
3
+ * 2 minor documentation fixes:
4
+ * updated Manifest.txt
5
+ * fixed issue #2 typo in README.rdoc
6
+
1
7
  === 0.6.5 2012-04-13
2
8
 
3
9
  * 1 bug fix:
@@ -13,6 +13,7 @@ lib/cartesian/grid_search.rb
13
13
  lib/cartesian/version.rb
14
14
  lib/cartesian_iterator.rb
15
15
  lib/grid_search.rb
16
+ lib/iterable.rb
16
17
  script/console
17
18
  script/destroy
18
19
  script/generate
@@ -24,6 +25,7 @@ test/test_cartesian_iterator.rb
24
25
  test/test_extensions.rb
25
26
  test/test_grid_search.rb
26
27
  test/test_helper.rb
28
+ test/test_iterable.rb
27
29
  test/test_suite.rb
28
30
  website/doc/Array.html
29
31
  website/doc/Cartesian.html
@@ -49,7 +49,7 @@ The '**' operator provides a convenient way of iterating multi-dimensionally ove
49
49
  Finally, the grid search methods
50
50
  require 'cartesian/grid_search'
51
51
  [-1, 0, 1, 2].argmax {|x| x**2 } #=> 2
52
- 0.argmin {|x| x.abs } #=> 0
52
+ [-1, 0, 1, 2].argmin {|x| x.abs } #=> 0
53
53
 
54
54
  == REQUIREMENTS:
55
55
 
@@ -63,7 +63,7 @@ Finally, the grid search methods
63
63
 
64
64
  (The MIT License)
65
65
 
66
- Copyright (c) 2006-2011 Adriano Mitre <adriano.mitre@gmail.com>
66
+ Copyright (c) 2006-2012 Adriano Mitre <adriano.mitre@gmail.com>
67
67
 
68
68
  Permission is hereby granted, free of charge, to any person obtaining
69
69
  a copy of this software and associated documentation files (the
@@ -39,7 +39,7 @@ module Cartesian
39
39
  # Unfortunately, as of now, the version data must be replicated in ../cartesian.rb,
40
40
  # due to a mix of newgem versions, each requiring a different one. Not DRY :P
41
41
  #
42
- VERSION = "0.6.5"
42
+ VERSION = "0.6.6"
43
43
 
44
44
  # Produces the cartesian product of self and other.
45
45
  # The result is an array of pairs (i.e. two-element arrays).
@@ -0,0 +1,25 @@
1
+ module Iterable
2
+ def restart
3
+ @next_index = -1
4
+ self
5
+ end
6
+
7
+ def next
8
+ restart unless defined? @next_index
9
+ raw_next
10
+ end
11
+
12
+ def raw_next
13
+ raise RangeError, 'there is no next element, please restart' if done?
14
+ self[@next_index += 1]
15
+ end
16
+
17
+ def restart_and_raw_next
18
+ self[@next_index = 0]
19
+ end
20
+
21
+ # TODO: consider a module inclusion time solution to "count rescue size", for performance sake
22
+ def done?
23
+ @next_index && (@next_index == (count rescue size)-1)
24
+ end
25
+ end
@@ -201,13 +201,13 @@
201
201
  <div class="method-source-code"
202
202
  id="new-source">
203
203
  <pre>
204
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 3</span>
205
- 3: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">foo</span>, <span class="ruby-identifier">bar</span>)
206
- 4: <span class="ruby-ivar">@lists</span> = []
207
- 5: <span class="ruby-ivar">@tot_iter</span> = <span class="ruby-value">1</span>
208
- 6: <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">foo</span>)
209
- 7: <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">bar</span>)
210
- 8: <span class="ruby-keyword kw">end</span></pre>
204
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 9</span>
205
+ 9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">foo</span>, <span class="ruby-identifier">bar</span>)
206
+ 10: <span class="ruby-ivar">@lists</span> = []
207
+ 11: <span class="ruby-ivar">@tot_iter</span> = <span class="ruby-value">1</span>
208
+ 12: <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">foo</span>)
209
+ 13: <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">bar</span>)
210
+ 14: <span class="ruby-keyword kw">end</span></pre>
211
211
  </div>
212
212
 
213
213
  </div>
@@ -273,10 +273,10 @@
273
273
  <div class="method-source-code"
274
274
  id="dup-source">
275
275
  <pre>
276
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 10</span>
277
- 10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dup</span>
278
- 11: <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-keyword kw">self</span>))
279
- 12: <span class="ruby-keyword kw">end</span></pre>
276
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 16</span>
277
+ 16: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dup</span>
278
+ 17: <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-keyword kw">self</span>))
279
+ 18: <span class="ruby-keyword kw">end</span></pre>
280
280
  </div>
281
281
 
282
282
  </div>
@@ -307,31 +307,32 @@
307
307
  <div class="method-source-code"
308
308
  id="each-source">
309
309
  <pre>
310
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 48</span>
311
- 48: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
312
- 49: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">1</span>
313
- 50:
314
- 51: <span class="ruby-identifier">elems</span> = []
315
- 52: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">list</span> <span class="ruby-keyword kw">in</span> <span class="ruby-ivar">@lists</span>
316
- 53: <span class="ruby-identifier">elems</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">list</span>.<span class="ruby-identifier">restart_and_raw_next</span>
317
- 54: <span class="ruby-keyword kw">end</span>
318
- 55: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value str">'1.9.1'</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> }); <span class="ruby-keyword kw">else</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>); <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># Yeah, v.map{|x|x} should be equal to v, but strangely it is NOT in Ruby versions prior to 1.9.2.</span>
310
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 54</span>
311
+ 54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
312
+ 55: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">1</span>
319
313
  56:
320
- 57: <span class="ruby-identifier">last_list_index</span> = <span class="ruby-ivar">@lists</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
321
- 58: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">last_list_index</span>
322
- 59: <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
323
- 60: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">elems</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">raw_next</span>
324
- 61: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value str">'1.9.1'</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> }); <span class="ruby-keyword kw">else</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>); <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># See previous comment.</span>
325
- 62: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">last_list_index</span>
326
- 63: <span class="ruby-keyword kw">next</span>
327
- 64: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
328
- 65: <span class="ruby-identifier">elems</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">restart_and_raw_next</span>
329
- 66: <span class="ruby-identifier">n</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
330
- 67: <span class="ruby-keyword kw">else</span>
331
- 68: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
332
- 69: <span class="ruby-keyword kw">end</span>
333
- 70: <span class="ruby-keyword kw">end</span>
334
- 71: <span class="ruby-keyword kw">end</span></pre>
314
+ 57: <span class="ruby-identifier">elems</span> = []
315
+ 58: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">list</span> <span class="ruby-keyword kw">in</span> <span class="ruby-ivar">@lists</span>
316
+ 59: <span class="ruby-identifier">elems</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">list</span>.<span class="ruby-identifier">restart_and_raw_next</span>
317
+ 60: <span class="ruby-keyword kw">end</span>
318
+ 61: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value str">'1.9.1'</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> }); <span class="ruby-keyword kw">else</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>); <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># Yeah, v.map{|x|x} should be equal to v, but strangely it is NOT in Ruby versions prior to 1.9.2.</span>
319
+ 62:
320
+ 63: <span class="ruby-identifier">last_list_index</span> = <span class="ruby-ivar">@lists</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
321
+ 64: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">last_list_index</span>
322
+ 65: <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
323
+ 66: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">done?</span>
324
+ 67: <span class="ruby-identifier">elems</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">raw_next</span>
325
+ 68: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value str">'1.9.1'</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> }); <span class="ruby-keyword kw">else</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>); <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># See previous comment.</span>
326
+ 69: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">last_list_index</span>
327
+ 70: <span class="ruby-keyword kw">next</span>
328
+ 71: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
329
+ 72: <span class="ruby-identifier">elems</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">restart_and_raw_next</span>
330
+ 73: <span class="ruby-identifier">n</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
331
+ 74: <span class="ruby-keyword kw">else</span>
332
+ 75: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
333
+ 76: <span class="ruby-keyword kw">end</span>
334
+ 77: <span class="ruby-keyword kw">end</span>
335
+ 78: <span class="ruby-keyword kw">end</span></pre>
335
336
  </div>
336
337
 
337
338
  </div>
@@ -362,13 +363,13 @@
362
363
  <div class="method-source-code"
363
364
  id="equal-source">
364
365
  <pre>
365
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 14</span>
366
- 14: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">equal</span>(<span class="ruby-identifier">other</span>)
367
- 15: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variables</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">var_name</span><span class="ruby-operator">|</span>
368
- 16: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">var_name</span>) <span class="ruby-operator">!=</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">var_name</span>)
369
- 17: <span class="ruby-keyword kw">end</span>
370
- 18: <span class="ruby-keyword kw">true</span>
371
- 19: <span class="ruby-keyword kw">end</span></pre>
366
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 20</span>
367
+ 20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">equal</span>(<span class="ruby-identifier">other</span>)
368
+ 21: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variables</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">var_name</span><span class="ruby-operator">|</span>
369
+ 22: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">var_name</span>) <span class="ruby-operator">!=</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">var_name</span>)
370
+ 23: <span class="ruby-keyword kw">end</span>
371
+ 24: <span class="ruby-keyword kw">true</span>
372
+ 25: <span class="ruby-keyword kw">end</span></pre>
372
373
  </div>
373
374
 
374
375
  </div>
@@ -403,11 +404,11 @@
403
404
  <div class="method-source-code"
404
405
  id="left-product-source">
405
406
  <pre>
406
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 43</span>
407
- 43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">left_product</span>(<span class="ruby-identifier">other</span>)
408
- 44: (<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">left_product!</span>(<span class="ruby-identifier">other</span>)
409
- 45: <span class="ruby-identifier">result</span>
410
- 46: <span class="ruby-keyword kw">end</span></pre>
407
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 49</span>
408
+ 49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">left_product</span>(<span class="ruby-identifier">other</span>)
409
+ 50: (<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">left_product!</span>(<span class="ruby-identifier">other</span>)
410
+ 51: <span class="ruby-identifier">result</span>
411
+ 52: <span class="ruby-keyword kw">end</span></pre>
411
412
  </div>
412
413
 
413
414
  </div>
@@ -438,12 +439,12 @@
438
439
  <div class="method-source-code"
439
440
  id="left-product--source">
440
441
  <pre>
441
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 30</span>
442
- 30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">left_product!</span>(<span class="ruby-identifier">other</span>)
443
- 31: <span class="ruby-ivar">@lists</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">dup</span>
444
- 32: <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">*=</span> <span class="ruby-ivar">@lists</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">size</span>
445
- 33: <span class="ruby-keyword kw">self</span>
446
- 34: <span class="ruby-keyword kw">end</span></pre>
442
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 36</span>
443
+ 36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">left_product!</span>(<span class="ruby-identifier">other</span>)
444
+ 37: <span class="ruby-ivar">@lists</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-constant">Array</span>(<span class="ruby-identifier">other</span>).<span class="ruby-identifier">dup</span>
445
+ 38: <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">*=</span> <span class="ruby-ivar">@lists</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">size</span>
446
+ 39: <span class="ruby-keyword kw">self</span>
447
+ 40: <span class="ruby-keyword kw">end</span></pre>
447
448
  </div>
448
449
 
449
450
  </div>
@@ -474,11 +475,11 @@
474
475
  <div class="method-source-code"
475
476
  id="product-source">
476
477
  <pre>
477
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 36</span>
478
- 36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">product</span>(<span class="ruby-identifier">other</span>)
479
- 37: (<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">product!</span>(<span class="ruby-identifier">other</span>)
480
- 38: <span class="ruby-identifier">result</span>
481
- 39: <span class="ruby-keyword kw">end</span></pre>
478
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 42</span>
479
+ 42: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">product</span>(<span class="ruby-identifier">other</span>)
480
+ 43: (<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">product!</span>(<span class="ruby-identifier">other</span>)
481
+ 44: <span class="ruby-identifier">result</span>
482
+ 45: <span class="ruby-keyword kw">end</span></pre>
482
483
  </div>
483
484
 
484
485
  </div>
@@ -513,12 +514,12 @@
513
514
  <div class="method-source-code"
514
515
  id="product--source">
515
516
  <pre>
516
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 22</span>
517
- 22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">other</span>)
518
- 23: <span class="ruby-ivar">@lists</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">dup</span>
519
- 24: <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">*=</span> <span class="ruby-ivar">@lists</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">size</span>
520
- 25: <span class="ruby-keyword kw">self</span>
521
- 26: <span class="ruby-keyword kw">end</span></pre>
517
+ <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 28</span>
518
+ 28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">other</span>)
519
+ 29: <span class="ruby-ivar">@lists</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Array</span>(<span class="ruby-identifier">other</span>).<span class="ruby-identifier">dup</span>
520
+ 30: <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">*=</span> <span class="ruby-ivar">@lists</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">size</span>
521
+ 31: <span class="ruby-keyword kw">self</span>
522
+ 32: <span class="ruby-keyword kw">end</span></pre>
522
523
  </div>
523
524
 
524
525
  </div>
@@ -38,8 +38,8 @@
38
38
  <div class="section-body">
39
39
  <ul>
40
40
 
41
- <li><a href="./lib/cartesian_iterator_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
- class="thickbox" title="lib/cartesian_iterator.rb">lib/cartesian_iterator.rb</a></li>
41
+ <li><a href="./lib/iterable_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="lib/iterable.rb">lib/iterable.rb</a></li>
43
43
 
44
44
  </ul>
45
45
  </div>
@@ -62,6 +62,8 @@
62
62
  <h3 class="section-header">Methods</h3>
63
63
  <ul class="link-list">
64
64
 
65
+ <li><a href="#method-i-done%3F">#done?</a></li>
66
+
65
67
  <li><a href="#method-i-next">#next</a></li>
66
68
 
67
69
  <li><a href="#method-i-raw_next">#raw_next</a></li>
@@ -145,6 +147,43 @@
145
147
  <h3 class="section-header">Public Instance Methods</h3>
146
148
 
147
149
 
150
+ <div id="done--method" class="method-detail ">
151
+ <a name="method-i-done%3F"></a>
152
+
153
+ <div class="method-heading">
154
+
155
+ <span class="method-name">done?</span><span
156
+ class="method-args">()</span>
157
+ <span class="method-click-advice">click to toggle source</span>
158
+
159
+ </div>
160
+
161
+ <div class="method-description">
162
+
163
+ <p>
164
+ TODO: consider a module inclusion time solution to &#8220;count rescue
165
+ size&#8221;, for performance sake
166
+ </p>
167
+
168
+
169
+
170
+ <div class="method-source-code"
171
+ id="done--source">
172
+ <pre>
173
+ <span class="ruby-comment cmt"># File lib/iterable.rb, line 22</span>
174
+ 22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">done?</span>
175
+ 23: <span class="ruby-ivar">@next_index</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-ivar">@next_index</span> <span class="ruby-operator">==</span> (<span class="ruby-identifier">count</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">size</span>)<span class="ruby-operator">-</span><span class="ruby-value">1</span>)
176
+ 24: <span class="ruby-keyword kw">end</span></pre>
177
+ </div>
178
+
179
+ </div>
180
+
181
+
182
+
183
+
184
+ </div>
185
+
186
+
148
187
  <div id="next-method" class="method-detail ">
149
188
  <a name="method-i-next"></a>
150
189
 
@@ -165,11 +204,11 @@
165
204
  <div class="method-source-code"
166
205
  id="next-source">
167
206
  <pre>
168
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 83</span>
169
- 83: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
170
- 84: <span class="ruby-identifier">restart</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@next_index</span>
171
- 85: <span class="ruby-identifier">raw_next</span>
172
- 86: <span class="ruby-keyword kw">end</span></pre>
207
+ <span class="ruby-comment cmt"># File lib/iterable.rb, line 7</span>
208
+ 7: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
209
+ 8: <span class="ruby-identifier">restart</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@next_index</span>
210
+ 9: <span class="ruby-identifier">raw_next</span>
211
+ 10: <span class="ruby-keyword kw">end</span></pre>
173
212
  </div>
174
213
 
175
214
  </div>
@@ -200,10 +239,11 @@
200
239
  <div class="method-source-code"
201
240
  id="raw-next-source">
202
241
  <pre>
203
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 88</span>
204
- 88: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">raw_next</span>
205
- 89: <span class="ruby-keyword kw">self</span>[<span class="ruby-ivar">@next_index</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>]
206
- 90: <span class="ruby-keyword kw">end</span></pre>
242
+ <span class="ruby-comment cmt"># File lib/iterable.rb, line 12</span>
243
+ 12: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">raw_next</span>
244
+ 13: <span class="ruby-identifier">raise</span> <span class="ruby-constant">RangeError</span>, <span class="ruby-value str">'there is no next element, please restart'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">done?</span>
245
+ 14: <span class="ruby-keyword kw">self</span>[<span class="ruby-ivar">@next_index</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>]
246
+ 15: <span class="ruby-keyword kw">end</span></pre>
207
247
  </div>
208
248
 
209
249
  </div>
@@ -234,11 +274,11 @@
234
274
  <div class="method-source-code"
235
275
  id="restart-source">
236
276
  <pre>
237
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 78</span>
238
- 78: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart</span>
239
- 79: <span class="ruby-ivar">@next_index</span> = <span class="ruby-value">1</span>
240
- 80: <span class="ruby-keyword kw">true</span>
241
- 81: <span class="ruby-keyword kw">end</span></pre>
277
+ <span class="ruby-comment cmt"># File lib/iterable.rb, line 2</span>
278
+ 2: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart</span>
279
+ 3: <span class="ruby-ivar">@next_index</span> = <span class="ruby-value">1</span>
280
+ 4: <span class="ruby-keyword kw">self</span>
281
+ 5: <span class="ruby-keyword kw">end</span></pre>
242
282
  </div>
243
283
 
244
284
  </div>
@@ -269,10 +309,10 @@
269
309
  <div class="method-source-code"
270
310
  id="restart-and-raw-next-source">
271
311
  <pre>
272
- <span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 92</span>
273
- 92: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart_and_raw_next</span>
274
- 93: <span class="ruby-keyword kw">self</span>[<span class="ruby-ivar">@next_index</span> = <span class="ruby-value">0</span>]
275
- 94: <span class="ruby-keyword kw">end</span></pre>
312
+ <span class="ruby-comment cmt"># File lib/iterable.rb, line 17</span>
313
+ 17: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart_and_raw_next</span>
314
+ 18: <span class="ruby-keyword kw">self</span>[<span class="ruby-ivar">@next_index</span> = <span class="ruby-value">0</span>]
315
+ 19: <span class="ruby-keyword kw">end</span></pre>
276
316
  </div>
277
317
 
278
318
  </div>
@@ -183,7 +183,7 @@ sudo gem install cartesian
183
183
  (The MIT License)
184
184
  </p>
185
185
  <p>
186
- Copyright &#169; 2006-2011 Adriano Mitre <adriano.mitre@gmail.com>
186
+ Copyright &#169; 2006-2012 Adriano Mitre <adriano.mitre@gmail.com>
187
187
  </p>
188
188
  <p>
189
189
  Permission is hereby granted, free of charge, to any person obtaining a
@@ -1,5 +1,6 @@
1
- Fri, 07 Jan 2011 13:53:06 -0200
2
- README.rdoc Fri, 07 Jan 2011 02:46:43 -0200
3
- lib/cartesian.rb Fri, 07 Jan 2011 13:53:03 -0200
4
- lib/cartesian_iterator.rb Fri, 07 Jan 2011 02:46:43 -0200
5
- lib/grid_search.rb Wed, 05 Jan 2011 06:07:10 -0200
1
+ Sun, 15 Apr 2012 03:34:04 -0300
2
+ README.rdoc Sun, 15 Apr 2012 03:31:27 -0300
3
+ lib/cartesian.rb Sun, 15 Apr 2012 03:31:27 -0300
4
+ lib/cartesian_iterator.rb Sun, 15 Apr 2012 03:31:27 -0300
5
+ lib/grid_search.rb Sun, 15 Apr 2012 03:31:27 -0300
6
+ lib/iterable.rb Sun, 15 Apr 2012 03:31:27 -0300
@@ -73,6 +73,8 @@
73
73
 
74
74
  <li><a href="Cartesian.html#method-i-cartesian">#cartesian &mdash; Cartesian</a></li>
75
75
 
76
+ <li><a href="Iterable.html#method-i-done%3F">#done? &mdash; Iterable</a></li>
77
+
76
78
  <li><a href="CartesianIterator.html#method-i-dup">#dup &mdash; CartesianIterator</a></li>
77
79
 
78
80
  <li><a href="CartesianIterator.html#method-i-each">#each &mdash; CartesianIterator</a></li>
@@ -24,13 +24,15 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2011-01-07 02:46:43 -0200</dd>
27
+ <dd class="modified-date">2012-04-15 03:31:27 -0300</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
31
31
  <dd class="requires">
32
32
  <ul>
33
33
 
34
+ <li>iterable</li>
35
+
34
36
  </ul>
35
37
  </dd>
36
38
 
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2011-01-07 13:53:03 -0200</dd>
27
+ <dd class="modified-date">2012-04-15 03:31:27 -0300</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -24,7 +24,7 @@
24
24
  <div id="metadata">
25
25
  <dl>
26
26
  <dt class="modified-date">Last Modified</dt>
27
- <dd class="modified-date">2011-01-05 06:07:10 -0200</dd>
27
+ <dd class="modified-date">2012-04-15 03:31:27 -0300</dd>
28
28
 
29
29
 
30
30
  <dt class="requires">Requires</dt>
@@ -1,128 +1,5 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
- <title>
8
-
9
- </title>
10
- <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
- <style>
12
1
 
13
- </style>
14
- <script type="text/javascript">
15
- window.onload = function() {
16
- settings = {
17
- tl: { radius: 10 },
18
- tr: { radius: 10 },
19
- bl: { radius: 10 },
20
- br: { radius: 10 },
21
- antiAlias: true,
22
- autoPad: true,
23
- validTags: ["div"]
24
- }
25
- var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
- versionBox.applyCornersToAll();
27
- }
28
- </script>
29
- </head>
30
- <body>
31
- <div id="main">
32
2
 
33
- <h1></h1>
34
- <div id="version" class="clickable" onclick='document.location = "http://github.com/adrianomitre/cartesian"; return false'>
35
- <p>Get Version</p>
36
- <a href="http://github.com/adrianomitre/cartesian" class="numbers">0.6.4</a>
37
- </div>
38
- <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script><h1>cartesian</h1>
39
- <h3>Cartesian products in Ruby</h3>
40
- <h2>What</h2>
41
- <p>Provides methods for the calculation of the cartesian producted between<br />
42
- two or more enumerable objects. Includes grid search optimization methods.<br />
43
- It can also be easily and conveniently mixed-in into any enumerable class.</p>
44
- <h2>Installing</h2>
45
- <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">cartesian</span></pre></p>
46
- <h2>The basics</h2>
47
- <p><pre class='syntax'><span class="constant">Cartesian</span><span class="punct">::</span><span class="ident">product</span> <span class="punct">[</span><span class="number">1</span><span class="punct">,</span><span class="number">2</span><span class="punct">],[</span><span class="number">3</span><span class="punct">,</span><span class="number">4</span><span class="punct">]</span> <span class="comment">#=&gt; [[1, 3], [1, 4], [2, 3], [2, 4]]</span></pre></p>
48
- <h2>Demonstration of usage</h2>
49
- <p>One can use the Cartesian module directly<br />
50
- <pre class='syntax'>
51
- <span class="ident">require</span> <span class="punct">'</span><span class="string">cartesian</span><span class="punct">'</span>
52
- <span class="ident">foo</span> <span class="punct">=</span> <span class="punct">[</span><span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">]</span>
53
- <span class="ident">bar</span> <span class="punct">=</span> <span class="punct">[&quot;</span><span class="string">a</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">b</span><span class="punct">&quot;]</span>
54
- <span class="constant">Cartesian</span><span class="punct">::</span><span class="ident">product</span><span class="punct">(</span><span class="ident">foo</span><span class="punct">,</span> <span class="ident">bar</span><span class="punct">)</span> <span class="comment">#=&gt; [[1, &quot;a&quot;], [1, &quot;b&quot;], [2, &quot;a&quot;], [2, &quot;b&quot;]]</span>
55
- </pre></p>
56
- <p>or use the methods provided by the mixin in the Array class</p>
57
- <p><pre class='syntax'>
58
- <span class="ident">foo</span><span class="punct">.</span><span class="ident">cartesian</span><span class="punct">(</span><span class="ident">bar</span><span class="punct">)</span> <span class="comment">#=&gt; [[1, &quot;a&quot;], [1, &quot;b&quot;], [2, &quot;a&quot;], [2, &quot;b&quot;]]</span>
59
- </pre></p>
60
- <p>which include the short&#8217;n&#8217;sweet <em>x</em> method</p>
61
- <p><pre class='syntax'>
62
- <span class="ident">v</span> <span class="punct">=</span> <span class="punct">[]</span> <span class="comment">#=&gt; []</span>
63
- <span class="keyword">for</span> <span class="ident">a</span><span class="punct">,</span> <span class="ident">b</span> <span class="keyword">in</span> <span class="punct">[</span><span class="number">1</span><span class="punct">,</span><span class="number">2</span><span class="punct">].</span><span class="ident">x</span> <span class="punct">[</span><span class="number">3</span><span class="punct">,</span><span class="number">4</span><span class="punct">]</span>
64
- <span class="ident">v</span> <span class="punct">&lt;&lt;</span> <span class="punct">[</span><span class="ident">a</span><span class="punct">,</span><span class="ident">b</span><span class="punct">]</span>
65
- <span class="keyword">end</span> <span class="comment">#=&gt; true</span>
66
- <span class="ident">v</span> <span class="comment">#=&gt; [[1, 3], [1, 4], [2, 3], [2, 4]]</span>
67
- </pre></p>
68
- <p>The &#8216;**&#8217; operator provides a convenient way of iterating multi-dimensionally over the same array or range</p>
69
- <p><pre class='syntax'>
70
- <span class="ident">u</span> <span class="punct">=</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">1</span><span class="punct">]**</span><span class="number">3</span> <span class="comment">#=&gt; #&lt;CartesianIterator:0x7f2fb8e54978 @tot_iter=8, \</span>
71
- <span class="comment"># @lists=[[0, 1], [0, 1], [0, 1]]&gt;</span>
72
- <span class="ident">u</span><span class="punct">.</span><span class="ident">to_a</span> <span class="comment">#=&gt; [[0, 0, 0], [0, 0, 1], [0, 1, 0], \</span>
73
- <span class="comment"># [0, 1, 1], [1, 0, 0], [1, 0, 1], \</span>
74
- <span class="comment"># [1, 1, 0], [1, 1, 1]]</span>
75
- </pre></p>
76
- <p>Finally, the grid search methods</p>
77
- <p><pre class='syntax'>
78
- <span class="ident">require</span> <span class="punct">'</span><span class="string">grid_search</span><span class="punct">'</span>
79
- <span class="punct">[-</span><span class="number">1</span><span class="punct">,</span> <span class="number">0</span><span class="punct">,</span> <span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">].</span><span class="ident">argmax</span> <span class="punct">{|</span><span class="ident">x</span><span class="punct">|</span> <span class="ident">x</span><span class="punct">**</span><span class="number">2</span> <span class="punct">}</span> <span class="comment">#=&gt; 2</span>
80
- <span class="punct">[-</span><span class="number">1</span><span class="punct">,</span> <span class="number">0</span><span class="punct">,</span> <span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">].</span><span class="ident">argmin</span> <span class="punct">{|</span><span class="ident">x</span><span class="punct">|</span> <span class="ident">x</span><span class="punct">.</span><span class="ident">abs</span> <span class="punct">}</span> <span class="comment">#=&gt; 0</span></pre><br />
81
- </pre></p>
82
- <p>For more examples and details, see the RDoc-generated documentation <a href="doc/index.html">here</a>.</p>
83
- <h2>How to submit patches</h2>
84
- <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
85
- <p>You can fetch the source from:</p>
86
- <ul>
87
- <li>github: <a href="http://github.com/adrianomitre/cartesian/tree/master">http://github.com/adrianomitre/cartesian/tree/master</a></li>
88
- </ul>
89
- <pre>git clone git@github.com:adrianomitre/cartesian.git</pre>
90
- <h3>Build and test instructions</h3>
91
- <pre>cd cartesian
92
- rake test
93
- rake install_gem</pre>
94
- <h2>License</h2>
95
- <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
96
- <h2>Contact</h2>
97
- <p>Comments are welcome. Send an email to <a href="mailto:adriano.mitre@gmail.com">Adriano Mitre</a>.</p>
98
- <div align=right>
99
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
100
- <input type="hidden" name="cmd" value="_s-xclick">
101
- <input type="hidden" name="hosted_button_id" value="9ABWULT73Y7AC">
102
- <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
103
- <p><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></p>
104
- </form>
105
- </div>
106
- <p class="coda">
107
- <a href="http://github.com/adrianomitre">Adriano Mitre</a>, 7th January 2011<br>
108
- Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
109
- </p>
110
- </div>
3
+ Generating the website requires the newgem RubyGem
4
+ Install: gem install newgem
111
5
 
112
- <!-- insert site tracking codes here, like Google Urchin -->
113
- <script type="text/javascript">
114
-
115
- var _gaq = _gaq || [];
116
- _gaq.push(['_setAccount', 'UA-20605454-1']);
117
- _gaq.push(['_trackPageview']);
118
-
119
- (function() {
120
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
121
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
122
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
123
- })();
124
-
125
- </script>
126
-
127
- </body>
128
- </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartesian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-13 00:00:00.000000000 Z
12
+ date: 2012-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: newgem
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.5.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.3
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: hoe
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +92,7 @@ files:
76
92
  - lib/cartesian/version.rb
77
93
  - lib/cartesian_iterator.rb
78
94
  - lib/grid_search.rb
95
+ - lib/iterable.rb
79
96
  - script/console
80
97
  - script/destroy
81
98
  - script/generate
@@ -87,6 +104,7 @@ files:
87
104
  - test/test_extensions.rb
88
105
  - test/test_grid_search.rb
89
106
  - test/test_helper.rb
107
+ - test/test_iterable.rb
90
108
  - test/test_suite.rb
91
109
  - website/doc/Array.html
92
110
  - website/doc/Cartesian.html
@@ -106,7 +124,6 @@ files:
106
124
  - website/javascripts/rounded_corners_lite.inc.js
107
125
  - website/stylesheets/screen.css
108
126
  - website/template.html.erb
109
- - test/test_iterable.rb
110
127
  - .gemtest
111
128
  homepage: http://adrianomitre.github.com/cartesian/website/index.html
112
129
  licenses: []