merge_enum 0.3.0 → 0.4.0
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 +4 -4
- data/lib/merge_enum/merge_enumerable.rb +44 -16
- data/lib/merge_enum/version.rb +1 -1
- data/spec/merge_enum/merge_enumerable_spec.rb +970 -368
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b344598810bdbe8112d13374ee3ef4ca181c72d5
|
4
|
+
data.tar.gz: c996eeb69073556486627ab077c283b36087bed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c06db945cffc49ab77aed6a1dd72c09d1eb55141301562ef2ddab741bfece4e195006d40f5514cc9cef9235fdaff2b660297e77b52c03f69b875c118fc34577
|
7
|
+
data.tar.gz: 97a5db5273067661a5f5a321a75ac289664ec1306be13bb0704b1de854d280417a4c5e5ec10424ce6f72d56205c7a4a9d8acb08d167a0d10515f91e283c23cb4
|
@@ -20,18 +20,7 @@ module MergeEnum
|
|
20
20
|
# options
|
21
21
|
opt_fst = @options[:first]
|
22
22
|
opt_fst = opt_fst.to_i if opt_fst
|
23
|
-
|
24
|
-
opt_cmpct_proc = if opt_cmpct.is_a? Proc
|
25
|
-
if opt_cmpct.arity == 0
|
26
|
-
-> (e) { opt_cmpct.call }
|
27
|
-
else
|
28
|
-
opt_cmpct
|
29
|
-
end
|
30
|
-
elsif opt_cmpct
|
31
|
-
-> (e) { e.nil? }
|
32
|
-
else
|
33
|
-
-> (e) { false }
|
34
|
-
end
|
23
|
+
(opt_proc, _proc) = merge_options_proc @options
|
35
24
|
|
36
25
|
# local variables
|
37
26
|
cnt = 0
|
@@ -53,17 +42,17 @@ module MergeEnum
|
|
53
42
|
c = c.call fst
|
54
43
|
called_first = true
|
55
44
|
else
|
56
|
-
c = c.call fst,
|
45
|
+
c = c.call fst, opt_proc
|
57
46
|
called_first = true
|
58
47
|
end
|
59
48
|
end
|
60
49
|
|
61
50
|
if fst
|
62
51
|
# with first option
|
63
|
-
c = c.first fst unless called_first or
|
52
|
+
c = c.first fst unless called_first or _proc
|
64
53
|
_cnt = 0
|
65
54
|
c.each do |e|
|
66
|
-
next if
|
55
|
+
next if _proc and not opt_proc.call e
|
67
56
|
block.call e
|
68
57
|
_cnt += 1
|
69
58
|
break if fst <= _cnt
|
@@ -72,7 +61,7 @@ module MergeEnum
|
|
72
61
|
else
|
73
62
|
# without first option
|
74
63
|
c.each do |e|
|
75
|
-
next if
|
64
|
+
next if _proc and not opt_proc.call e
|
76
65
|
block.call e
|
77
66
|
end
|
78
67
|
end
|
@@ -80,6 +69,45 @@ module MergeEnum
|
|
80
69
|
self
|
81
70
|
end
|
82
71
|
|
72
|
+
private
|
73
|
+
|
74
|
+
def merge_options_proc options
|
75
|
+
opts = []
|
76
|
+
|
77
|
+
opt_cmpct = options[:compact]
|
78
|
+
opts << if opt_cmpct.is_a? Proc
|
79
|
+
if opt_cmpct.arity == 0
|
80
|
+
[-> (e) { not opt_cmpct.call }, true]
|
81
|
+
else
|
82
|
+
[-> (e) { not opt_cmpct.call e }, true]
|
83
|
+
end
|
84
|
+
elsif opt_cmpct
|
85
|
+
[-> (e) { not e.nil? }, true]
|
86
|
+
else
|
87
|
+
[-> (e) { true }, false]
|
88
|
+
end
|
89
|
+
|
90
|
+
opt_slct = options[:select]
|
91
|
+
opts << if opt_slct.is_a? Proc
|
92
|
+
if opt_slct.arity == 0
|
93
|
+
[-> (e) { opt_slct.call }, true]
|
94
|
+
else
|
95
|
+
[opt_slct, true]
|
96
|
+
end
|
97
|
+
elsif opt_slct
|
98
|
+
raise ":select is must be a Proc"
|
99
|
+
else
|
100
|
+
[-> (e) { true }, false]
|
101
|
+
end
|
102
|
+
|
103
|
+
[
|
104
|
+
-> (e) { opts.all?{ |opt| opt[0].call e } },
|
105
|
+
opts.any?{ |opt| opt[1] }
|
106
|
+
]
|
107
|
+
end
|
108
|
+
|
109
|
+
public
|
110
|
+
|
83
111
|
def concat arg
|
84
112
|
self.class.new *@collections, arg, @options
|
85
113
|
end
|
data/lib/merge_enum/version.rb
CHANGED