musa-dsl 0.14.18 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/README.md +5 -1
- data/lib/musa-dsl.rb +54 -11
- data/lib/musa-dsl/core-ext.rb +7 -13
- data/lib/musa-dsl/core-ext/array-explode-ranges.rb +15 -23
- data/lib/musa-dsl/core-ext/arrayfy.rb +30 -12
- data/lib/musa-dsl/core-ext/attribute-builder.rb +194 -0
- data/lib/musa-dsl/core-ext/deep-copy.rb +185 -0
- data/lib/musa-dsl/core-ext/dynamic-proxy.rb +44 -40
- data/lib/musa-dsl/core-ext/inspect-nice.rb +40 -22
- data/lib/musa-dsl/core-ext/smart-proc-binder.rb +108 -0
- data/lib/musa-dsl/core-ext/with.rb +26 -0
- data/lib/musa-dsl/datasets.rb +8 -3
- data/lib/musa-dsl/datasets/dataset.rb +3 -0
- data/lib/musa-dsl/datasets/delta-d.rb +12 -0
- data/lib/musa-dsl/datasets/e.rb +61 -0
- data/lib/musa-dsl/datasets/gdv.rb +51 -411
- data/lib/musa-dsl/datasets/gdvd.rb +179 -0
- data/lib/musa-dsl/datasets/helper.rb +41 -0
- data/lib/musa-dsl/datasets/p.rb +68 -0
- data/lib/musa-dsl/datasets/packed-v.rb +19 -0
- data/lib/musa-dsl/datasets/pdv.rb +22 -15
- data/lib/musa-dsl/datasets/ps.rb +113 -0
- data/lib/musa-dsl/datasets/score.rb +210 -0
- data/lib/musa-dsl/datasets/score/queriable.rb +48 -0
- data/lib/musa-dsl/datasets/score/render.rb +31 -0
- data/lib/musa-dsl/datasets/score/to-mxml/process-pdv.rb +160 -0
- data/lib/musa-dsl/datasets/score/to-mxml/process-ps.rb +51 -0
- data/lib/musa-dsl/datasets/score/to-mxml/process-time.rb +153 -0
- data/lib/musa-dsl/datasets/score/to-mxml/to-mxml.rb +158 -0
- data/lib/musa-dsl/datasets/v.rb +23 -0
- data/lib/musa-dsl/generative.rb +5 -5
- data/lib/musa-dsl/generative/backboner.rb +274 -0
- data/lib/musa-dsl/generative/darwin.rb +102 -96
- data/lib/musa-dsl/generative/generative-grammar.rb +182 -187
- data/lib/musa-dsl/generative/markov.rb +56 -53
- data/lib/musa-dsl/generative/variatio.rb +234 -222
- data/lib/musa-dsl/logger.rb +1 -0
- data/lib/musa-dsl/logger/logger.rb +31 -0
- data/lib/musa-dsl/matrix.rb +1 -0
- data/lib/musa-dsl/matrix/matrix.rb +210 -0
- data/lib/musa-dsl/midi.rb +2 -2
- data/lib/musa-dsl/midi/midi-recorder.rb +54 -52
- data/lib/musa-dsl/midi/midi-voices.rb +183 -182
- data/lib/musa-dsl/music.rb +5 -5
- data/lib/musa-dsl/music/chord-definition.rb +54 -50
- data/lib/musa-dsl/music/chord-definitions.rb +13 -9
- data/lib/musa-dsl/music/chords.rb +236 -238
- data/lib/musa-dsl/music/equally-tempered-12-tone-scale-system.rb +187 -183
- data/lib/musa-dsl/music/scales.rb +331 -332
- data/lib/musa-dsl/musicxml.rb +1 -0
- data/lib/musa-dsl/musicxml/builder/attributes.rb +155 -0
- data/lib/musa-dsl/musicxml/builder/backup-forward.rb +45 -0
- data/lib/musa-dsl/musicxml/builder/direction.rb +322 -0
- data/lib/musa-dsl/musicxml/builder/helper.rb +90 -0
- data/lib/musa-dsl/musicxml/builder/measure.rb +137 -0
- data/lib/musa-dsl/musicxml/builder/note-complexities.rb +152 -0
- data/lib/musa-dsl/musicxml/builder/note.rb +577 -0
- data/lib/musa-dsl/musicxml/builder/part-group.rb +44 -0
- data/lib/musa-dsl/musicxml/builder/part.rb +67 -0
- data/lib/musa-dsl/musicxml/builder/pitched-note.rb +126 -0
- data/lib/musa-dsl/musicxml/builder/rest.rb +117 -0
- data/lib/musa-dsl/musicxml/builder/score-partwise.rb +120 -0
- data/lib/musa-dsl/musicxml/builder/typed-text.rb +43 -0
- data/lib/musa-dsl/musicxml/builder/unpitched-note.rb +112 -0
- data/lib/musa-dsl/neumalang.rb +1 -1
- data/lib/musa-dsl/neumalang/datatypes.citrus +79 -0
- data/lib/musa-dsl/neumalang/neuma.citrus +165 -0
- data/lib/musa-dsl/neumalang/neumalang.citrus +32 -242
- data/lib/musa-dsl/neumalang/neumalang.rb +373 -142
- data/lib/musa-dsl/neumalang/process.citrus +21 -0
- data/lib/musa-dsl/neumalang/terminals.citrus +67 -0
- data/lib/musa-dsl/neumalang/vectors.citrus +23 -0
- data/lib/musa-dsl/neumas.rb +5 -0
- data/lib/musa-dsl/neumas/array-to-neumas.rb +34 -0
- data/lib/musa-dsl/neumas/neuma-decoder.rb +63 -0
- data/lib/musa-dsl/neumas/neuma-gdv-decoder.rb +57 -0
- data/lib/musa-dsl/neumas/neuma-gdvd-decoder.rb +15 -0
- data/lib/musa-dsl/neumas/neumas.rb +37 -0
- data/lib/musa-dsl/neumas/string-to-neumas.rb +33 -0
- data/lib/musa-dsl/repl.rb +1 -1
- data/lib/musa-dsl/repl/repl.rb +105 -105
- data/lib/musa-dsl/sequencer.rb +1 -1
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-control.rb +163 -136
- data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-helper.rb +301 -286
- data/lib/musa-dsl/sequencer/base-sequencer-implementation.rb +562 -270
- data/lib/musa-dsl/sequencer/base-sequencer-public.rb +199 -188
- data/lib/musa-dsl/sequencer/base-sequencer-tick-based.rb +77 -0
- data/lib/musa-dsl/sequencer/base-sequencer-tickless-based.rb +75 -0
- data/lib/musa-dsl/sequencer/sequencer-dsl.rb +105 -85
- data/lib/musa-dsl/sequencer/timeslots.rb +34 -0
- data/lib/musa-dsl/series.rb +1 -1
- data/lib/musa-dsl/{core-ext → series}/array-to-serie.rb +1 -1
- data/lib/musa-dsl/series/base-series.rb +171 -168
- data/lib/musa-dsl/series/hash-serie-splitter.rb +134 -132
- data/lib/musa-dsl/series/holder-serie.rb +1 -1
- data/lib/musa-dsl/series/main-serie-constructors.rb +6 -1
- data/lib/musa-dsl/series/main-serie-operations.rb +807 -797
- data/lib/musa-dsl/series/proxy-serie.rb +6 -6
- data/lib/musa-dsl/series/queue-serie.rb +5 -5
- data/lib/musa-dsl/series/series.rb +2 -0
- data/lib/musa-dsl/transcription.rb +4 -0
- data/lib/musa-dsl/transcription/from-gdv-to-midi.rb +227 -0
- data/lib/musa-dsl/transcription/from-gdv-to-musicxml.rb +36 -0
- data/lib/musa-dsl/transcription/from-gdv.rb +17 -0
- data/lib/musa-dsl/transcription/transcription.rb +55 -0
- data/lib/musa-dsl/transport.rb +6 -6
- data/lib/musa-dsl/transport/clock.rb +26 -26
- data/lib/musa-dsl/transport/dummy-clock.rb +32 -30
- data/lib/musa-dsl/transport/external-tick-clock.rb +21 -20
- data/lib/musa-dsl/transport/input-midi-clock.rb +82 -80
- data/lib/musa-dsl/transport/timer-clock.rb +72 -71
- data/lib/musa-dsl/transport/timer.rb +28 -26
- data/lib/musa-dsl/transport/transport.rb +98 -94
- data/musa-dsl.gemspec +3 -3
- metadata +73 -24
- data/lib/musa-dsl/core-ext/array-apply-get.rb +0 -18
- data/lib/musa-dsl/core-ext/array-to-neumas.rb +0 -28
- data/lib/musa-dsl/core-ext/as-context-run.rb +0 -44
- data/lib/musa-dsl/core-ext/duplicate.rb +0 -134
- data/lib/musa-dsl/core-ext/key-parameters-procedure-binder.rb +0 -85
- data/lib/musa-dsl/core-ext/proc-nice.rb +0 -13
- data/lib/musa-dsl/core-ext/send-nice.rb +0 -21
- data/lib/musa-dsl/core-ext/string-to-neumas.rb +0 -27
- data/lib/musa-dsl/datasets/gdv-decorators.rb +0 -221
- data/lib/musa-dsl/generative/rules.rb +0 -282
- data/lib/musa-dsl/neuma.rb +0 -1
- data/lib/musa-dsl/neuma/neuma.rb +0 -181
@@ -2,193 +2,195 @@ module Musa
|
|
2
2
|
# TODO: adapt to series prototyping
|
3
3
|
# TODO: full test cases
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
buffered
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
class HashSplitter
|
15
|
-
def initialize(proxy)
|
16
|
-
@proxy = proxy
|
17
|
-
@series = {}
|
5
|
+
module Series
|
6
|
+
module SerieOperations
|
7
|
+
def split(buffered: nil, master: nil)
|
8
|
+
buffered ||= false
|
9
|
+
|
10
|
+
return HashSplitter.new HashSplitter::KeyProxy.new(self) if master.nil? && !buffered
|
11
|
+
return HashSplitter.new HashSplitter::MasterSlaveKeyProxy.new(self, master) if !master.nil? && !buffered
|
12
|
+
return HashSplitter.new HashSplitter::BufferedKeyProxy.new(self) if buffered
|
18
13
|
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@series[key] = Splitted.new(@proxy, key: key)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class KeyProxy
|
29
|
-
def initialize(hash_serie)
|
30
|
-
@serie = hash_serie.instance
|
31
|
-
@values = {}
|
15
|
+
class HashSplitter
|
16
|
+
def initialize(proxy)
|
17
|
+
@proxy = proxy
|
18
|
+
@series = {}
|
32
19
|
end
|
33
20
|
|
34
|
-
def
|
35
|
-
@
|
36
|
-
|
21
|
+
def [](key)
|
22
|
+
serie = if @series.key? key
|
23
|
+
@series[key]
|
24
|
+
else
|
25
|
+
@series[key] = Splitted.new(@proxy, key: key)
|
26
|
+
end
|
37
27
|
end
|
38
28
|
|
39
|
-
|
40
|
-
|
29
|
+
class KeyProxy
|
30
|
+
def initialize(hash_serie)
|
31
|
+
@serie = hash_serie.instance
|
32
|
+
@values = {}
|
33
|
+
end
|
41
34
|
|
42
|
-
|
35
|
+
def restart
|
36
|
+
@serie.restart
|
37
|
+
@values = {}
|
38
|
+
end
|
43
39
|
|
44
|
-
|
45
|
-
|
40
|
+
def next_value(key)
|
41
|
+
return nil unless @values
|
46
42
|
|
47
|
-
|
48
|
-
value = @values[key] if @values
|
43
|
+
value = @values[key]
|
49
44
|
|
50
|
-
|
51
|
-
|
45
|
+
if value.nil?
|
46
|
+
before_values = @values.collect { |k, v| [k, v] unless v.nil? }.compact.to_h
|
52
47
|
|
53
|
-
|
48
|
+
@values = @serie.next_value
|
49
|
+
value = @values[key] if @values
|
54
50
|
|
55
|
-
|
56
|
-
|
51
|
+
warn "Warning: splitted serie #{@serie} values #{before_values} are being lost" if !value.nil? && !before_values.empty?
|
52
|
+
end
|
57
53
|
|
58
|
-
|
59
|
-
value = @values[key]
|
54
|
+
@values[key] = nil if @values
|
60
55
|
|
61
|
-
|
62
|
-
peek_values = @serie.peek_next_value
|
63
|
-
value = peek_values[key] if peek_values
|
56
|
+
value
|
64
57
|
end
|
65
58
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
59
|
+
def peek_next_value(key)
|
60
|
+
value = @values[key]
|
69
61
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
62
|
+
if value.nil?
|
63
|
+
peek_values = @serie.peek_next_value
|
64
|
+
value = peek_values[key] if peek_values
|
65
|
+
end
|
75
66
|
|
76
|
-
|
77
|
-
|
78
|
-
@values = {}
|
67
|
+
value
|
68
|
+
end
|
79
69
|
end
|
80
70
|
|
81
|
-
|
82
|
-
|
71
|
+
class BufferedKeyProxy
|
72
|
+
def initialize(hash_serie)
|
73
|
+
@serie = hash_serie.instance
|
74
|
+
@values = {}
|
75
|
+
end
|
76
|
+
|
77
|
+
def restart
|
78
|
+
@serie.restart
|
79
|
+
@values = {}
|
80
|
+
end
|
81
|
+
|
82
|
+
def next_value(key)
|
83
|
+
value = nil
|
83
84
|
|
84
|
-
|
85
|
-
|
85
|
+
if @values[key].nil? || @values[key].empty?
|
86
|
+
hash_value = @serie.next_value
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
if hash_value
|
89
|
+
hash_value.each do |k, v|
|
90
|
+
@values[k] = [] if @values[k].nil?
|
91
|
+
@values[k] << v
|
92
|
+
end
|
91
93
|
end
|
92
94
|
end
|
95
|
+
|
96
|
+
value = @values[key].shift if @values[key]
|
97
|
+
|
98
|
+
value
|
93
99
|
end
|
94
100
|
|
95
|
-
|
101
|
+
def peek_next_value(key)
|
102
|
+
value = nil
|
96
103
|
|
97
|
-
|
104
|
+
if @values[key] && !@values[key].empty?
|
105
|
+
value = @values[key].first
|
106
|
+
else
|
107
|
+
peek_values = @serie.peek_next_value
|
108
|
+
value = peek_values[key] if peek_values
|
109
|
+
end
|
110
|
+
|
111
|
+
value
|
112
|
+
end
|
98
113
|
end
|
99
114
|
|
100
|
-
|
101
|
-
|
115
|
+
class MasterSlaveKeyProxy
|
116
|
+
def initialize(hash_serie, master)
|
117
|
+
@serie = hash_serie.instance
|
118
|
+
@master = master
|
119
|
+
@values = {}
|
120
|
+
@values_counter = {}
|
121
|
+
end
|
102
122
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
value = peek_values[key] if peek_values
|
123
|
+
def restart
|
124
|
+
@serie.restart
|
125
|
+
@values = {}
|
126
|
+
@values_counter = {}
|
108
127
|
end
|
109
128
|
|
110
|
-
|
111
|
-
|
112
|
-
end
|
129
|
+
def next_value(key)
|
130
|
+
return nil unless @values
|
113
131
|
|
114
|
-
|
115
|
-
def initialize(hash_serie, master)
|
116
|
-
@serie = hash_serie.instance
|
117
|
-
@master = master
|
118
|
-
@values = {}
|
119
|
-
@values_counter = {}
|
120
|
-
end
|
132
|
+
value = @values[key]
|
121
133
|
|
122
|
-
|
123
|
-
|
124
|
-
@values = {}
|
125
|
-
@values_counter = {}
|
126
|
-
end
|
134
|
+
if value.nil?
|
135
|
+
@values = @serie.next_value
|
127
136
|
|
128
|
-
|
129
|
-
return nil unless @values
|
137
|
+
value = @values[key] if @values
|
130
138
|
|
131
|
-
|
139
|
+
# warn "Info: splitted serie #{@serie} use count on next_value: #{@values_counter}"
|
140
|
+
@values_counter = {}
|
141
|
+
end
|
132
142
|
|
133
|
-
|
134
|
-
@
|
143
|
+
@values_counter[key] ||= 0
|
144
|
+
@values_counter[key] += 1
|
135
145
|
|
136
|
-
|
146
|
+
@values[key] = nil if key == @master && @values
|
137
147
|
|
138
|
-
|
139
|
-
@values_counter = {}
|
148
|
+
value
|
140
149
|
end
|
141
150
|
|
142
|
-
|
143
|
-
|
151
|
+
def peek_next_value(key)
|
152
|
+
return nil unless @values
|
144
153
|
|
145
|
-
|
146
|
-
|
147
|
-
value
|
148
|
-
end
|
154
|
+
value = @values[key]
|
149
155
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
156
|
+
if value.nil?
|
157
|
+
peek_values = @serie.peek_next_value
|
158
|
+
value = peek_values[key] if peek_values
|
159
|
+
end
|
154
160
|
|
155
|
-
|
156
|
-
peek_values = @serie.peek_next_value
|
157
|
-
value = peek_values[key] if peek_values
|
161
|
+
value
|
158
162
|
end
|
159
|
-
|
160
|
-
value
|
161
163
|
end
|
162
|
-
end
|
163
164
|
|
164
|
-
|
165
|
-
|
165
|
+
class Splitted
|
166
|
+
include Serie
|
166
167
|
|
167
|
-
|
168
|
-
|
169
|
-
|
168
|
+
def initialize(proxy, key:)
|
169
|
+
@proxy = proxy
|
170
|
+
@key = key
|
170
171
|
|
171
|
-
|
172
|
-
|
172
|
+
mark_as_instance!
|
173
|
+
end
|
173
174
|
|
174
|
-
|
175
|
-
|
176
|
-
|
175
|
+
def _prototype
|
176
|
+
raise PrototypingSerieError, 'Cannot get prototype of a splitted serie'
|
177
|
+
end
|
177
178
|
|
178
|
-
|
179
|
-
|
180
|
-
|
179
|
+
def _restart
|
180
|
+
@proxy.restart
|
181
|
+
end
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
183
|
+
def next_value
|
184
|
+
@proxy.next_value(@key)
|
185
|
+
end
|
185
186
|
|
186
|
-
|
187
|
-
|
187
|
+
def peek_next_value
|
188
|
+
@proxy.peek_next_value(@key)
|
189
|
+
end
|
188
190
|
end
|
189
191
|
end
|
190
|
-
end
|
191
192
|
|
192
|
-
|
193
|
+
private_constant :HashSplitter
|
194
|
+
end
|
193
195
|
end
|
194
196
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
-
|
1
|
+
require_relative '../core-ext/arrayfy'
|
2
|
+
|
3
|
+
using Musa::Extension::Arrayfy
|
4
|
+
using Musa::Extension::ExplodeRanges
|
2
5
|
|
3
6
|
# TODO: añadir en for: steps: (nº de pasos en los que repartir el incremento)
|
4
7
|
|
5
8
|
module Musa
|
6
9
|
module Series
|
10
|
+
extend self
|
11
|
+
|
7
12
|
def NIL
|
8
13
|
NilSerie.new
|
9
14
|
end
|
@@ -1,1151 +1,1161 @@
|
|
1
1
|
module Musa
|
2
|
-
module
|
2
|
+
module Series
|
3
|
+
module SerieOperations
|
4
|
+
def autorestart
|
5
|
+
Autorestart.new self
|
6
|
+
end
|
3
7
|
|
4
|
-
|
5
|
-
|
6
|
-
end
|
8
|
+
def repeat(times = nil, condition: nil, &condition_block)
|
9
|
+
condition ||= condition_block
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
if times || condition
|
12
|
+
Repeater.new self, times, &condition
|
13
|
+
else
|
14
|
+
InfiniteRepeater.new self
|
15
|
+
end
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
InfiniteRepeater.new self
|
18
|
+
def max_size(length)
|
19
|
+
LengthLimiter.new self, length
|
15
20
|
end
|
16
|
-
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
def skip(length)
|
23
|
+
Skipper.new self, length
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
def flatten
|
27
|
+
Flattener.new self
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
def process_with(**parameters, &processor)
|
31
|
+
Processor.new self, parameters, &processor
|
32
|
+
end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
# TODO: test case
|
35
|
+
def hashify(*keys)
|
36
|
+
HashFromSeriesArray.new self, keys
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
# TODO: test case
|
40
|
+
def shift(shift)
|
41
|
+
Shifter.new self, shift
|
42
|
+
end
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
# TODO: test case
|
45
|
+
def lock
|
46
|
+
Locker.new self
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
# TODO: test case
|
50
|
+
def reverse
|
51
|
+
Reverser.new self
|
52
|
+
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
# TODO: test case
|
55
|
+
def randomize(random: nil)
|
56
|
+
random ||= Random.new
|
57
|
+
Randomizer.new self, random
|
58
|
+
end
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
def remove(block = nil, &yield_block)
|
61
|
+
# TODO make history an optional block parameter (via keyparametersprocedurebinder)
|
62
|
+
block ||= yield_block
|
63
|
+
Remover.new self, &block
|
64
|
+
end
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
def select(block = nil, &yield_block)
|
67
|
+
# TODO add optional history (via keyparametersprocedurebinder)
|
68
|
+
block ||= yield_block
|
69
|
+
Selector.new self, &block
|
70
|
+
end
|
65
71
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
72
|
+
# TODO: test case
|
73
|
+
def switch(*indexed_series, **hash_series)
|
74
|
+
Switcher.new self, indexed_series, hash_series
|
75
|
+
end
|
71
76
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
77
|
+
def multiplex(*indexed_series, **hash_series)
|
78
|
+
MultiplexSelector.new self, indexed_series, hash_series
|
79
|
+
end
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
|
81
|
+
# TODO: test case
|
82
|
+
def switch_serie(*indexed_series, **hash_series)
|
83
|
+
SwitchFullSerie.new self, indexed_series, hash_series
|
84
|
+
end
|
80
85
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
86
|
+
def after(*series)
|
87
|
+
Sequence.new [self, *series]
|
88
|
+
end
|
85
89
|
|
86
|
-
|
87
|
-
|
88
|
-
|
90
|
+
def +(other)
|
91
|
+
Sequence.new [self, other]
|
92
|
+
end
|
89
93
|
|
90
|
-
|
91
|
-
|
92
|
-
|
94
|
+
def cut(length)
|
95
|
+
Cutter.new self, length
|
96
|
+
end
|
93
97
|
|
94
|
-
|
95
|
-
|
96
|
-
|
98
|
+
def merge
|
99
|
+
MergeSerieOfSeries.new self
|
100
|
+
end
|
97
101
|
|
98
|
-
|
99
|
-
|
100
|
-
|
102
|
+
def with(block = nil, on_restart: nil, **with_series, &yield_block)
|
103
|
+
block ||= yield_block
|
104
|
+
ProcessWith.new self, with_series, on_restart, &block
|
105
|
+
end
|
101
106
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
107
|
+
alias_method :eval, :with
|
108
|
+
|
109
|
+
def map(&yield_block)
|
110
|
+
ProcessWith.new self, &yield_block
|
111
|
+
end
|
106
112
|
|
107
|
-
|
113
|
+
# TODO: test case
|
114
|
+
def slave
|
115
|
+
slave_serie = Slave.new self
|
108
116
|
|
109
|
-
|
110
|
-
|
111
|
-
end
|
117
|
+
@_slaves ||= []
|
118
|
+
@_slaves << slave_serie
|
112
119
|
|
113
|
-
|
114
|
-
|
115
|
-
slave_serie = Slave.new self
|
120
|
+
slave_serie
|
121
|
+
end
|
116
122
|
|
117
|
-
|
118
|
-
|
123
|
+
###
|
124
|
+
### Implementation
|
125
|
+
###
|
119
126
|
|
120
|
-
|
121
|
-
|
127
|
+
class ProcessWith
|
128
|
+
include Musa::Extension::SmartProcBinder
|
129
|
+
include Serie
|
122
130
|
|
123
|
-
|
124
|
-
### Implementation
|
125
|
-
###
|
131
|
+
attr_reader :source, :with_sources, :on_restart, :block
|
126
132
|
|
127
|
-
|
128
|
-
|
133
|
+
def initialize(serie, with_series = nil, on_restart = nil, &block)
|
134
|
+
@source = serie
|
135
|
+
@with_sources = with_series || {}
|
136
|
+
@on_restart = on_restart
|
137
|
+
@block = SmartProcBinder.new(block) if block_given?
|
129
138
|
|
130
|
-
|
139
|
+
if @source.prototype?
|
140
|
+
@with_sources = @with_sources.transform_values { |s| s.prototype }
|
141
|
+
else
|
142
|
+
@with_sources = @with_sources.transform_values { |s| s.instance }
|
143
|
+
end
|
131
144
|
|
132
|
-
|
133
|
-
|
134
|
-
@with_sources = with_series || {}
|
135
|
-
@on_restart = on_restart
|
136
|
-
@block = KeyParametersProcedureBinder.new(block) if block_given?
|
145
|
+
mark_regarding! @source
|
146
|
+
end
|
137
147
|
|
138
|
-
|
148
|
+
def _prototype
|
149
|
+
@source = @source.prototype
|
139
150
|
@with_sources = @with_sources.transform_values { |s| s.prototype }
|
140
|
-
else
|
141
|
-
@with_sources = @with_sources.transform_values { |s| s.instance }
|
142
151
|
end
|
143
152
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
@source = @source.prototype
|
149
|
-
@with_sources = @with_sources.transform_values { |s| s.prototype }
|
150
|
-
end
|
151
|
-
|
152
|
-
def _instance
|
153
|
-
@source = @source.instance
|
154
|
-
@with_sources = @with_sources.transform_values { |s| s.instance }
|
155
|
-
end
|
153
|
+
def _instance
|
154
|
+
@source = @source.instance
|
155
|
+
@with_sources = @with_sources.transform_values { |s| s.instance }
|
156
|
+
end
|
156
157
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
def _restart
|
159
|
+
@source.restart
|
160
|
+
@with_sources.values.each { |s| s.restart }
|
161
|
+
@on_restart.call if @on_restart
|
162
|
+
end
|
162
163
|
|
163
|
-
|
164
|
-
|
165
|
-
|
164
|
+
def _next_value
|
165
|
+
main = @source.next_value
|
166
|
+
others = @with_sources.transform_values { |v| v.next_value }
|
166
167
|
|
167
|
-
|
168
|
+
value = nil
|
168
169
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
if main && !others.values.include?(nil)
|
171
|
+
if @block
|
172
|
+
value = @block._call([main], others)
|
173
|
+
else
|
174
|
+
value = [main, others]
|
175
|
+
end
|
174
176
|
end
|
177
|
+
|
178
|
+
value
|
175
179
|
end
|
176
180
|
|
177
|
-
|
181
|
+
def infinite?
|
182
|
+
@source.infinite? && !@with_sources.values.find { |s| !s.infinite? }
|
183
|
+
end
|
178
184
|
end
|
179
185
|
|
180
|
-
|
181
|
-
@source.infinite? && !@with_sources.values.find { |s| !s.infinite? }
|
182
|
-
end
|
183
|
-
end
|
186
|
+
private_constant :ProcessWith
|
184
187
|
|
185
|
-
|
188
|
+
class Switcher
|
189
|
+
include Serie
|
186
190
|
|
187
|
-
|
188
|
-
include Serie
|
191
|
+
attr_accessor :selector, :sources
|
189
192
|
|
190
|
-
|
193
|
+
def initialize(selector, indexed_series, hash_series)
|
191
194
|
|
192
|
-
|
195
|
+
@selector = selector
|
196
|
+
get = @selector.prototype? ? :prototype : :instance
|
193
197
|
|
194
|
-
|
195
|
-
|
198
|
+
if indexed_series && !indexed_series.empty?
|
199
|
+
@sources = indexed_series.collect(&get)
|
200
|
+
elsif hash_series && !hash_series.empty?
|
201
|
+
@sources = hash_series.clone.transform_values(&get)
|
202
|
+
end
|
196
203
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
@sources = hash_series.clone.transform_values(&get)
|
201
|
-
end
|
204
|
+
if get == :_prototype
|
205
|
+
@sources.freeze
|
206
|
+
end
|
202
207
|
|
203
|
-
|
204
|
-
@sources.freeze
|
208
|
+
mark_regarding! @selector
|
205
209
|
end
|
206
210
|
|
207
|
-
|
208
|
-
|
211
|
+
def _prototype
|
212
|
+
@selector = @selector.prototype
|
213
|
+
@sources = @sources.collect(&:prototype).freeze if @sources.is_a? Array
|
214
|
+
@sources.transform_values(&:prototype).freeze if @sources.is_a? Hash
|
215
|
+
end
|
209
216
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
217
|
+
def _instance
|
218
|
+
@selector = @selector.instance
|
219
|
+
@sources = @sources.collect(&:instance) if @sources.is_a? Array
|
220
|
+
@sources.transform_values(&:_instance) if @sources.is_a? Hash
|
221
|
+
end
|
215
222
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
223
|
+
def _restart
|
224
|
+
@selector.restart
|
225
|
+
@sources.each(&:restart) if @sources.is_a? Array
|
226
|
+
@sources.each { |_key, serie| serie.restart } if @sources.is_a? Hash
|
227
|
+
end
|
221
228
|
|
222
|
-
|
223
|
-
|
224
|
-
@sources.each(&:restart) if @sources.is_a? Array
|
225
|
-
@sources.each { |_key, serie| serie.restart } if @sources.is_a? Hash
|
226
|
-
end
|
229
|
+
def _next_value
|
230
|
+
value = nil
|
227
231
|
|
228
|
-
|
229
|
-
value = nil
|
232
|
+
index_or_key = @selector.next_value
|
230
233
|
|
231
|
-
|
234
|
+
value = @sources[index_or_key].next_value unless index_or_key.nil?
|
232
235
|
|
233
|
-
|
236
|
+
value
|
237
|
+
end
|
234
238
|
|
235
|
-
|
239
|
+
def infinite?
|
240
|
+
@selector.infinite? && @sources.any? { |serie| serie.infinite? }
|
241
|
+
end
|
236
242
|
end
|
237
243
|
|
238
|
-
|
239
|
-
@selector.infinite? && @sources.any? { |serie| serie.infinite? }
|
240
|
-
end
|
241
|
-
end
|
244
|
+
private_constant :Switcher
|
242
245
|
|
243
|
-
|
246
|
+
class MultiplexSelector
|
247
|
+
include Serie
|
244
248
|
|
245
|
-
|
246
|
-
include Serie
|
249
|
+
attr_accessor :selector, :sources
|
247
250
|
|
248
|
-
|
251
|
+
def initialize(selector, indexed_series, hash_series)
|
252
|
+
@selector = selector
|
253
|
+
get = @selector.prototype? ? :prototype : :instance
|
249
254
|
|
250
|
-
|
251
|
-
|
252
|
-
|
255
|
+
if indexed_series && !indexed_series.empty?
|
256
|
+
@sources = indexed_series.collect(&get)
|
257
|
+
elsif hash_series && !hash_series.empty?
|
258
|
+
@sources = hash_series.clone.transform_values(&get)
|
259
|
+
end
|
253
260
|
|
254
|
-
|
255
|
-
@sources = indexed_series.collect(&get)
|
256
|
-
elsif hash_series && !hash_series.empty?
|
257
|
-
@sources = hash_series.clone.transform_values(&get)
|
258
|
-
end
|
261
|
+
_restart false
|
259
262
|
|
260
|
-
|
263
|
+
if get == :_prototype
|
264
|
+
@sources.freeze
|
265
|
+
end
|
261
266
|
|
262
|
-
|
263
|
-
@sources.freeze
|
267
|
+
mark_regarding! @selector
|
264
268
|
end
|
265
269
|
|
266
|
-
|
267
|
-
|
270
|
+
def _prototype
|
271
|
+
@selector = @selector.prototype
|
272
|
+
@sources = @sources.collect(&:prototype).freeze if @sources.is_a? Array
|
273
|
+
@sources.transform_values(&:prototype).freeze if @sources.is_a? Hash
|
274
|
+
end
|
268
275
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
276
|
+
def _instance
|
277
|
+
@selector = @selector.instance
|
278
|
+
@sources = @sources.collect(&:instance) if @sources.is_a? Array
|
279
|
+
@sources.transform_values(&:_instance) if @sources.is_a? Hash
|
280
|
+
end
|
274
281
|
|
275
|
-
|
276
|
-
|
277
|
-
@sources = @sources.collect(&:instance) if @sources.is_a? Array
|
278
|
-
@sources.transform_values(&:_instance) if @sources.is_a? Hash
|
279
|
-
end
|
282
|
+
def _restart(restart_sources = true)
|
283
|
+
@current_value = nil
|
280
284
|
|
281
|
-
|
282
|
-
|
285
|
+
if restart_sources
|
286
|
+
@selector.restart
|
287
|
+
@sources.each(&:restart) if @sources.is_a? Array
|
288
|
+
@sources.each { |_key, serie| serie.restart } if @sources.is_a? Hash
|
289
|
+
end
|
283
290
|
|
284
|
-
|
285
|
-
@selector.restart
|
286
|
-
@sources.each(&:restart) if @sources.is_a? Array
|
287
|
-
@sources.each { |_key, serie| serie.restart } if @sources.is_a? Hash
|
291
|
+
@first = true
|
288
292
|
end
|
289
293
|
|
290
|
-
|
291
|
-
|
294
|
+
def _next_value
|
295
|
+
@current_value =
|
296
|
+
if @first || !@current_value.nil?
|
297
|
+
@first = false
|
298
|
+
index_or_key = @selector.next_value
|
299
|
+
unless index_or_key.nil?
|
300
|
+
@sources.each(&:next_value)
|
301
|
+
@sources[index_or_key].current_value
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
292
305
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
@first = false
|
297
|
-
index_or_key = @selector.next_value
|
298
|
-
unless index_or_key.nil?
|
299
|
-
@sources.each(&:next_value)
|
300
|
-
@sources[index_or_key].current_value
|
301
|
-
end
|
302
|
-
end
|
306
|
+
def infinite?
|
307
|
+
@selector.infinite? && @sources.any? { |serie| serie.infinite? }
|
308
|
+
end
|
303
309
|
end
|
304
310
|
|
305
|
-
|
306
|
-
@selector.infinite? && @sources.any? { |serie| serie.infinite? }
|
307
|
-
end
|
308
|
-
end
|
311
|
+
private_constant :MultiplexSelector
|
309
312
|
|
310
|
-
|
313
|
+
class SwitchFullSerie
|
314
|
+
include Serie
|
311
315
|
|
312
|
-
|
313
|
-
include Serie
|
316
|
+
attr_accessor :selector, :sources
|
314
317
|
|
315
|
-
|
318
|
+
def initialize(selector, indexed_series, hash_series)
|
319
|
+
@selector = selector
|
320
|
+
get = @selector.prototype? ? :prototype : :instance
|
316
321
|
|
317
|
-
|
318
|
-
|
319
|
-
|
322
|
+
if indexed_series && !indexed_series.empty?
|
323
|
+
@sources = indexed_series.collect(&get)
|
324
|
+
elsif hash_series && !hash_series.empty?
|
325
|
+
@sources = hash_series.clone.transform_values(&get)
|
326
|
+
end
|
320
327
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
@sources = hash_series.clone.transform_values(&get)
|
325
|
-
end
|
328
|
+
if get == :_prototype
|
329
|
+
@sources.freeze
|
330
|
+
end
|
326
331
|
|
327
|
-
|
328
|
-
@sources.freeze
|
332
|
+
mark_regarding! @selector
|
329
333
|
end
|
330
334
|
|
331
|
-
|
332
|
-
|
335
|
+
def _prototype
|
336
|
+
@selector = @selector.prototype
|
337
|
+
@sources = @sources.collect(&:prototype).freeze if @sources.is_a? Array
|
338
|
+
@sources.transform_values(&:prototype).freeze if @sources.is_a? Hash
|
339
|
+
end
|
333
340
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
341
|
+
def _instance
|
342
|
+
@selector = @selector.instance
|
343
|
+
@sources = @sources.collect(&:instance) if @sources.is_a? Array
|
344
|
+
@sources.transform_values(&:_instance) if @sources.is_a? Hash
|
345
|
+
end
|
339
346
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
end
|
347
|
+
def _restart
|
348
|
+
@selector.restart
|
349
|
+
@sources.each(&:restart)
|
350
|
+
end
|
345
351
|
|
346
|
-
|
347
|
-
|
348
|
-
@sources.each(&:restart)
|
349
|
-
end
|
352
|
+
def _next_value
|
353
|
+
value = nil
|
350
354
|
|
351
|
-
|
352
|
-
value = nil
|
355
|
+
value = @sources[@index_or_key].next_value unless @index_or_key.nil?
|
353
356
|
|
354
|
-
|
357
|
+
if value.nil?
|
358
|
+
@index_or_key = @selector.next_value
|
355
359
|
|
356
|
-
|
357
|
-
|
360
|
+
value = next_value unless @index_or_key.nil?
|
361
|
+
end
|
358
362
|
|
359
|
-
value
|
363
|
+
value
|
360
364
|
end
|
361
365
|
|
362
|
-
|
366
|
+
def infinite?
|
367
|
+
!!(@selector.infinite? || @sources.find(&:infinite?))
|
368
|
+
end
|
363
369
|
end
|
364
370
|
|
365
|
-
|
366
|
-
!!(@selector.infinite? || @sources.find(&:infinite?))
|
367
|
-
end
|
368
|
-
end
|
371
|
+
private_constant :SwitchFullSerie
|
369
372
|
|
370
|
-
|
373
|
+
class InfiniteRepeater
|
374
|
+
include Serie
|
371
375
|
|
372
|
-
|
373
|
-
include Serie
|
376
|
+
attr_reader :source
|
374
377
|
|
375
|
-
|
378
|
+
def initialize(serie)
|
379
|
+
@source = serie
|
376
380
|
|
377
|
-
|
378
|
-
|
381
|
+
mark_regarding! @source
|
382
|
+
end
|
379
383
|
|
380
|
-
|
381
|
-
|
384
|
+
def _prototype
|
385
|
+
@source = @source.prototype
|
386
|
+
end
|
382
387
|
|
383
|
-
|
384
|
-
|
385
|
-
|
388
|
+
def _instance
|
389
|
+
@source = @source.instance
|
390
|
+
end
|
386
391
|
|
387
|
-
|
388
|
-
|
389
|
-
|
392
|
+
def _restart
|
393
|
+
@source.restart
|
394
|
+
end
|
390
395
|
|
391
|
-
|
392
|
-
|
393
|
-
end
|
396
|
+
def _next_value
|
397
|
+
value = @source.next_value
|
394
398
|
|
395
|
-
|
396
|
-
|
399
|
+
if value.nil?
|
400
|
+
@source.restart
|
401
|
+
value = @source.next_value
|
402
|
+
end
|
397
403
|
|
398
|
-
|
399
|
-
@source.restart
|
400
|
-
value = @source.next_value
|
404
|
+
value
|
401
405
|
end
|
402
406
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
def infinite?
|
407
|
-
true
|
407
|
+
def infinite?
|
408
|
+
true
|
409
|
+
end
|
408
410
|
end
|
409
|
-
end
|
410
411
|
|
411
|
-
|
412
|
+
private_constant :InfiniteRepeater
|
412
413
|
|
413
|
-
|
414
|
-
|
414
|
+
class Repeater
|
415
|
+
include Serie
|
415
416
|
|
416
|
-
|
417
|
+
attr_reader :source, :times, :condition
|
417
418
|
|
418
|
-
|
419
|
-
|
419
|
+
def initialize(serie, times = nil, &condition)
|
420
|
+
@source = serie
|
420
421
|
|
421
|
-
|
422
|
-
|
422
|
+
@times = times
|
423
|
+
@external_condition = condition
|
423
424
|
|
424
|
-
|
425
|
-
|
425
|
+
_restart false
|
426
|
+
@condition = calculate_condition
|
426
427
|
|
427
|
-
|
428
|
-
|
428
|
+
mark_regarding! @source
|
429
|
+
end
|
429
430
|
|
430
|
-
|
431
|
-
|
432
|
-
|
431
|
+
def _prototype
|
432
|
+
@source = @source.prototype
|
433
|
+
@condition = calculate_condition
|
434
|
+
end
|
433
435
|
|
434
|
-
|
435
|
-
|
436
|
-
|
436
|
+
def _instance
|
437
|
+
@source = @source.instance
|
438
|
+
@condition = calculate_condition
|
439
|
+
end
|
437
440
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
441
|
+
def _restart(restart_sources = true)
|
442
|
+
@count = 0
|
443
|
+
@source.restart if restart_sources
|
444
|
+
end
|
442
445
|
|
443
|
-
|
444
|
-
|
446
|
+
def _next_value
|
447
|
+
value = @source.next_value
|
445
448
|
|
446
|
-
|
447
|
-
|
449
|
+
if value.nil?
|
450
|
+
@count += 1
|
448
451
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
+
if @condition.call
|
453
|
+
@source.restart
|
454
|
+
value = @source.next_value
|
455
|
+
end
|
452
456
|
end
|
453
|
-
end
|
454
457
|
|
455
|
-
|
456
|
-
|
458
|
+
value
|
459
|
+
end
|
457
460
|
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
+
def infinite?
|
462
|
+
@source.infinite?
|
463
|
+
end
|
461
464
|
|
462
|
-
|
465
|
+
private
|
463
466
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
+
def calculate_condition
|
468
|
+
if @external_condition
|
469
|
+
@external_condition
|
470
|
+
elsif @times
|
471
|
+
proc { @count < @times }
|
472
|
+
else
|
473
|
+
proc { false }
|
474
|
+
end
|
475
|
+
end
|
467
476
|
end
|
468
|
-
end
|
469
477
|
|
470
|
-
|
478
|
+
private_constant :Repeater
|
471
479
|
|
472
|
-
|
473
|
-
|
480
|
+
class LengthLimiter
|
481
|
+
include Serie
|
474
482
|
|
475
|
-
|
483
|
+
attr_reader :source, :length
|
476
484
|
|
477
|
-
|
478
|
-
|
479
|
-
|
485
|
+
def initialize(serie, length)
|
486
|
+
@source = serie
|
487
|
+
@length = length
|
480
488
|
|
481
|
-
|
489
|
+
_restart false
|
482
490
|
|
483
|
-
|
484
|
-
|
491
|
+
mark_regarding! @source
|
492
|
+
end
|
485
493
|
|
486
|
-
|
487
|
-
|
488
|
-
|
494
|
+
def _prototype
|
495
|
+
@source = @source.prototype
|
496
|
+
end
|
489
497
|
|
490
|
-
|
491
|
-
|
492
|
-
|
498
|
+
def _instance
|
499
|
+
@source = @source.instance
|
500
|
+
end
|
493
501
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
502
|
+
def _restart(restart_sources = true)
|
503
|
+
@position = 0
|
504
|
+
@source.restart if restart_sources
|
505
|
+
end
|
498
506
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
507
|
+
def _next_value
|
508
|
+
if @position < @length
|
509
|
+
@position += 1
|
510
|
+
@source.next_value
|
511
|
+
end
|
503
512
|
end
|
504
|
-
end
|
505
513
|
|
506
|
-
|
507
|
-
|
514
|
+
def infinite?
|
515
|
+
false
|
516
|
+
end
|
508
517
|
end
|
509
|
-
end
|
510
518
|
|
511
|
-
|
519
|
+
private_constant :LengthLimiter
|
512
520
|
|
513
|
-
|
514
|
-
|
521
|
+
class Skipper
|
522
|
+
include Serie
|
515
523
|
|
516
|
-
|
524
|
+
attr_reader :source, :length
|
517
525
|
|
518
|
-
|
519
|
-
|
520
|
-
|
526
|
+
def initialize(serie, length)
|
527
|
+
@source = serie
|
528
|
+
@length = length
|
521
529
|
|
522
|
-
|
530
|
+
_restart false
|
523
531
|
|
524
|
-
|
525
|
-
|
532
|
+
mark_regarding! @source
|
533
|
+
end
|
526
534
|
|
527
|
-
|
528
|
-
|
529
|
-
|
535
|
+
def _prototype
|
536
|
+
@source = @source.prototype
|
537
|
+
end
|
530
538
|
|
531
|
-
|
532
|
-
|
533
|
-
|
539
|
+
def _instance
|
540
|
+
@source = @source.instance
|
541
|
+
end
|
534
542
|
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
543
|
+
def _restart(restart_sources = true)
|
544
|
+
@source.restart if restart_sources
|
545
|
+
@first = true
|
546
|
+
end
|
539
547
|
|
540
|
-
|
541
|
-
|
542
|
-
|
548
|
+
def _next_value
|
549
|
+
@length.times { @source.next_value } if @first
|
550
|
+
@first = nil
|
543
551
|
|
544
|
-
|
545
|
-
|
552
|
+
@source.next_value
|
553
|
+
end
|
546
554
|
|
547
|
-
|
548
|
-
|
555
|
+
def infinite?
|
556
|
+
@source.infinite?
|
557
|
+
end
|
549
558
|
end
|
550
|
-
end
|
551
|
-
|
552
|
-
private_constant :Skipper
|
553
559
|
|
554
|
-
|
555
|
-
include Serie
|
560
|
+
private_constant :Skipper
|
556
561
|
|
557
|
-
|
558
|
-
|
559
|
-
def initialize(serie)
|
560
|
-
@source = serie
|
562
|
+
class Flattener
|
563
|
+
include Serie
|
561
564
|
|
562
|
-
|
565
|
+
attr_reader :source
|
563
566
|
|
564
|
-
|
565
|
-
|
567
|
+
def initialize(serie)
|
568
|
+
@source = serie
|
566
569
|
|
567
|
-
|
568
|
-
@source = @source.prototype
|
569
|
-
_restart false
|
570
|
-
end
|
570
|
+
_restart false
|
571
571
|
|
572
|
-
|
573
|
-
|
574
|
-
_restart false
|
575
|
-
end
|
572
|
+
mark_regarding! @source
|
573
|
+
end
|
576
574
|
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
@restart_each_serie = true
|
581
|
-
else
|
582
|
-
@restart_each_serie = false
|
575
|
+
def _prototype
|
576
|
+
@source = @source.prototype
|
577
|
+
_restart false
|
583
578
|
end
|
584
579
|
|
585
|
-
|
586
|
-
|
580
|
+
def _instance
|
581
|
+
@source = @source.instance
|
582
|
+
_restart false
|
583
|
+
end
|
587
584
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
case value
|
593
|
-
when Serie
|
594
|
-
value = value.instance
|
595
|
-
value.restart if @restart_each_serie
|
596
|
-
@stack.push(value)
|
597
|
-
_next_value
|
598
|
-
when nil
|
599
|
-
@stack.pop
|
600
|
-
_next_value
|
585
|
+
def _restart(restart_sources = true)
|
586
|
+
if restart_sources
|
587
|
+
@source.restart
|
588
|
+
@restart_each_serie = true
|
601
589
|
else
|
602
|
-
|
590
|
+
@restart_each_serie = false
|
591
|
+
end
|
592
|
+
|
593
|
+
@stack = [@source]
|
594
|
+
end
|
595
|
+
|
596
|
+
def _next_value
|
597
|
+
if @stack.last
|
598
|
+
value = @stack.last.next_value
|
599
|
+
|
600
|
+
case value
|
601
|
+
when Serie
|
602
|
+
value = value.instance
|
603
|
+
value.restart if @restart_each_serie
|
604
|
+
@stack.push(value)
|
605
|
+
_next_value
|
606
|
+
when nil
|
607
|
+
@stack.pop
|
608
|
+
_next_value
|
609
|
+
else
|
610
|
+
value
|
611
|
+
end
|
603
612
|
end
|
604
613
|
end
|
605
|
-
end
|
606
614
|
|
607
|
-
|
608
|
-
|
615
|
+
def infinite?
|
616
|
+
@source.infinite? # TODO revisar porque las series hijas sí que pueden ser infinitas
|
617
|
+
end
|
609
618
|
end
|
610
|
-
end
|
611
619
|
|
612
|
-
|
620
|
+
private_constant :Flattener
|
613
621
|
|
614
|
-
|
615
|
-
|
622
|
+
class MergeSerieOfSeries
|
623
|
+
include Serie
|
616
624
|
|
617
|
-
|
625
|
+
attr_reader :source
|
618
626
|
|
619
|
-
|
620
|
-
|
621
|
-
|
627
|
+
def initialize(serie)
|
628
|
+
@source = serie
|
629
|
+
_restart false
|
622
630
|
|
623
|
-
|
624
|
-
|
631
|
+
mark_regarding! @source
|
632
|
+
end
|
625
633
|
|
626
|
-
|
627
|
-
|
628
|
-
|
634
|
+
def _prototype
|
635
|
+
@source = @source.prototype
|
636
|
+
end
|
629
637
|
|
630
|
-
|
631
|
-
|
632
|
-
|
638
|
+
def _instance
|
639
|
+
@source = @source.instance
|
640
|
+
end
|
633
641
|
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
642
|
+
def _restart(restart_sources = true)
|
643
|
+
if restart_sources
|
644
|
+
@source.restart
|
645
|
+
@restart_each_serie = true
|
646
|
+
end
|
647
|
+
@current_serie = nil
|
638
648
|
end
|
639
|
-
@current_serie = nil
|
640
|
-
end
|
641
649
|
|
642
|
-
|
643
|
-
|
650
|
+
def _next_value
|
651
|
+
value = nil
|
644
652
|
|
645
|
-
|
653
|
+
restart_current_serie_if_needed = false
|
646
654
|
|
647
|
-
|
648
|
-
|
649
|
-
|
655
|
+
if @current_serie.nil?
|
656
|
+
@current_serie = @source.next_value
|
657
|
+
@current_serie = @current_serie.instance if @current_serie
|
650
658
|
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
659
|
+
if @restart_each_serie
|
660
|
+
@current_serie.restart if @current_serie
|
661
|
+
else
|
662
|
+
restart_current_serie_if_needed = true
|
663
|
+
end
|
655
664
|
end
|
656
|
-
end
|
657
665
|
|
658
|
-
|
659
|
-
|
666
|
+
if @current_serie
|
667
|
+
value = @current_serie.next_value
|
660
668
|
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
669
|
+
if value.nil?
|
670
|
+
if restart_current_serie_if_needed
|
671
|
+
@current_serie.restart
|
672
|
+
else
|
673
|
+
@current_serie = nil
|
674
|
+
end
|
667
675
|
|
668
|
-
|
676
|
+
value = _next_value
|
677
|
+
end
|
669
678
|
end
|
670
|
-
end
|
671
679
|
|
672
|
-
|
680
|
+
value
|
681
|
+
end
|
673
682
|
end
|
674
|
-
end
|
675
683
|
|
676
|
-
|
684
|
+
private_constant :MergeSerieOfSeries
|
677
685
|
|
678
|
-
|
679
|
-
|
686
|
+
class Processor
|
687
|
+
include Musa::Extension::SmartProcBinder
|
688
|
+
include Serie
|
680
689
|
|
681
|
-
|
690
|
+
attr_reader :source
|
682
691
|
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
692
|
+
def initialize(serie, parameters, &processor)
|
693
|
+
@source = serie
|
694
|
+
@parameters = parameters
|
695
|
+
@processor = SmartProcBinder.new(processor)
|
687
696
|
|
688
|
-
|
697
|
+
_restart false
|
689
698
|
|
690
|
-
|
691
|
-
|
699
|
+
mark_regarding! @source
|
700
|
+
end
|
692
701
|
|
693
|
-
|
694
|
-
|
695
|
-
|
702
|
+
def _prototype
|
703
|
+
@source = @source.prototype
|
704
|
+
end
|
696
705
|
|
697
|
-
|
698
|
-
|
699
|
-
|
706
|
+
def _instance
|
707
|
+
@source = @source.instance
|
708
|
+
end
|
700
709
|
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
710
|
+
def _restart(restart_source = true)
|
711
|
+
@source.restart if restart_source
|
712
|
+
@pending_values = []
|
713
|
+
end
|
705
714
|
|
706
|
-
|
707
|
-
|
715
|
+
def _next_value
|
716
|
+
if @pending_values.empty?
|
708
717
|
|
709
|
-
|
718
|
+
v = @source.next_value
|
710
719
|
|
711
|
-
|
712
|
-
|
720
|
+
if v.nil?
|
721
|
+
nil
|
722
|
+
else
|
723
|
+
value = @processor.call(v, **@parameters)
|
724
|
+
|
725
|
+
if value.is_a?(Array)
|
726
|
+
@pending_values = value
|
727
|
+
value = _next_value
|
728
|
+
end
|
729
|
+
|
730
|
+
value
|
731
|
+
end
|
713
732
|
else
|
714
|
-
value = @
|
733
|
+
value = @pending_values.shift
|
715
734
|
|
716
|
-
if value.
|
717
|
-
@pending_values = value
|
735
|
+
if value.nil?
|
718
736
|
value = _next_value
|
719
737
|
end
|
720
738
|
|
721
739
|
value
|
722
740
|
end
|
723
|
-
else
|
724
|
-
value = @pending_values.shift
|
725
|
-
|
726
|
-
if value.nil?
|
727
|
-
value = _next_value
|
728
|
-
end
|
729
|
-
|
730
|
-
value
|
731
741
|
end
|
732
|
-
end
|
733
742
|
|
734
|
-
|
735
|
-
|
743
|
+
def infinite?
|
744
|
+
@source.infinite?
|
745
|
+
end
|
736
746
|
end
|
737
|
-
end
|
738
|
-
|
739
|
-
class Autorestart
|
740
|
-
include Serie
|
741
747
|
|
742
|
-
|
748
|
+
class Autorestart
|
749
|
+
include Serie
|
743
750
|
|
744
|
-
|
745
|
-
@source = serie
|
751
|
+
attr_reader :source
|
746
752
|
|
747
|
-
|
753
|
+
def initialize(serie)
|
754
|
+
@source = serie
|
748
755
|
|
749
|
-
|
750
|
-
end
|
756
|
+
@restart_on_next = false
|
751
757
|
|
752
|
-
|
753
|
-
|
754
|
-
end
|
758
|
+
mark_regarding! @source
|
759
|
+
end
|
755
760
|
|
756
|
-
|
757
|
-
|
758
|
-
|
761
|
+
def _prototype
|
762
|
+
@source = @source.prototype
|
763
|
+
end
|
759
764
|
|
760
|
-
|
761
|
-
|
762
|
-
|
765
|
+
def _instance
|
766
|
+
@source = @source.instance
|
767
|
+
end
|
763
768
|
|
764
|
-
|
765
|
-
if @restart_on_next
|
769
|
+
def _restart
|
766
770
|
@source.restart
|
767
|
-
@restart_on_next = false
|
768
771
|
end
|
769
772
|
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
end
|
776
|
-
end
|
777
|
-
|
778
|
-
private_constant :Autorestart
|
779
|
-
|
780
|
-
class Cutter
|
781
|
-
include Serie
|
782
|
-
|
783
|
-
attr_reader :source, :length
|
784
|
-
|
785
|
-
def initialize(serie, length)
|
786
|
-
@source = serie
|
787
|
-
@length = length
|
788
|
-
|
789
|
-
mark_regarding! @source
|
790
|
-
end
|
791
|
-
|
792
|
-
def _prototype
|
793
|
-
@source = @source.prototype
|
794
|
-
end
|
795
|
-
|
796
|
-
def _instance
|
797
|
-
@source = @source.instance
|
798
|
-
end
|
773
|
+
def _next_value
|
774
|
+
if @restart_on_next
|
775
|
+
@source.restart
|
776
|
+
@restart_on_next = false
|
777
|
+
end
|
799
778
|
|
800
|
-
|
801
|
-
@source.restart
|
802
|
-
end
|
779
|
+
value = @source.next_value
|
803
780
|
|
804
|
-
|
805
|
-
@previous.materialize if @previous
|
781
|
+
@restart_on_next = value.nil?
|
806
782
|
|
807
|
-
|
783
|
+
value
|
784
|
+
end
|
808
785
|
end
|
809
786
|
|
810
|
-
|
787
|
+
private_constant :Autorestart
|
811
788
|
|
812
|
-
class
|
789
|
+
class Cutter
|
813
790
|
include Serie
|
814
791
|
|
792
|
+
attr_reader :source, :length
|
793
|
+
|
815
794
|
def initialize(serie, length)
|
816
795
|
@source = serie
|
817
796
|
@length = length
|
818
797
|
|
819
|
-
@
|
820
|
-
_restart
|
821
|
-
|
822
|
-
mark_as_instance!
|
798
|
+
mark_regarding! @source
|
823
799
|
end
|
824
800
|
|
825
801
|
def _prototype
|
826
|
-
|
802
|
+
@source = @source.prototype
|
803
|
+
end
|
804
|
+
|
805
|
+
def _instance
|
806
|
+
@source = @source.instance
|
827
807
|
end
|
828
808
|
|
829
809
|
def _restart
|
830
|
-
@
|
810
|
+
@source.restart
|
831
811
|
end
|
832
812
|
|
833
813
|
def _next_value
|
834
|
-
|
835
|
-
value ||= @values[@count] = @source.next_value if @count < @length
|
814
|
+
@previous.materialize if @previous
|
836
815
|
|
837
|
-
@
|
838
|
-
|
839
|
-
value
|
816
|
+
@previous = CutSerie.new @source, @length if @source.peek_next_value
|
840
817
|
end
|
841
818
|
|
842
|
-
|
843
|
-
|
819
|
+
private
|
820
|
+
|
821
|
+
class CutSerie
|
822
|
+
include Serie
|
823
|
+
|
824
|
+
def initialize(serie, length)
|
825
|
+
@source = serie
|
826
|
+
@length = length
|
827
|
+
|
828
|
+
@values = []
|
829
|
+
_restart
|
830
|
+
|
831
|
+
mark_as_instance!
|
832
|
+
end
|
833
|
+
|
834
|
+
def _prototype
|
835
|
+
raise PrototypingSerieError, 'Cannot get prototype of a cut serie'
|
836
|
+
end
|
837
|
+
|
838
|
+
def _restart
|
839
|
+
@count = 0
|
840
|
+
end
|
841
|
+
|
842
|
+
def _next_value
|
843
|
+
value ||= @values[@count]
|
844
|
+
value ||= @values[@count] = @source.next_value if @count < @length
|
845
|
+
|
846
|
+
@count += 1
|
847
|
+
|
848
|
+
value
|
849
|
+
end
|
850
|
+
|
851
|
+
def materialize
|
852
|
+
(@values.size..@length - 1).each { |i| @values[i] = @source.next_value }
|
853
|
+
end
|
844
854
|
end
|
845
855
|
end
|
846
|
-
end
|
847
856
|
|
848
|
-
|
857
|
+
private_constant :Cutter
|
849
858
|
|
850
|
-
|
851
|
-
|
859
|
+
class Locker
|
860
|
+
include Serie
|
852
861
|
|
853
|
-
|
862
|
+
attr_reader :source
|
854
863
|
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
864
|
+
def initialize(serie)
|
865
|
+
@source = serie
|
866
|
+
@values = []
|
867
|
+
@first_round = true
|
859
868
|
|
860
|
-
|
869
|
+
_restart
|
861
870
|
|
862
|
-
|
863
|
-
|
871
|
+
mark_regarding! @source
|
872
|
+
end
|
864
873
|
|
865
|
-
|
866
|
-
|
867
|
-
|
874
|
+
def _prototype
|
875
|
+
@source = @source.prototype
|
876
|
+
end
|
868
877
|
|
869
|
-
|
870
|
-
|
871
|
-
|
878
|
+
def _instance
|
879
|
+
@source = @source.instance
|
880
|
+
end
|
872
881
|
|
873
|
-
|
874
|
-
|
875
|
-
|
882
|
+
def _restart
|
883
|
+
@index = 0
|
884
|
+
end
|
876
885
|
|
877
|
-
|
878
|
-
|
879
|
-
|
886
|
+
def _next_value
|
887
|
+
if @first_round
|
888
|
+
value = @source.next_value
|
880
889
|
|
881
|
-
|
882
|
-
|
883
|
-
else
|
884
|
-
if @index < @values.size
|
885
|
-
value = @values[@index]
|
886
|
-
@index += 1
|
890
|
+
@first_round = false if value.nil?
|
891
|
+
@values << value unless value.nil?
|
887
892
|
else
|
888
|
-
|
893
|
+
if @index < @values.size
|
894
|
+
value = @values[@index]
|
895
|
+
@index += 1
|
896
|
+
else
|
897
|
+
value = nil
|
898
|
+
end
|
889
899
|
end
|
890
|
-
end
|
891
900
|
|
892
|
-
|
901
|
+
value
|
902
|
+
end
|
893
903
|
end
|
894
|
-
end
|
895
904
|
|
896
|
-
|
905
|
+
private_constant :Locker
|
897
906
|
|
898
|
-
|
899
|
-
|
907
|
+
class Reverser
|
908
|
+
include Serie
|
900
909
|
|
901
|
-
|
910
|
+
attr_reader :source
|
902
911
|
|
903
|
-
|
904
|
-
|
905
|
-
|
912
|
+
def initialize(serie)
|
913
|
+
@source = serie
|
914
|
+
_restart false, false
|
906
915
|
|
907
|
-
|
908
|
-
|
916
|
+
mark_regarding! @source
|
917
|
+
end
|
909
918
|
|
910
|
-
|
911
|
-
|
912
|
-
|
919
|
+
def _prototype
|
920
|
+
@source = @source.prototype
|
921
|
+
end
|
913
922
|
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
923
|
+
def _instance
|
924
|
+
@source = @source.instance
|
925
|
+
_restart false, true
|
926
|
+
end
|
918
927
|
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
928
|
+
def _restart(restart_sources = true, get_reversed = true)
|
929
|
+
@source.restart if restart_sources
|
930
|
+
@reversed = FromArray.new(next_values_array_of(@source).reverse).instance if get_reversed
|
931
|
+
end
|
923
932
|
|
924
|
-
|
925
|
-
|
926
|
-
|
933
|
+
def _next_value
|
934
|
+
@reversed.next_value
|
935
|
+
end
|
927
936
|
|
928
|
-
|
937
|
+
private
|
929
938
|
|
930
|
-
|
931
|
-
|
939
|
+
def next_values_array_of(serie)
|
940
|
+
array = []
|
932
941
|
|
933
|
-
|
934
|
-
|
935
|
-
|
942
|
+
until (value = serie.next_value).nil?
|
943
|
+
array << value
|
944
|
+
end
|
936
945
|
|
937
|
-
|
946
|
+
array
|
947
|
+
end
|
938
948
|
end
|
939
|
-
end
|
940
949
|
|
941
|
-
|
950
|
+
private_constant :Reverser
|
942
951
|
|
943
|
-
|
944
|
-
|
952
|
+
class Randomizer
|
953
|
+
include Serie
|
945
954
|
|
946
|
-
|
955
|
+
attr_reader :source, :random
|
947
956
|
|
948
|
-
|
949
|
-
|
950
|
-
|
957
|
+
def initialize(serie, random)
|
958
|
+
@source = serie
|
959
|
+
@random = random
|
951
960
|
|
952
|
-
|
961
|
+
_restart false
|
953
962
|
|
954
|
-
|
955
|
-
|
963
|
+
mark_regarding! @source
|
964
|
+
end
|
956
965
|
|
957
|
-
|
958
|
-
|
959
|
-
|
966
|
+
def _prototype
|
967
|
+
@source = @source.prototype
|
968
|
+
end
|
960
969
|
|
961
|
-
|
962
|
-
|
963
|
-
|
970
|
+
def _instance
|
971
|
+
@source = @source.instance
|
972
|
+
end
|
964
973
|
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
974
|
+
def _restart(restart_sources = true)
|
975
|
+
@source.restart if restart_sources
|
976
|
+
@values = @source.to_a
|
977
|
+
end
|
969
978
|
|
970
|
-
|
971
|
-
|
979
|
+
def _next_value
|
980
|
+
_restart(false) if @needs_restart
|
972
981
|
|
973
|
-
|
974
|
-
|
975
|
-
|
982
|
+
if !@values.empty?
|
983
|
+
position = @random.rand(0...@values.size)
|
984
|
+
value = @values[position]
|
976
985
|
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
986
|
+
@values.delete_at position
|
987
|
+
else
|
988
|
+
value = nil
|
989
|
+
end
|
981
990
|
|
982
|
-
|
991
|
+
value
|
992
|
+
end
|
983
993
|
end
|
984
|
-
end
|
985
994
|
|
986
|
-
|
995
|
+
private_constant :Randomizer
|
987
996
|
|
988
|
-
|
989
|
-
|
997
|
+
class Shifter
|
998
|
+
include Serie
|
990
999
|
|
991
|
-
|
1000
|
+
attr_reader :source, :shift
|
992
1001
|
|
993
|
-
|
994
|
-
|
995
|
-
|
1002
|
+
def initialize(serie, shift)
|
1003
|
+
raise ArgumentError, "cannot shift to right an infinite serie #{serie}" if shift > 0 && serie.infinite?
|
1004
|
+
raise ArgumentError, 'cannot shift to right: function not yet implemented' if shift > 0
|
996
1005
|
|
997
|
-
|
998
|
-
|
1006
|
+
@source = serie
|
1007
|
+
@shift = shift
|
999
1008
|
|
1000
|
-
|
1009
|
+
_restart false
|
1001
1010
|
|
1002
|
-
|
1003
|
-
|
1011
|
+
mark_regarding! @source
|
1012
|
+
end
|
1004
1013
|
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1014
|
+
def _prototype
|
1015
|
+
@source = @source.prototype
|
1016
|
+
end
|
1008
1017
|
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1018
|
+
def _instance
|
1019
|
+
@source = @source.instance
|
1020
|
+
end
|
1012
1021
|
|
1013
|
-
|
1014
|
-
|
1022
|
+
def _restart(restart_sources = true)
|
1023
|
+
@source.restart if restart_sources
|
1015
1024
|
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1025
|
+
@shifted = []
|
1026
|
+
@shift.abs.times { @shifted << @source.next_value } if @shift < 0
|
1027
|
+
end
|
1019
1028
|
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1029
|
+
def _next_value
|
1030
|
+
value = @source.next_value
|
1031
|
+
return value unless value.nil?
|
1023
1032
|
|
1024
|
-
|
1033
|
+
@shifted.shift
|
1034
|
+
end
|
1025
1035
|
end
|
1026
|
-
end
|
1027
1036
|
|
1028
|
-
|
1037
|
+
private_constant :Shifter
|
1029
1038
|
|
1030
|
-
|
1031
|
-
|
1039
|
+
class Remover
|
1040
|
+
include Serie
|
1032
1041
|
|
1033
|
-
|
1042
|
+
attr_reader :source
|
1034
1043
|
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1044
|
+
def initialize(serie, &block)
|
1045
|
+
@source = serie
|
1046
|
+
@block = block
|
1047
|
+
@history = []
|
1039
1048
|
|
1040
|
-
|
1049
|
+
_restart false
|
1041
1050
|
|
1042
|
-
|
1043
|
-
|
1051
|
+
mark_regarding! @source
|
1052
|
+
end
|
1044
1053
|
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1054
|
+
def _prototype
|
1055
|
+
@source = @source.prototype
|
1056
|
+
end
|
1048
1057
|
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1058
|
+
def _instance
|
1059
|
+
@source = @source.instance
|
1060
|
+
end
|
1052
1061
|
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1062
|
+
def _restart(restart_sources = true)
|
1063
|
+
@source.restart if restart_sources
|
1064
|
+
@history.clear
|
1065
|
+
end
|
1057
1066
|
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1067
|
+
def _next_value
|
1068
|
+
if value = @source.next_value
|
1069
|
+
while @block.call(value, @history)
|
1070
|
+
@history << value
|
1071
|
+
value = @source.next_value
|
1072
|
+
end
|
1061
1073
|
@history << value
|
1062
|
-
value = @source.next_value
|
1063
1074
|
end
|
1064
|
-
|
1075
|
+
value
|
1065
1076
|
end
|
1066
|
-
value
|
1067
1077
|
end
|
1068
|
-
end
|
1069
1078
|
|
1070
|
-
|
1079
|
+
private_constant :Remover
|
1071
1080
|
|
1072
|
-
|
1073
|
-
|
1081
|
+
class Selector
|
1082
|
+
include Serie
|
1074
1083
|
|
1075
|
-
|
1084
|
+
attr_reader :source
|
1076
1085
|
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1086
|
+
def initialize(serie, &block)
|
1087
|
+
@source = serie
|
1088
|
+
@block = block
|
1080
1089
|
|
1081
|
-
|
1090
|
+
_restart false
|
1082
1091
|
|
1083
|
-
|
1084
|
-
|
1092
|
+
mark_regarding! @source
|
1093
|
+
end
|
1085
1094
|
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1095
|
+
def _prototype
|
1096
|
+
@source = @source.prototype
|
1097
|
+
end
|
1089
1098
|
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1099
|
+
def _instance
|
1100
|
+
@source = @source.instance
|
1101
|
+
end
|
1093
1102
|
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1103
|
+
def _restart(restart_sources = true)
|
1104
|
+
@source.restart if restart_sources
|
1105
|
+
end
|
1097
1106
|
|
1098
|
-
|
1099
|
-
value = @source.next_value
|
1100
|
-
until value.nil? || @block.call(value)
|
1107
|
+
def _next_value
|
1101
1108
|
value = @source.next_value
|
1109
|
+
until value.nil? || @block.call(value)
|
1110
|
+
value = @source.next_value
|
1111
|
+
end
|
1112
|
+
value
|
1102
1113
|
end
|
1103
|
-
value
|
1104
1114
|
end
|
1105
|
-
end
|
1106
1115
|
|
1107
|
-
|
1116
|
+
private_constant :Selector
|
1108
1117
|
|
1109
|
-
|
1110
|
-
|
1118
|
+
class HashFromSeriesArray
|
1119
|
+
include Serie
|
1111
1120
|
|
1112
|
-
|
1121
|
+
attr_reader :source, :keys
|
1113
1122
|
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1123
|
+
def initialize(serie, keys)
|
1124
|
+
@source = serie
|
1125
|
+
@keys = keys
|
1126
|
+
_restart false
|
1118
1127
|
|
1119
|
-
|
1120
|
-
|
1128
|
+
mark_regarding! @source
|
1129
|
+
end
|
1121
1130
|
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1131
|
+
def _prototype
|
1132
|
+
@source = @source.prototype
|
1133
|
+
end
|
1125
1134
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1135
|
+
def _instance
|
1136
|
+
@source = @source.instance
|
1137
|
+
end
|
1129
1138
|
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1139
|
+
def _restart(restart_sources = true)
|
1140
|
+
@source.restart if restart_sources
|
1141
|
+
end
|
1133
1142
|
|
1134
|
-
|
1135
|
-
|
1143
|
+
def _next_value
|
1144
|
+
array = @source.next_value
|
1136
1145
|
|
1137
|
-
|
1146
|
+
return nil unless array
|
1138
1147
|
|
1139
|
-
|
1148
|
+
value = array.length.times.collect { |i| [@keys[i], array[i]] }.to_h
|
1140
1149
|
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1150
|
+
if value.find { |_key, value| value.nil? }
|
1151
|
+
nil
|
1152
|
+
else
|
1153
|
+
value
|
1154
|
+
end
|
1145
1155
|
end
|
1146
1156
|
end
|
1147
|
-
end
|
1148
1157
|
|
1149
|
-
|
1158
|
+
private_constant :HashFromSeriesArray
|
1159
|
+
end
|
1150
1160
|
end
|
1151
1161
|
end
|