when_exe 0.3.7 → 0.3.8
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/README.md +210 -171
- data/bin/irb.rc +1 -0
- data/lib/when_exe.rb +78 -53
- data/lib/when_exe/basictypes.rb +27 -8
- data/lib/when_exe/calendarnote.rb +848 -805
- data/lib/when_exe/calendartypes.rb +110 -240
- data/lib/when_exe/coordinates.rb +2440 -2175
- data/lib/when_exe/core/compatibility.rb +1 -1
- data/lib/when_exe/core/duration.rb +13 -11
- data/lib/when_exe/core/extension.rb +38 -45
- data/lib/when_exe/ephemeris.rb +43 -14
- data/lib/when_exe/ephemeris/eclipse.rb +149 -0
- data/lib/when_exe/ephemeris/notes.rb +39 -7
- data/lib/when_exe/icalendar.rb +2 -6
- data/lib/when_exe/inspect.rb +1408 -1399
- data/lib/when_exe/parts/enumerator.rb +486 -477
- data/lib/when_exe/parts/resource.rb +1101 -1069
- data/lib/when_exe/parts/timezone.rb +6 -5
- data/lib/when_exe/region/babylonian.rb +405 -405
- data/lib/when_exe/region/bahai.rb +21 -61
- data/lib/when_exe/region/chinese/epochs.rb +81 -81
- data/lib/when_exe/region/chinese/twins.rb +51 -51
- data/lib/when_exe/region/christian.rb +7 -2
- data/lib/when_exe/region/coptic.rb +1 -1
- data/lib/when_exe/region/discordian.rb +9 -16
- data/lib/when_exe/region/french.rb +1 -1
- data/lib/when_exe/region/hanke_henry.rb +57 -0
- data/lib/when_exe/region/indian.rb +41 -73
- data/lib/when_exe/region/international_fixed.rb +97 -0
- data/lib/when_exe/region/iranian.rb +203 -203
- data/lib/when_exe/region/japanese.rb +13 -13
- data/lib/when_exe/region/japanese/eclipses.rb +1194 -0
- data/lib/when_exe/region/japanese/notes.rb +1482 -1383
- data/lib/when_exe/region/japanese/residues.rb +726 -721
- data/lib/when_exe/region/japanese/twins.rb +37 -37
- data/lib/when_exe/region/jewish.rb +2 -2
- data/lib/when_exe/region/pax.rb +60 -0
- data/lib/when_exe/region/positivist.rb +100 -0
- data/lib/when_exe/region/roman.rb +333 -334
- data/lib/when_exe/region/shire.rb +3 -20
- data/lib/when_exe/region/thai.rb +2 -2
- data/lib/when_exe/region/tibetan.rb +3 -3
- data/lib/when_exe/region/tranquility.rb +208 -0
- data/lib/when_exe/region/vanishing_leprechaun.rb +53 -0
- data/lib/when_exe/region/vietnamese.rb +4 -4
- data/lib/when_exe/region/world.rb +9 -13
- data/lib/when_exe/region/world_season.rb +89 -0
- data/lib/when_exe/region/zoroastrian.rb +4 -2
- data/lib/when_exe/tmobjects.rb +14 -4
- data/lib/when_exe/tmposition.rb +239 -81
- data/lib/when_exe/tmreference.rb +57 -28
- data/lib/when_exe/version.rb +1 -1
- data/link_to_online_documents +6 -3
- data/test/examples/today.rb +1 -1
- data/test/scripts.rb +23 -0
- data/test/scripts/2.ext.rb +169 -0
- data/test/scripts/2.rb +169 -0
- data/test/scripts/3.ext.rb +133 -0
- data/test/scripts/3.rb +134 -0
- data/test/scripts/4.ext.rb +112 -0
- data/test/scripts/4.min.rb +65 -0
- data/test/scripts/4.rb +136 -0
- data/test/scripts/5.ext.rb +78 -0
- data/test/scripts/5.rb +81 -0
- data/test/scripts/6.gcal.rb +131 -0
- data/test/scripts/6.rb +205 -0
- data/test/scripts/6.tz.rb +105 -0
- data/test/scripts/7.phase.rb +109 -0
- data/test/scripts/7.rb +95 -0
- data/test/scripts/7.term.rb +128 -0
- data/test/scripts/7.week.rb +84 -0
- data/test/scripts/8.ext.rb +61 -0
- data/test/scripts/8.rb +62 -0
- data/test/scripts/9.ext.rb +131 -0
- data/test/scripts/9.rb +130 -0
- data/test/scripts/chinese-luni-solar.rb +52 -0
- data/test/{examples → scripts}/geometric_complex.rb +41 -41
- data/test/scripts/geometric_complex.txt +18 -0
- data/test/scripts/korea.rb +59 -0
- data/test/scripts/thai-reviewed.txt +211 -0
- data/test/scripts/thai.rb +36 -0
- data/test/scripts/thai.txt +210 -0
- data/test/test.rb +7 -0
- data/test/test/basictypes.rb +22 -0
- data/test/test/coordinates.rb +2 -1
- data/test/test/ephemeris.rb +34 -2
- data/test/test/icalendar.rb +12 -0
- data/test/test/inspect.rb +37 -1
- data/test/test/parts.rb +4 -3
- data/test/test/region/armenian.rb +20 -0
- data/test/test/region/bahai.rb +58 -0
- data/test/test/region/chinese.rb +14 -3
- data/test/test/region/christian.rb +16 -35
- data/test/test/region/discordian.rb +20 -0
- data/test/test/region/indian.rb +30 -2
- data/test/test/region/japanese.rb +24 -0
- data/test/test/region/jewish.rb +2 -0
- data/test/test/region/m17n.rb +9 -0
- data/test/test/region/reforms.rb +121 -0
- data/test/test/region/residue.rb +17 -11
- data/test/test/region/shire.rb +58 -0
- data/test/test/region/swedish.rb +45 -0
- data/test/test/region/zoroastrian.rb +58 -0
- data/test/test/tmobjects.rb +74 -0
- data/test/test/tmposition.rb +468 -397
- data/when_exe.gemspec +2 -2
- metadata +49 -6
|
@@ -1,477 +1,486 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
=begin
|
|
3
|
-
Copyright (C) 2011-2014 Takashi SUGA
|
|
4
|
-
|
|
5
|
-
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
|
6
|
-
=end
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
# 本ライブラリのための諸々の部品
|
|
10
|
-
#
|
|
11
|
-
module When::Parts
|
|
12
|
-
|
|
13
|
-
#
|
|
14
|
-
# v1.8.x のための互換性確保用
|
|
15
|
-
#
|
|
16
|
-
# @private
|
|
17
|
-
class Enumerator < ::Enumerator ; end if Object.const_defined?(:Enumerator)
|
|
18
|
-
|
|
19
|
-
#
|
|
20
|
-
# 本ライブラリ用の Enumerator の雛形
|
|
21
|
-
#
|
|
22
|
-
class Enumerator
|
|
23
|
-
|
|
24
|
-
# @private
|
|
25
|
-
def self._options(args)
|
|
26
|
-
options = args[-1].kind_of?(Hash) ? args.pop.dup : {}
|
|
27
|
-
options[:exdate] =
|
|
28
|
-
case options[:exdate]
|
|
29
|
-
when GeometricComplex ; options[:exdate].dup
|
|
30
|
-
when nil ; GeometricComplex.new()
|
|
31
|
-
else ; GeometricComplex.new(options[:exdate])
|
|
32
|
-
end
|
|
33
|
-
return options
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# 生成元オブジェクト
|
|
37
|
-
# @return [Comparable]
|
|
38
|
-
attr_reader :parent
|
|
39
|
-
|
|
40
|
-
# オプション
|
|
41
|
-
# @return [Hash]
|
|
42
|
-
# @private
|
|
43
|
-
attr_accessor :options
|
|
44
|
-
protected :options=
|
|
45
|
-
|
|
46
|
-
# 除外要素
|
|
47
|
-
# @return [When::Parts::GeometricComplex]
|
|
48
|
-
attr_accessor :exdate
|
|
49
|
-
protected :exdate=
|
|
50
|
-
|
|
51
|
-
# 処理済み要素
|
|
52
|
-
# @return [When::Parts::GeometricComplex]
|
|
53
|
-
attr_accessor :processed
|
|
54
|
-
protected :processed=
|
|
55
|
-
|
|
56
|
-
# 最初の要素
|
|
57
|
-
# @return [Comparable]
|
|
58
|
-
attr_accessor :first
|
|
59
|
-
protected :first=
|
|
60
|
-
|
|
61
|
-
# 最後の要素
|
|
62
|
-
# @return [Comparable]
|
|
63
|
-
attr_accessor :last
|
|
64
|
-
protected :last=
|
|
65
|
-
|
|
66
|
-
# 繰り返し方向
|
|
67
|
-
# @return [Symbol]
|
|
68
|
-
# [ :forward - 昇順 ]
|
|
69
|
-
# [ :reverse - 降順 ]
|
|
70
|
-
attr_reader :direction
|
|
71
|
-
|
|
72
|
-
# 最大繰り返し回数
|
|
73
|
-
# @return [Integer]
|
|
74
|
-
attr_reader :count_limit
|
|
75
|
-
|
|
76
|
-
# 現在の繰り返し回数
|
|
77
|
-
# @return [Integer]
|
|
78
|
-
attr_reader :count
|
|
79
|
-
|
|
80
|
-
# 現在の要素
|
|
81
|
-
# @return [Comparable]
|
|
82
|
-
attr_accessor :current
|
|
83
|
-
protected :current=
|
|
84
|
-
|
|
85
|
-
# 現在のインデックス
|
|
86
|
-
# @return [Integer]
|
|
87
|
-
# @private
|
|
88
|
-
attr_reader :index
|
|
89
|
-
|
|
90
|
-
# with_object メソッドで渡すインスタンス
|
|
91
|
-
# @return [Comparable]
|
|
92
|
-
# @private
|
|
93
|
-
attr_accessor :object
|
|
94
|
-
protected :object=
|
|
95
|
-
|
|
96
|
-
#
|
|
97
|
-
# ブロックを評価する
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
#
|
|
186
|
-
#
|
|
187
|
-
#
|
|
188
|
-
#
|
|
189
|
-
#
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
#
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
#
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
#
|
|
245
|
-
#
|
|
246
|
-
#
|
|
247
|
-
# @param [
|
|
248
|
-
#
|
|
249
|
-
# [
|
|
250
|
-
#
|
|
251
|
-
#
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
@
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
#
|
|
333
|
-
#
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
#
|
|
365
|
-
# @
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
#
|
|
372
|
-
#
|
|
373
|
-
# @
|
|
374
|
-
#
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
#
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
def
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
#
|
|
417
|
-
#
|
|
418
|
-
#
|
|
419
|
-
#
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
#
|
|
428
|
-
#
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
#
|
|
437
|
-
#
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
end
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
=begin
|
|
3
|
+
Copyright (C) 2011-2014 Takashi SUGA
|
|
4
|
+
|
|
5
|
+
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
|
6
|
+
=end
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# 本ライブラリのための諸々の部品
|
|
10
|
+
#
|
|
11
|
+
module When::Parts
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# v1.8.x のための互換性確保用
|
|
15
|
+
#
|
|
16
|
+
# @private
|
|
17
|
+
class Enumerator < ::Enumerator ; end if Object.const_defined?(:Enumerator)
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# 本ライブラリ用の Enumerator の雛形
|
|
21
|
+
#
|
|
22
|
+
class Enumerator
|
|
23
|
+
|
|
24
|
+
# @private
|
|
25
|
+
def self._options(args)
|
|
26
|
+
options = args[-1].kind_of?(Hash) ? args.pop.dup : {}
|
|
27
|
+
options[:exdate] =
|
|
28
|
+
case options[:exdate]
|
|
29
|
+
when GeometricComplex ; options[:exdate].dup
|
|
30
|
+
when nil ; GeometricComplex.new()
|
|
31
|
+
else ; GeometricComplex.new(options[:exdate])
|
|
32
|
+
end
|
|
33
|
+
return options
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# 生成元オブジェクト
|
|
37
|
+
# @return [Comparable]
|
|
38
|
+
attr_reader :parent
|
|
39
|
+
|
|
40
|
+
# オプション
|
|
41
|
+
# @return [Hash]
|
|
42
|
+
# @private
|
|
43
|
+
attr_accessor :options
|
|
44
|
+
protected :options=
|
|
45
|
+
|
|
46
|
+
# 除外要素
|
|
47
|
+
# @return [When::Parts::GeometricComplex]
|
|
48
|
+
attr_accessor :exdate
|
|
49
|
+
protected :exdate=
|
|
50
|
+
|
|
51
|
+
# 処理済み要素
|
|
52
|
+
# @return [When::Parts::GeometricComplex]
|
|
53
|
+
attr_accessor :processed
|
|
54
|
+
protected :processed=
|
|
55
|
+
|
|
56
|
+
# 最初の要素
|
|
57
|
+
# @return [Comparable]
|
|
58
|
+
attr_accessor :first
|
|
59
|
+
protected :first=
|
|
60
|
+
|
|
61
|
+
# 最後の要素
|
|
62
|
+
# @return [Comparable]
|
|
63
|
+
attr_accessor :last
|
|
64
|
+
protected :last=
|
|
65
|
+
|
|
66
|
+
# 繰り返し方向
|
|
67
|
+
# @return [Symbol]
|
|
68
|
+
# [ :forward - 昇順 ]
|
|
69
|
+
# [ :reverse - 降順 ]
|
|
70
|
+
attr_reader :direction
|
|
71
|
+
|
|
72
|
+
# 最大繰り返し回数
|
|
73
|
+
# @return [Integer]
|
|
74
|
+
attr_reader :count_limit
|
|
75
|
+
|
|
76
|
+
# 現在の繰り返し回数
|
|
77
|
+
# @return [Integer]
|
|
78
|
+
attr_reader :count
|
|
79
|
+
|
|
80
|
+
# 現在の要素
|
|
81
|
+
# @return [Comparable]
|
|
82
|
+
attr_accessor :current
|
|
83
|
+
protected :current=
|
|
84
|
+
|
|
85
|
+
# 現在のインデックス
|
|
86
|
+
# @return [Integer]
|
|
87
|
+
# @private
|
|
88
|
+
attr_reader :index
|
|
89
|
+
|
|
90
|
+
# with_object メソッドで渡すインスタンス
|
|
91
|
+
# @return [Comparable]
|
|
92
|
+
# @private
|
|
93
|
+
attr_accessor :object
|
|
94
|
+
protected :object=
|
|
95
|
+
|
|
96
|
+
#
|
|
97
|
+
# ブロックを評価する
|
|
98
|
+
#
|
|
99
|
+
# @param [Hash] options 以下の通り
|
|
100
|
+
# @option options [Symbol] :direction 方向(:forward/:reverse)
|
|
101
|
+
# @option options [Comparable] :until 終了閾値
|
|
102
|
+
# @option options [Integer] :count_limit 繰り返し回数
|
|
103
|
+
#
|
|
104
|
+
# @return [rewind された self]
|
|
105
|
+
#
|
|
106
|
+
def each(options={})
|
|
107
|
+
@direction = options[:direction] if options.key?(:direction)
|
|
108
|
+
@last = @direction == :reverse ? [options[:until], @last].compact.max :
|
|
109
|
+
[options[:until], @last].compact.min
|
|
110
|
+
@count_limit = [options[:count_limit], @count_limit].compact.min
|
|
111
|
+
return self unless block_given?
|
|
112
|
+
while (has_next?) do
|
|
113
|
+
if @index
|
|
114
|
+
yield(succ, @index)
|
|
115
|
+
@index += 1
|
|
116
|
+
elsif @object
|
|
117
|
+
yield(succ, @object)
|
|
118
|
+
else
|
|
119
|
+
yield(succ)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
@index = @object = nil
|
|
123
|
+
rewind
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# index をブロックに渡して評価する
|
|
128
|
+
#
|
|
129
|
+
# @param [Integer] offset index の初期値
|
|
130
|
+
#
|
|
131
|
+
# @return [When::Parts:Enumerator]
|
|
132
|
+
# [ ブロックあり - rewind された self ]
|
|
133
|
+
# [ ブロックなし - copy ]
|
|
134
|
+
#
|
|
135
|
+
def with_index(offset=0, &block)
|
|
136
|
+
if block_given?
|
|
137
|
+
@index = offset||@count
|
|
138
|
+
return each(block)
|
|
139
|
+
else
|
|
140
|
+
copy = _copy
|
|
141
|
+
copy.object = nil
|
|
142
|
+
copy.index = offset||@count
|
|
143
|
+
return copy
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
#
|
|
148
|
+
# index をブロックに渡して評価する
|
|
149
|
+
#
|
|
150
|
+
# @param [Comparable] object ブロックに渡す Object
|
|
151
|
+
#
|
|
152
|
+
# @return [When::Parts:Enumerator]
|
|
153
|
+
# [ ブロックあり - rewind された self ]
|
|
154
|
+
# [ ブロックなし - copy ]
|
|
155
|
+
#
|
|
156
|
+
def with_object(object, &block)
|
|
157
|
+
if block_given?
|
|
158
|
+
@object = object
|
|
159
|
+
each(block)
|
|
160
|
+
return object
|
|
161
|
+
else
|
|
162
|
+
copy = _copy
|
|
163
|
+
copy.object = object
|
|
164
|
+
copy.index = nil
|
|
165
|
+
return copy
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
#
|
|
170
|
+
# 巻き戻す
|
|
171
|
+
#
|
|
172
|
+
# @return [rewind された self]
|
|
173
|
+
#
|
|
174
|
+
def _rewind
|
|
175
|
+
@processed = @exdate.dup
|
|
176
|
+
@count = 0
|
|
177
|
+
@current = :first
|
|
178
|
+
succ
|
|
179
|
+
self
|
|
180
|
+
end
|
|
181
|
+
alias :rewind :_rewind
|
|
182
|
+
|
|
183
|
+
#
|
|
184
|
+
# 次の要素があるか?
|
|
185
|
+
#
|
|
186
|
+
# @return [Boolean]
|
|
187
|
+
# [ true - ある ]
|
|
188
|
+
# [ false - ない ]
|
|
189
|
+
#
|
|
190
|
+
def has_next?
|
|
191
|
+
return (@count_limit != 0) && (@current != nil)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
#
|
|
195
|
+
# 次の要素を取り出す
|
|
196
|
+
#
|
|
197
|
+
# @return [Comparable] 次の要素
|
|
198
|
+
# @raise [StopIteration] 次の要素がない場合 rewind して例外を発生
|
|
199
|
+
#
|
|
200
|
+
def next
|
|
201
|
+
return succ if has_next?
|
|
202
|
+
rewind
|
|
203
|
+
raise StopIteration, "Iteration Stopped"
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
#
|
|
207
|
+
# 次の要素を取り出す
|
|
208
|
+
#
|
|
209
|
+
# @return [Comparable]
|
|
210
|
+
# [ 次の要素あり - 次の要素 ]
|
|
211
|
+
# [ 次の要素なし - nil ]
|
|
212
|
+
#
|
|
213
|
+
# @note
|
|
214
|
+
# 次の要素がない場合 rewind や、StopIteration例外発生は行わない
|
|
215
|
+
#
|
|
216
|
+
def succ
|
|
217
|
+
value = @current
|
|
218
|
+
if @count_limit.kind_of?(Numeric) && @count >= @count_limit
|
|
219
|
+
@current = nil
|
|
220
|
+
else
|
|
221
|
+
loop do
|
|
222
|
+
@current = _succ
|
|
223
|
+
break unless @current
|
|
224
|
+
next if (@current == :next)
|
|
225
|
+
@current = GeometricComplex.new(@current, @duration) if @duration
|
|
226
|
+
next if _exclude(@current)
|
|
227
|
+
case @direction
|
|
228
|
+
when :reverse
|
|
229
|
+
next if @current > @first
|
|
230
|
+
@current = nil if @last && @current < @last
|
|
231
|
+
break
|
|
232
|
+
else
|
|
233
|
+
next if @current < @first
|
|
234
|
+
@current = nil if @last && @current > @last
|
|
235
|
+
break
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
@count += 1
|
|
239
|
+
_exclude(@current) if @current
|
|
240
|
+
end
|
|
241
|
+
return value
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# オブジェクトの生成
|
|
245
|
+
#
|
|
246
|
+
# @overload initialize(parent, range, count_limit=nil)
|
|
247
|
+
# @param [Comparable] parent 生成元
|
|
248
|
+
# @param [Range, When::Parts::GeometricComplex] range
|
|
249
|
+
# [ 始点 - range.first ]
|
|
250
|
+
# [ 終点 - range.last ]
|
|
251
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
|
252
|
+
#
|
|
253
|
+
# @overload initialize(parent, first, direction, count_limit=nil)
|
|
254
|
+
# @param [Comparable] parent 生成元
|
|
255
|
+
# @param [When::TM::TemporalPosition] first 始点
|
|
256
|
+
# @param [Symbol] direction (options[:direction]で渡してもよい)
|
|
257
|
+
# [ :forward - 昇順 ]
|
|
258
|
+
# [ :reverse - 降順 ]
|
|
259
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし, options[:count_limit]で渡してもよい)
|
|
260
|
+
#
|
|
261
|
+
def initialize(*args)
|
|
262
|
+
@options = self.class._options(args)
|
|
263
|
+
@exdate = @options.delete(:exdate)
|
|
264
|
+
@exevent = @options.delete(:exevent)
|
|
265
|
+
@parent, *rest = args
|
|
266
|
+
_range(rest)
|
|
267
|
+
_rewind
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
private
|
|
271
|
+
|
|
272
|
+
def _range(rest)
|
|
273
|
+
if rest[0].instance_of?(Range)
|
|
274
|
+
range, @count_limit, others = rest
|
|
275
|
+
raise ArgumentError, "Too many arguments" if others
|
|
276
|
+
@first = When.when?(range.first)
|
|
277
|
+
@last = When.when?(range.last)
|
|
278
|
+
@exdate |= @last if (range.exclude_end?)
|
|
279
|
+
if (@first > @last)
|
|
280
|
+
@first, @last = @last, @first
|
|
281
|
+
@direction = :reverse
|
|
282
|
+
else
|
|
283
|
+
@direction = :forward
|
|
284
|
+
end
|
|
285
|
+
else
|
|
286
|
+
@first, @direction, @count_limit, others = rest
|
|
287
|
+
raise ArgumentError, "Too many arguments" if others
|
|
288
|
+
raise ArgumentError, "Too few arguments" unless @first
|
|
289
|
+
@direction ||= :forward
|
|
290
|
+
@last = nil
|
|
291
|
+
end
|
|
292
|
+
@count_limit = @options[:count_limit] if @options[:count_limit] && (!@count_limit || @count_limit > @options[:count_limit])
|
|
293
|
+
@options.delete(:count_limit)
|
|
294
|
+
@direction = @options[:direction] if @options[:direction]
|
|
295
|
+
@options.delete(:direction)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def _exclude(value)
|
|
299
|
+
if @exevent
|
|
300
|
+
@exevent.each do |ev|
|
|
301
|
+
return true if ev.include?(value)
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
previous = @processed._include?(value)
|
|
305
|
+
@processed |= value if previous == false
|
|
306
|
+
registered = (previous==value) ? previous : value
|
|
307
|
+
registered = registered.first if registered.kind_of?(GeometricComplex)
|
|
308
|
+
registered.events ||=[]
|
|
309
|
+
registered.events << self.parent
|
|
310
|
+
registered.events.uniq!
|
|
311
|
+
return previous != false
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def _copy
|
|
315
|
+
copy = dup
|
|
316
|
+
copy.options = @options.dup if @options
|
|
317
|
+
copy.exdate = @exdate.dup if @exdate
|
|
318
|
+
copy.exevent = @exevent.dup if @exevent
|
|
319
|
+
copy.processed = @processed.dup if @processed
|
|
320
|
+
copy.first = @first.dup if @first
|
|
321
|
+
copy.last = @last.dup if @last
|
|
322
|
+
copy.current = @current.dup if @current.respond_to?(:dup)
|
|
323
|
+
copy.object = @object.dup if @object.respond_to?(:dup)
|
|
324
|
+
return copy
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
#
|
|
328
|
+
# 時間位置の Array を順に取り出す Enumerator
|
|
329
|
+
#
|
|
330
|
+
class Array < Enumerator
|
|
331
|
+
|
|
332
|
+
# 整列して、重複した候補を削除
|
|
333
|
+
#
|
|
334
|
+
# @param [Array] list
|
|
335
|
+
# @param [Symbol] direction
|
|
336
|
+
# [ :forward - 昇順 ]
|
|
337
|
+
# [ :reverse - 降順 ]
|
|
338
|
+
#
|
|
339
|
+
# @return [Array]
|
|
340
|
+
# @note
|
|
341
|
+
# eql? はオーバーライドしない
|
|
342
|
+
#
|
|
343
|
+
def self._sort(list, direction)
|
|
344
|
+
list = list.sort
|
|
345
|
+
prev = nil
|
|
346
|
+
list.delete_if do |x|
|
|
347
|
+
if (x == prev)
|
|
348
|
+
true
|
|
349
|
+
else
|
|
350
|
+
prev = x
|
|
351
|
+
false
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
list.reverse! if (direction == :reverse)
|
|
355
|
+
return list
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# 初期リスト
|
|
359
|
+
# @return [Array]
|
|
360
|
+
# @private
|
|
361
|
+
attr_accessor :initial_list
|
|
362
|
+
protected :initial_list=
|
|
363
|
+
|
|
364
|
+
# 現在リスト
|
|
365
|
+
# @return [Array]
|
|
366
|
+
# @private
|
|
367
|
+
attr_accessor :current_list
|
|
368
|
+
protected :current_list=
|
|
369
|
+
|
|
370
|
+
#
|
|
371
|
+
# 巻き戻す
|
|
372
|
+
#
|
|
373
|
+
# @return [rewind された self]
|
|
374
|
+
# @private
|
|
375
|
+
def _rewind
|
|
376
|
+
@current_list = @initial_list.dup
|
|
377
|
+
super
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# オブジェクトの生成
|
|
381
|
+
#
|
|
382
|
+
# @overload initialize(parent, list, count_limit=nil))
|
|
383
|
+
# @param [Comparable] parent 生成元
|
|
384
|
+
# @param [Array<When::TM::TemporalPosition>] list 順に取り出す時間位置の Array
|
|
385
|
+
# @param [Symbol] direction
|
|
386
|
+
# [ :forward - 昇順 ]
|
|
387
|
+
# [ :reverse - 降順 ]
|
|
388
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
|
389
|
+
#
|
|
390
|
+
def initialize(*args)
|
|
391
|
+
parent, list, direction, *args = args
|
|
392
|
+
raise ArgumentError, "Too few arguments" unless list
|
|
393
|
+
@initial_list = self.class._sort(list, direction||:forward)
|
|
394
|
+
super(parent, @initial_list[0], direction, *args)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
private
|
|
398
|
+
|
|
399
|
+
def _succ
|
|
400
|
+
return @current_list.shift
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def _copy
|
|
404
|
+
copy = super
|
|
405
|
+
copy.initial_list = @initial_list.dup
|
|
406
|
+
copy.current_list = @current_list.dup
|
|
407
|
+
return copy
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
#
|
|
412
|
+
# 複数の下位 Enumerator の結果を順に取り出す Enumerator
|
|
413
|
+
#
|
|
414
|
+
class Integrated < Enumerator
|
|
415
|
+
|
|
416
|
+
#
|
|
417
|
+
# 下位 Enumerator
|
|
418
|
+
#
|
|
419
|
+
# @return [Array<When::Parts::Enumerator>]
|
|
420
|
+
#
|
|
421
|
+
attr_accessor :enumerators
|
|
422
|
+
protected :enumerators=
|
|
423
|
+
|
|
424
|
+
#
|
|
425
|
+
# 巻き戻す
|
|
426
|
+
#
|
|
427
|
+
# @return [rewind された self]
|
|
428
|
+
#
|
|
429
|
+
def rewind
|
|
430
|
+
@enumerators.each do |enum|
|
|
431
|
+
enum._rewind
|
|
432
|
+
end
|
|
433
|
+
super
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
# オブジェクトの生成
|
|
437
|
+
#
|
|
438
|
+
# @overload initialize(parent, enumerators, first, count_limit=nil))
|
|
439
|
+
# @param [Comparable] parent 生成元
|
|
440
|
+
# @param [Array<When::Parts::Enumerator>] list 順に取り出す下位 Enumeratorの Array
|
|
441
|
+
# @param [When::TM::TemporalPosition] first 始点
|
|
442
|
+
# @param [Symbol] direction
|
|
443
|
+
# [ :forward - 昇順 ]
|
|
444
|
+
# [ :reverse - 降順 ]
|
|
445
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
|
446
|
+
#
|
|
447
|
+
def initialize(*args)
|
|
448
|
+
parent, @enumerators, *rest = args
|
|
449
|
+
raise ArgumentError, "Too few arguments" unless @enumerators.kind_of?(::Array)
|
|
450
|
+
super(parent, *rest)
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
private
|
|
454
|
+
|
|
455
|
+
def _copy
|
|
456
|
+
copy = super
|
|
457
|
+
copy.enumerators = @enumerators.map {|e| e._copy}
|
|
458
|
+
return copy
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
def _succ
|
|
462
|
+
current = nil
|
|
463
|
+
selected = nil
|
|
464
|
+
@enumerators.each_index do |i|
|
|
465
|
+
value = @enumerators[i].current
|
|
466
|
+
next unless (value)
|
|
467
|
+
if (current)
|
|
468
|
+
verify = current <=> value
|
|
469
|
+
case @direction
|
|
470
|
+
when :reverse ; next if (verify > 0)
|
|
471
|
+
else ; next if (verify < 0)
|
|
472
|
+
end
|
|
473
|
+
if (verify == 0)
|
|
474
|
+
next if current.kind_of?(GeometricComplex) && current.include?(value)
|
|
475
|
+
#next if current.precision <= value.precision # TODO
|
|
476
|
+
end
|
|
477
|
+
end
|
|
478
|
+
current = value
|
|
479
|
+
selected = i
|
|
480
|
+
end
|
|
481
|
+
@enumerators[selected].succ if (selected)
|
|
482
|
+
return current
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
end
|