epitools 0.5.64 → 0.5.65

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c97e30eb1552bb115bad441fa21bf0c5e1a58a10
4
- data.tar.gz: 5559b075618fdc77e4bc55ece12b42dc8cf4ad49
3
+ metadata.gz: 94166d901d6ab0595ed2a71eec10b24d91d52fec
4
+ data.tar.gz: 1eecd4e24c563b3622a20f3da7606c2bd558ed60
5
5
  SHA512:
6
- metadata.gz: b61f7535b2d27d437bedc30197de4de5b09a4d2234f8580c33779a37b9337031e31a6e071995ffeb111ef87a195dec7502ee5aba42b15d7899d836a5980888bf
7
- data.tar.gz: cb9807f3b5953ece8e40171aa48363042c5610a28aea82c1702f6b7ce3c2f536106294f7b06a45b42b86491715b83b05267d65b15609fdf14e46df3cd51f97fb
6
+ metadata.gz: beea01a551fa4042079de50f34ad39e75d1b7d42a996350c4983febfa63cb0771e525f7eeb949907a9d27be3bbc27f53dd6774e0dfd847b21aa0986bec986328
7
+ data.tar.gz: 65e93518be6608ee373e76ed7dddc9c1ef53b9fe1182f96409d9cad75b880e218ada0ff8d56c6e2cf8fac226c6a451e6c88914a9b2d48de817e508b7ec16a17f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.64
1
+ 0.5.65
@@ -58,10 +58,6 @@ module Enumerable
58
58
  # #=> [ ["Chapter 1", ...], ["Chapter 2", ...], etc. ]
59
59
  #
60
60
  def split_at(matcher=nil, options={}, &block)
61
- # TODO: Ruby 1.9 returns Enumerators for everything now. Maybe use that?
62
-
63
- return self unless self.any?
64
-
65
61
  include_boundary = options[:include_boundary] || false
66
62
 
67
63
  if matcher.nil?
@@ -75,43 +71,42 @@ module Enumerable
75
71
  end
76
72
  end
77
73
 
78
- chunks = []
79
- current_chunk = []
74
+ Enumerator.new do |yielder|
75
+ current_chunk = []
76
+ splits = 0
77
+ max_splits = options[:once] == true ? 1 : options[:max_splits]
80
78
 
81
- splits = 0
82
- max_splits = options[:once] == true ? 1 : options[:max_splits]
79
+ each do |e|
83
80
 
84
- each do |e|
81
+ if boundary_test_proc.call(e) and (max_splits == nil or splits < max_splits)
85
82
 
86
- if boundary_test_proc.call(e) and (max_splits == nil or splits < max_splits)
83
+ if current_chunk.empty? and not include_boundary
84
+ next # hit 2 boundaries in a row... just keep moving, people!
85
+ end
87
86
 
88
- if current_chunk.empty? and not include_boundary
89
- next # hit 2 boundaries in a row... just keep moving, people!
90
- end
87
+ if options[:after]
88
+ # split after boundary
89
+ current_chunk << e if include_boundary # include the boundary, if necessary
90
+ yielder << current_chunk # shift everything after the boundary into the resultset
91
+ current_chunk = [] # start a new result
92
+ else
93
+ # split before boundary
94
+ yielder << current_chunk # shift before the boundary into the resultset
95
+ current_chunk = [] # start a new result
96
+ current_chunk << e if include_boundary # include the boundary, if necessary
97
+ end
98
+
99
+ splits += 1
91
100
 
92
- if options[:after]
93
- # split after boundary
94
- current_chunk << e if include_boundary # include the boundary, if necessary
95
- chunks << current_chunk # shift everything after the boundary into the resultset
96
- current_chunk = [] # start a new result
97
101
  else
98
- # split before boundary
99
- chunks << current_chunk # shift before the boundary into the resultset
100
- current_chunk = [] # start a new result
101
- current_chunk << e if include_boundary # include the boundary, if necessary
102
+ current_chunk << e
102
103
  end
103
104
 
104
- splits += 1
105
-
106
- else
107
- current_chunk << e
108
105
  end
109
106
 
110
- end
107
+ yielder << current_chunk if current_chunk.any?
111
108
 
112
- chunks << current_chunk if current_chunk.any?
113
-
114
- chunks # resultset
109
+ end
115
110
  end
116
111
 
117
112
  #
@@ -470,23 +470,23 @@ describe Enumerable do
470
470
  end
471
471
 
472
472
  it "splits" do
473
- [1,2,3,4,5].split_at {|e| e == 3}.should == [ [1,2], [4,5] ]
474
- [1,2,3,4,5].split_after {|e| e == 3}.should == [ [1,2,3], [4,5] ]
475
- [1,2,3,4,5].split_before {|e| e == 3}.should == [ [1,2], [3,4,5] ]
473
+ [1,2,3,4,5].split_at {|e| e == 3}.to_a.should == [ [1,2], [4,5] ]
474
+ [1,2,3,4,5].split_after {|e| e == 3}.to_a.should == [ [1,2,3], [4,5] ]
475
+ [1,2,3,4,5].split_before {|e| e == 3}.to_a.should == [ [1,2], [3,4,5] ]
476
476
 
477
477
  result = "a\nb\n---\nc\nd\n".lines.split_at(/---/)
478
478
  result.map_recursively(&:strip).should == [ %w[a b], %w[c d] ]
479
479
  end
480
480
 
481
- it "handles nested things" do
481
+ it "splits with nested things" do
482
482
  array = [ [],["a"],"a",[1,2,3] ]
483
483
 
484
484
  lambda {
485
485
  array.split_at("a")
486
486
  }.should_not raise_error
487
487
 
488
- array.split_at("a").should == [ array[0..1], array[3..3] ]
489
- array.split_at([1,2,3]).should == [ array[0..2] ]
488
+ array.split_at("a").to_a.should == [ array[0..1], array[3..3] ]
489
+ array.split_at([1,2,3]).to_a.should == [ array[0..2] ]
490
490
  end
491
491
 
492
492
  it "handles arbitrary objects" do
@@ -495,7 +495,7 @@ describe Enumerable do
495
495
  particular = arbitrary.new(1,2,3)
496
496
  array = [ arbitrary.new, arbitrary.new, particular, arbitrary.new]
497
497
 
498
- array.split_at(particular).should == [ array[0..1], array[3..3] ]
498
+ array.split_at(particular).to_a.should == [ array[0..1], array[3..3] ]
499
499
  end
500
500
 
501
501
  it "sums" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.64
4
+ version: 0.5.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-04 00:00:00.000000000 Z
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec