epitools 0.5.64 → 0.5.65
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext/enumerable.rb +25 -30
- data/spec/core_ext_spec.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94166d901d6ab0595ed2a71eec10b24d91d52fec
|
4
|
+
data.tar.gz: 1eecd4e24c563b3622a20f3da7606c2bd558ed60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beea01a551fa4042079de50f34ad39e75d1b7d42a996350c4983febfa63cb0771e525f7eeb949907a9d27be3bbc27f53dd6774e0dfd847b21aa0986bec986328
|
7
|
+
data.tar.gz: 65e93518be6608ee373e76ed7dddc9c1ef53b9fe1182f96409d9cad75b880e218ada0ff8d56c6e2cf8fac226c6a451e6c88914a9b2d48de817e508b7ec16a17f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
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
|
-
|
79
|
-
|
74
|
+
Enumerator.new do |yielder|
|
75
|
+
current_chunk = []
|
76
|
+
splits = 0
|
77
|
+
max_splits = options[:once] == true ? 1 : options[:max_splits]
|
80
78
|
|
81
|
-
|
82
|
-
max_splits = options[:once] == true ? 1 : options[:max_splits]
|
79
|
+
each do |e|
|
83
80
|
|
84
|
-
|
81
|
+
if boundary_test_proc.call(e) and (max_splits == nil or splits < max_splits)
|
85
82
|
|
86
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
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
|
-
|
107
|
+
yielder << current_chunk if current_chunk.any?
|
111
108
|
|
112
|
-
|
113
|
-
|
114
|
-
chunks # resultset
|
109
|
+
end
|
115
110
|
end
|
116
111
|
|
117
112
|
#
|
data/spec/core_ext_spec.rb
CHANGED
@@ -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 "
|
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.
|
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-
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|