when_exe 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +333 -212
- data/bin/make_ttl.rb +37 -0
- data/bin/make_ttl.rb.config +9 -0
- data/lib/when_exe.rb +923 -925
- data/lib/when_exe/calendarnote.rb +9 -5
- data/lib/when_exe/coordinates.rb +2437 -2446
- data/lib/when_exe/inspect.rb +1480 -1408
- data/lib/when_exe/linkeddata.rb +574 -0
- data/lib/when_exe/locales/akt.rb +177 -176
- data/lib/when_exe/locales/locale.rb +751 -751
- data/lib/when_exe/mini_application.rb +307 -307
- data/lib/when_exe/parts/resource.rb +1115 -1103
- data/lib/when_exe/region/chinese/epochs.rb +6 -5
- data/lib/when_exe/region/christian.rb +831 -829
- data/lib/when_exe/region/japanese.rb +93 -93
- data/lib/when_exe/region/japanese/notes.rb +1510 -1495
- data/lib/when_exe/region/japanese/residues.rb +13 -13
- data/lib/when_exe/tmposition.rb +2307 -2273
- data/lib/when_exe/tmreference.rb +1744 -1734
- data/lib/when_exe/version.rb +2 -2
- data/link_to_online_documents +1 -1
- data/test/scripts/3.ext.rb +6 -6
- data/test/scripts/3.rb +6 -6
- data/test/test.rb +76 -75
- data/test/test/icalendar.rb +883 -879
- data/test/test/linkeddata.rb +224 -0
- data/test/test/region/m17n.rb +193 -193
- data/when_exe.gemspec +3 -2
- metadata +13 -6
data/bin/make_ttl.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2014 Takashi SUGA
|
4
|
+
|
5
|
+
You may use and/or modify this file according to the license
|
6
|
+
described in the LICENSE.txt file included in this archive.
|
7
|
+
=end
|
8
|
+
|
9
|
+
Encoding.default_external = 'UTF-8'
|
10
|
+
Encoding.default_internal = 'UTF-8'
|
11
|
+
|
12
|
+
#require 'linkeddata' # gem install linkeddata
|
13
|
+
require 'json/ld' # gem install json-ld
|
14
|
+
require 'rdf/turtle' # gem install rdf-turtle
|
15
|
+
require 'when_exe'
|
16
|
+
include When
|
17
|
+
|
18
|
+
config = JSON.parse(File.read(ARGV[0] || 'make_ttl.rb.config'))
|
19
|
+
|
20
|
+
PREFIXES = Parts::Resource.namespace_prefixes(*config['resource'])
|
21
|
+
CONTEXT = Parts::Resource.prefixs_to_context(PREFIXES)
|
22
|
+
|
23
|
+
File.open(config['file'], 'w') do |file|
|
24
|
+
CONTEXT.each_pair do |key, value|
|
25
|
+
file.puts "@prefix #{key}: <#{value}> ."
|
26
|
+
end
|
27
|
+
(when?(config['begin'])..when?(config['end'])).each do |date|
|
28
|
+
graph = RDF::Graph.new <<
|
29
|
+
JSON::LD::API.toRdf(date.rdf_graph(
|
30
|
+
{'@context'=>CONTEXT, :prefixes=>PREFIXES, :included=>true, :include=>true}))
|
31
|
+
graph.dump(:ttl, :prefixes=>CONTEXT).each_line do |line|
|
32
|
+
file.puts line unless line =~ /^@/
|
33
|
+
end
|
34
|
+
STDERR.puts '%4d - %s' % [date[YEAR], Time.now.to_s[/\d+:\d+:\d+/]]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/lib/when_exe.rb
CHANGED
@@ -1,925 +1,923 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
=begin
|
3
|
-
Copyright (C) 2011-
|
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
|
-
begin
|
9
|
-
require 'json'
|
10
|
-
rescue LoadError
|
11
|
-
end
|
12
|
-
begin
|
13
|
-
require 'rubygems'
|
14
|
-
rescue LoadError
|
15
|
-
end
|
16
|
-
begin
|
17
|
-
gem 'tzinfo'
|
18
|
-
autoload :TZInfo, 'tzinfo'
|
19
|
-
rescue LoadError, NoMethodError
|
20
|
-
end
|
21
|
-
begin
|
22
|
-
gem 'gcalapi'
|
23
|
-
autoload :GoogleCalendar, 'when_exe/googlecalendar'
|
24
|
-
rescue LoadError, NoMethodError
|
25
|
-
end
|
26
|
-
|
27
|
-
autoload :URI, 'uri'
|
28
|
-
autoload :OpenURI, 'open-uri'
|
29
|
-
autoload :OpenSSL, 'openssl'
|
30
|
-
autoload :FileUtils, 'fileutils'
|
31
|
-
autoload :REXML, 'rexml/document'
|
32
|
-
autoload :Mutex, 'thread' unless Object.const_defined?(:Mutex)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# @
|
62
|
-
# @option options [
|
63
|
-
# @option options [
|
64
|
-
# @option options [
|
65
|
-
# @option options [
|
66
|
-
# @option options [String]
|
67
|
-
# @option options [
|
68
|
-
# @option options [
|
69
|
-
# @option options [Hash
|
70
|
-
# @option options [
|
71
|
-
# @option options [
|
72
|
-
# @option options [Hash
|
73
|
-
# @option options [
|
74
|
-
# @option options [
|
75
|
-
# @option options [
|
76
|
-
# @option options [
|
77
|
-
#
|
78
|
-
# @
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
TM::
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
update(
|
111
|
-
update(
|
112
|
-
update(
|
113
|
-
update(
|
114
|
-
update(
|
115
|
-
update(
|
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
|
-
require 'when_exe/
|
165
|
-
require 'when_exe/
|
166
|
-
require 'when_exe/
|
167
|
-
require 'when_exe/parts/
|
168
|
-
require 'when_exe/
|
169
|
-
require 'when_exe/
|
170
|
-
require 'when_exe/
|
171
|
-
require 'when_exe/
|
172
|
-
require 'when_exe/
|
173
|
-
require 'when_exe/
|
174
|
-
require 'when_exe/
|
175
|
-
require 'when_exe/
|
176
|
-
require 'when_exe/
|
177
|
-
require 'when_exe/
|
178
|
-
require 'when_exe/
|
179
|
-
require 'when_exe/
|
180
|
-
require 'when_exe/
|
181
|
-
require 'when_exe/
|
182
|
-
require 'when_exe/
|
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
|
-
autoload :
|
237
|
-
autoload :
|
238
|
-
autoload :
|
239
|
-
autoload :
|
240
|
-
autoload :
|
241
|
-
autoload :
|
242
|
-
autoload :
|
243
|
-
autoload :
|
244
|
-
autoload :
|
245
|
-
autoload :
|
246
|
-
autoload :
|
247
|
-
autoload :
|
248
|
-
autoload :
|
249
|
-
autoload :
|
250
|
-
autoload :
|
251
|
-
autoload :
|
252
|
-
autoload :
|
253
|
-
autoload :
|
254
|
-
autoload :
|
255
|
-
autoload :
|
256
|
-
autoload :
|
257
|
-
autoload :
|
258
|
-
autoload :
|
259
|
-
autoload :
|
260
|
-
autoload :
|
261
|
-
autoload :
|
262
|
-
autoload :
|
263
|
-
autoload :
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
autoload :
|
270
|
-
autoload :
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
autoload :
|
277
|
-
autoload :
|
278
|
-
autoload :
|
279
|
-
autoload :
|
280
|
-
autoload :
|
281
|
-
autoload :
|
282
|
-
autoload :
|
283
|
-
autoload :
|
284
|
-
autoload :
|
285
|
-
autoload :
|
286
|
-
autoload :
|
287
|
-
autoload :
|
288
|
-
autoload :
|
289
|
-
autoload :
|
290
|
-
autoload :
|
291
|
-
autoload :
|
292
|
-
autoload :
|
293
|
-
autoload :
|
294
|
-
autoload :
|
295
|
-
autoload :
|
296
|
-
autoload :
|
297
|
-
autoload :
|
298
|
-
autoload :
|
299
|
-
autoload :
|
300
|
-
autoload :
|
301
|
-
autoload :
|
302
|
-
autoload :
|
303
|
-
autoload :
|
304
|
-
autoload :
|
305
|
-
autoload :
|
306
|
-
autoload :
|
307
|
-
autoload :
|
308
|
-
autoload :
|
309
|
-
autoload :
|
310
|
-
autoload :
|
311
|
-
autoload :
|
312
|
-
autoload :
|
313
|
-
autoload :
|
314
|
-
autoload :
|
315
|
-
autoload :
|
316
|
-
autoload :
|
317
|
-
autoload :
|
318
|
-
autoload :
|
319
|
-
autoload :
|
320
|
-
autoload :
|
321
|
-
autoload :
|
322
|
-
autoload :
|
323
|
-
autoload :
|
324
|
-
autoload :
|
325
|
-
autoload :
|
326
|
-
autoload :
|
327
|
-
autoload :
|
328
|
-
autoload :
|
329
|
-
autoload :
|
330
|
-
autoload :
|
331
|
-
autoload :
|
332
|
-
autoload :
|
333
|
-
autoload :
|
334
|
-
autoload :
|
335
|
-
autoload :
|
336
|
-
autoload :
|
337
|
-
autoload :
|
338
|
-
autoload :
|
339
|
-
autoload :
|
340
|
-
autoload :
|
341
|
-
autoload :
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
'
|
347
|
-
'
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
autoload :
|
359
|
-
autoload :
|
360
|
-
autoload :
|
361
|
-
autoload :
|
362
|
-
autoload :
|
363
|
-
autoload :
|
364
|
-
autoload :
|
365
|
-
autoload :
|
366
|
-
autoload :
|
367
|
-
autoload :
|
368
|
-
autoload :
|
369
|
-
autoload :
|
370
|
-
autoload :
|
371
|
-
autoload :
|
372
|
-
autoload :
|
373
|
-
autoload :
|
374
|
-
|
375
|
-
autoload :
|
376
|
-
|
377
|
-
autoload :
|
378
|
-
autoload :
|
379
|
-
autoload :
|
380
|
-
autoload :
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
autoload :
|
391
|
-
autoload :
|
392
|
-
autoload :
|
393
|
-
autoload :
|
394
|
-
autoload :
|
395
|
-
autoload :
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
Index.new({:base=>0, :unit=>
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
autoload :
|
423
|
-
autoload :
|
424
|
-
autoload :
|
425
|
-
autoload :
|
426
|
-
autoload :
|
427
|
-
autoload :
|
428
|
-
autoload :
|
429
|
-
autoload :
|
430
|
-
autoload :
|
431
|
-
autoload :
|
432
|
-
autoload :
|
433
|
-
autoload :
|
434
|
-
autoload :
|
435
|
-
autoload :
|
436
|
-
autoload :
|
437
|
-
autoload :
|
438
|
-
|
439
|
-
autoload :
|
440
|
-
|
441
|
-
autoload :
|
442
|
-
autoload :
|
443
|
-
autoload :
|
444
|
-
autoload :
|
445
|
-
autoload :
|
446
|
-
autoload :
|
447
|
-
autoload :
|
448
|
-
autoload :
|
449
|
-
autoload :
|
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
|
-
|
478
|
-
|
479
|
-
'
|
480
|
-
['[
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
'
|
488
|
-
['[
|
489
|
-
['[
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
#
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
#
|
502
|
-
#
|
503
|
-
# @param [
|
504
|
-
# @param [
|
505
|
-
# @param [
|
506
|
-
#
|
507
|
-
# @param [When::TM::TemporalPosition
|
508
|
-
#
|
509
|
-
# @
|
510
|
-
#
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
when TM::TemporalPosition
|
518
|
-
when
|
519
|
-
when
|
520
|
-
when
|
521
|
-
when
|
522
|
-
when
|
523
|
-
when
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
#
|
531
|
-
#
|
532
|
-
#
|
533
|
-
#
|
534
|
-
# [
|
535
|
-
#
|
536
|
-
#
|
537
|
-
#
|
538
|
-
#
|
539
|
-
# [
|
540
|
-
#
|
541
|
-
#
|
542
|
-
#
|
543
|
-
#
|
544
|
-
#
|
545
|
-
#
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
#
|
556
|
-
#
|
557
|
-
#
|
558
|
-
# @param [
|
559
|
-
# @
|
560
|
-
#
|
561
|
-
# @
|
562
|
-
#
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
options
|
567
|
-
options[:
|
568
|
-
|
569
|
-
options[:clock]
|
570
|
-
|
571
|
-
options[:
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
#
|
579
|
-
#
|
580
|
-
# @
|
581
|
-
#
|
582
|
-
#
|
583
|
-
# @
|
584
|
-
#
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
#
|
592
|
-
#
|
593
|
-
#
|
594
|
-
# @
|
595
|
-
#
|
596
|
-
#
|
597
|
-
# @
|
598
|
-
#
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
# When
|
606
|
-
#
|
607
|
-
# @param [
|
608
|
-
# @param [
|
609
|
-
# @param [
|
610
|
-
#
|
611
|
-
# @
|
612
|
-
#
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
#
|
652
|
-
#
|
653
|
-
# @
|
654
|
-
#
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
#
|
662
|
-
#
|
663
|
-
# @
|
664
|
-
#
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
#
|
672
|
-
#
|
673
|
-
# @
|
674
|
-
#
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
#
|
684
|
-
#
|
685
|
-
#
|
686
|
-
# @param [
|
687
|
-
# @param [
|
688
|
-
# @
|
689
|
-
# @
|
690
|
-
# @option options [
|
691
|
-
# @option options [String]
|
692
|
-
#
|
693
|
-
#
|
694
|
-
#
|
695
|
-
#
|
696
|
-
#
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
# When::
|
704
|
-
#
|
705
|
-
# @param [
|
706
|
-
#
|
707
|
-
# @
|
708
|
-
#
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
when
|
714
|
-
when
|
715
|
-
when
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
clock
|
723
|
-
|
724
|
-
|
725
|
-
iri
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
#
|
731
|
-
#
|
732
|
-
#
|
733
|
-
# @param [When::
|
734
|
-
#
|
735
|
-
#
|
736
|
-
#
|
737
|
-
#
|
738
|
-
# @param [Numeric]
|
739
|
-
# @param [
|
740
|
-
# @param [
|
741
|
-
#
|
742
|
-
#
|
743
|
-
#
|
744
|
-
#
|
745
|
-
#
|
746
|
-
#
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
when
|
752
|
-
when
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
longitude
|
767
|
-
|
768
|
-
|
769
|
-
altitude
|
770
|
-
iri
|
771
|
-
iri
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
#
|
777
|
-
#
|
778
|
-
# @
|
779
|
-
#
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
when
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
#
|
795
|
-
#
|
796
|
-
#
|
797
|
-
#
|
798
|
-
#
|
799
|
-
#
|
800
|
-
#
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
#
|
809
|
-
#
|
810
|
-
#
|
811
|
-
#
|
812
|
-
#
|
813
|
-
#
|
814
|
-
#
|
815
|
-
#
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
#
|
823
|
-
#
|
824
|
-
# @
|
825
|
-
#
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
# When::BasicTypes::M17n
|
833
|
-
#
|
834
|
-
# @param [
|
835
|
-
# @param [
|
836
|
-
# @param [Array]
|
837
|
-
# @param [Hash]
|
838
|
-
#
|
839
|
-
# @
|
840
|
-
#
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
when
|
846
|
-
|
847
|
-
|
848
|
-
source
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
#
|
857
|
-
#
|
858
|
-
# @
|
859
|
-
# @
|
860
|
-
# @option options [
|
861
|
-
#
|
862
|
-
# @
|
863
|
-
#
|
864
|
-
# @
|
865
|
-
#
|
866
|
-
#
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
url
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
#
|
881
|
-
#
|
882
|
-
#
|
883
|
-
# @
|
884
|
-
#
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
#
|
893
|
-
#
|
894
|
-
#
|
895
|
-
# @param [
|
896
|
-
# @
|
897
|
-
# @
|
898
|
-
# @option options [
|
899
|
-
# @option options [
|
900
|
-
# @option options [Integer] :
|
901
|
-
#
|
902
|
-
#
|
903
|
-
#
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
#
|
911
|
-
#
|
912
|
-
# @
|
913
|
-
#
|
914
|
-
# @
|
915
|
-
#
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2011-2015 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
|
+
begin
|
9
|
+
require 'json'
|
10
|
+
rescue LoadError
|
11
|
+
end
|
12
|
+
begin
|
13
|
+
require 'rubygems'
|
14
|
+
rescue LoadError
|
15
|
+
end
|
16
|
+
begin
|
17
|
+
gem 'tzinfo'
|
18
|
+
autoload :TZInfo, 'tzinfo'
|
19
|
+
rescue LoadError, NoMethodError
|
20
|
+
end
|
21
|
+
begin
|
22
|
+
gem 'gcalapi'
|
23
|
+
autoload :GoogleCalendar, 'when_exe/googlecalendar'
|
24
|
+
rescue LoadError, NoMethodError
|
25
|
+
end
|
26
|
+
|
27
|
+
autoload :URI, 'uri'
|
28
|
+
autoload :OpenURI, 'open-uri'
|
29
|
+
autoload :OpenSSL, 'openssl'
|
30
|
+
autoload :FileUtils, 'fileutils'
|
31
|
+
autoload :REXML, 'rexml/document'
|
32
|
+
autoload :Mutex, 'thread' unless Object.const_defined?(:Mutex)
|
33
|
+
|
34
|
+
#
|
35
|
+
# A multicultural and multilingualized calendar library based on ISO 8601, ISO 19108 and RFC 5545
|
36
|
+
#
|
37
|
+
module When
|
38
|
+
|
39
|
+
class << self
|
40
|
+
|
41
|
+
#
|
42
|
+
# マルチスレッド対応の場合 true
|
43
|
+
#
|
44
|
+
# @return [Boolean]
|
45
|
+
#
|
46
|
+
attr_reader :multi_thread
|
47
|
+
|
48
|
+
#
|
49
|
+
# Logger オブジェクト
|
50
|
+
#
|
51
|
+
# @return [Logger]
|
52
|
+
#
|
53
|
+
attr_accessor :logger
|
54
|
+
private :logger=
|
55
|
+
|
56
|
+
# Initializations
|
57
|
+
#
|
58
|
+
# @param [Hash] options 以下の通り
|
59
|
+
# @option options [When::Parts::Timezone::Base] :local デフォルトの地方時
|
60
|
+
# @option options [When::Coordinates::Spatial] :location デフォルトの空間位置
|
61
|
+
# @option options [When::TM::IntervalLength] :until V::Event::Enumerator の until
|
62
|
+
# @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
|
63
|
+
# @option options [String] :namespace_format 名前空間定義の省略時に名前空間生成に用いる書式
|
64
|
+
# @option options [Hash{String=>String}] :unification 漢字の包摂パターン ({ 包摂前の文字列=>包摂後の文字列 })
|
65
|
+
# @option options [Array<String>] :order CalendarEra の検索順序 ([ IRI of When::TM::CalendarEra ])
|
66
|
+
# @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
|
67
|
+
# @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
|
68
|
+
# @option options [String] :base_uri Base URI for When_exe Resources (Default When::SourceURI)
|
69
|
+
# @option options [Hash<String=>String>] :additional_namespaces User defined namespaces (Default {})
|
70
|
+
# @option options [String] :root_dir Root Directory for When_exe Resources Cash data (Default When::RootDir)
|
71
|
+
# @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
|
72
|
+
# @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
|
73
|
+
# @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
|
74
|
+
# @option options [true] :escape すべて毎回 method_missing を発生させる
|
75
|
+
# @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
|
76
|
+
# @option options [Logger] :logger Logger オブジェクト
|
77
|
+
#
|
78
|
+
# @return [void]
|
79
|
+
#
|
80
|
+
# @note
|
81
|
+
# 本メソッドでマルチスレッド対応の管理変数の初期化を行っている。
|
82
|
+
# このため、本メソッド自体および本メソッドから呼んでいる各クラスの _setup_ メソッドはスレッドセーフでない。
|
83
|
+
#
|
84
|
+
def _setup_(options={})
|
85
|
+
@multi_thread = options[:multi_thread]
|
86
|
+
@logger = options[:logger]
|
87
|
+
Parts::MethodCash._setup_(options)
|
88
|
+
Parts::Resource._setup_(options)
|
89
|
+
Locale._setup_(options)
|
90
|
+
Coordinates::Spatial._setup_(options[:location])
|
91
|
+
TM::CalendarEra._setup_(options[:order])
|
92
|
+
TM::Calendar._setup_
|
93
|
+
TM::Clock._setup_(options[:local])
|
94
|
+
TM::TemporalPosition._setup_(options[:format])
|
95
|
+
V::Event._setup_(options[:until])
|
96
|
+
V::Timezone._setup_
|
97
|
+
Parts::Timezone._setup_
|
98
|
+
TimeStandard._setup_(options[:leap_seconds])
|
99
|
+
end
|
100
|
+
|
101
|
+
# 設定情報を取得する
|
102
|
+
#
|
103
|
+
# @return [Hash] 設定情報
|
104
|
+
#
|
105
|
+
def _setup_info
|
106
|
+
{:multi_thread => @multi_thread}.
|
107
|
+
update(Parts::MethodCash._setup_info).
|
108
|
+
update(Parts::Resource._setup_info).
|
109
|
+
update(Locale._setup_info).
|
110
|
+
update(Coordinates::Spatial._setup_info).
|
111
|
+
update(TM::CalendarEra._setup_info).
|
112
|
+
update(TM::Clock._setup_info).
|
113
|
+
update(TM::TemporalPosition._setup_info).
|
114
|
+
update(V::Event._setup_info).
|
115
|
+
update(TimeStandard._setup_info)
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# When 直下に定数として定義する時法・暦法(明示的的追加)
|
120
|
+
#
|
121
|
+
# @private
|
122
|
+
def _define_common_calendar_types(list=%w(UTC Gregorian Julian Civil))
|
123
|
+
list.each do |calendar|
|
124
|
+
resource = Parts::Resource._instance(calendar, '_c:')
|
125
|
+
Parts::Resource.synchronize do
|
126
|
+
Parts::Resource::ConstList << calendar
|
127
|
+
const_set(calendar, resource)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
alias :_const_missing :const_missing
|
133
|
+
|
134
|
+
#
|
135
|
+
# When 直下に定数として定義する時法・暦法など(暗黙的追加)
|
136
|
+
#
|
137
|
+
def const_missing(constant)
|
138
|
+
sgn, *args = TM::PeriodDuration._to_array(constant.to_s)
|
139
|
+
return const_set(constant, TM::PeriodDuration.new(*args)) if sgn
|
140
|
+
iri = Parts::Resource._abbreviation_to_iri(constant)
|
141
|
+
return _const_missing(constant) unless iri
|
142
|
+
resource = Parts::Resource._instance(iri)
|
143
|
+
return const_get(constant) if const_defined?(constant)
|
144
|
+
Parts::Resource.synchronize do
|
145
|
+
Parts::Resource::ConstList << constant
|
146
|
+
const_set(constant, resource)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# when_exe 用 International Resource Identifier
|
153
|
+
#
|
154
|
+
SourceURI = ENV["WHEN_EXE_BASE_URI"] || "http://hosi.org/When/"
|
155
|
+
|
156
|
+
#
|
157
|
+
# ルートディレクトリ(デフォルトでは lib の親ディレクトリ
|
158
|
+
#
|
159
|
+
RootDir = ENV["WHEN_EXE_ROOT_DIR"] || File.dirname(__FILE__).sub(/\/[^\/]*\z/,'')
|
160
|
+
|
161
|
+
require 'when_exe/version'
|
162
|
+
require 'when_exe/locales/locale'
|
163
|
+
require 'when_exe/locales/autoload'
|
164
|
+
require 'when_exe/parts/enumerator'
|
165
|
+
require 'when_exe/parts/resource'
|
166
|
+
require 'when_exe/parts/geometric_complex'
|
167
|
+
require 'when_exe/parts/timezone'
|
168
|
+
require 'when_exe/core/compatibility'
|
169
|
+
require 'when_exe/basictypes'
|
170
|
+
require 'when_exe/ephemeris'
|
171
|
+
require 'when_exe/coordinates'
|
172
|
+
require 'when_exe/icalendar'
|
173
|
+
require 'when_exe/tmobjects'
|
174
|
+
require 'when_exe/timestandard'
|
175
|
+
require 'when_exe/tmposition'
|
176
|
+
require 'when_exe/tmreference'
|
177
|
+
require 'when_exe/calendartypes'
|
178
|
+
require 'when_exe/calendarnote'
|
179
|
+
require 'when_exe/region/m17n'
|
180
|
+
require 'when_exe/region/residue'
|
181
|
+
require 'when_exe/inspect'
|
182
|
+
require 'when_exe/linkeddata'
|
183
|
+
|
184
|
+
#
|
185
|
+
# Module Constants
|
186
|
+
#
|
187
|
+
|
188
|
+
# 1 second period duration
|
189
|
+
PT1S = TM::PeriodDuration.new(nil,[0,0,0,1])
|
190
|
+
|
191
|
+
# 1 minute period duration
|
192
|
+
PT1M = TM::PeriodDuration.new(nil,[0,0,1,0])
|
193
|
+
|
194
|
+
# 1 hour period duration
|
195
|
+
PT1H = TM::PeriodDuration.new(nil,[0,1,0,0])
|
196
|
+
|
197
|
+
# 1 day period duration
|
198
|
+
P1D = TM::PeriodDuration.new([0,0,1])
|
199
|
+
|
200
|
+
# 1 week period duration
|
201
|
+
P1W = TM::PeriodDuration.new([0,0,7])
|
202
|
+
|
203
|
+
# 1 month period duration
|
204
|
+
P1M = TM::PeriodDuration.new([0,1,0])
|
205
|
+
|
206
|
+
# 1 year period duration
|
207
|
+
P1Y = TM::PeriodDuration.new([1,0,0])
|
208
|
+
|
209
|
+
# kind of When::TM::Position or When::TM::TemporalPosition
|
210
|
+
TimeValue = TM::IndeterminateValue
|
211
|
+
|
212
|
+
# 7 days week residue
|
213
|
+
Week = When::Parts::Resource._instance('_co:Common::Week')
|
214
|
+
|
215
|
+
# Gregorian months
|
216
|
+
Month = When::Parts::Resource._instance('_m:Calendar::Month')
|
217
|
+
|
218
|
+
# + ∞
|
219
|
+
PlusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Max})
|
220
|
+
|
221
|
+
# - ∞
|
222
|
+
MinusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Min})
|
223
|
+
|
224
|
+
# UTF-8 encoding
|
225
|
+
UTF8 = '.UTF-8'
|
226
|
+
|
227
|
+
# Windows-31J encoding
|
228
|
+
W31J = '.Windows-31J'
|
229
|
+
|
230
|
+
# eucJP encoding
|
231
|
+
EUCJP = '.eucJP'
|
232
|
+
|
233
|
+
class BasicTypes::M17n
|
234
|
+
autoload :Japanese, 'when_exe/region/japanese'
|
235
|
+
autoload :Chinese, 'when_exe/region/chinese'
|
236
|
+
autoload :Yi, 'when_exe/region/chinese'
|
237
|
+
autoload :Tibetan, 'when_exe/region/tibetan'
|
238
|
+
autoload :Thai, 'when_exe/region/thai'
|
239
|
+
autoload :Balinese, 'when_exe/region/balinese'
|
240
|
+
autoload :Javanese, 'when_exe/region/javanese'
|
241
|
+
autoload :Indian, 'when_exe/region/indian'
|
242
|
+
autoload :Iranian, 'when_exe/region/iranian'
|
243
|
+
autoload :Islamic, 'when_exe/region/islamic'
|
244
|
+
autoload :Jewish, 'when_exe/region/jewish'
|
245
|
+
autoload :AncientOrient, 'when_exe/region/babylonian'
|
246
|
+
autoload :Armenian, 'when_exe/region/armenian'
|
247
|
+
autoload :Roman, 'when_exe/region/roman'
|
248
|
+
autoload :Coptic, 'when_exe/region/coptic'
|
249
|
+
autoload :French, 'when_exe/region/french'
|
250
|
+
autoload :World, 'when_exe/region/world'
|
251
|
+
autoload :Positivist, 'when_exe/region/positivist'
|
252
|
+
autoload :InternationalFixed, 'when_exe/region/international_fixed'
|
253
|
+
autoload :WorldSeason, 'when_exe/region/world_season'
|
254
|
+
autoload :Tranquility, 'when_exe/region/tranquility'
|
255
|
+
autoload :Pax, 'when_exe/region/pax'
|
256
|
+
autoload :HankeHenry, 'when_exe/region/hanke_henry'
|
257
|
+
autoload :Shire, 'when_exe/region/shire'
|
258
|
+
autoload :Dee, 'when_exe/region/dee'
|
259
|
+
autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
|
260
|
+
autoload :Yerm, 'when_exe/region/yerm'
|
261
|
+
autoload :Goddess, 'when_exe/region/goddess'
|
262
|
+
autoload :Martian, 'when_exe/region/martian'
|
263
|
+
autoload :WeekDate, 'when_exe/region/weekdate'
|
264
|
+
end
|
265
|
+
|
266
|
+
module Locale
|
267
|
+
autoload :WikipediaLinks, 'when_exe/locales/links'
|
268
|
+
autoload :IAST, 'when_exe/locales/iast'
|
269
|
+
autoload :IASTR, 'when_exe/locales/iast'
|
270
|
+
autoload :AKT, 'when_exe/locales/akt'
|
271
|
+
end
|
272
|
+
|
273
|
+
module CalendarTypes
|
274
|
+
autoload :Japanese, 'when_exe/region/japanese/calendars'
|
275
|
+
autoload :JapaneseTwin, 'when_exe/region/japanese/twins'
|
276
|
+
autoload :ChineseTwin, 'when_exe/region/chinese/twins'
|
277
|
+
autoload :ChineseSolar, 'when_exe/region/chinese'
|
278
|
+
autoload :ChineseLuniSolar, 'when_exe/region/chinese'
|
279
|
+
autoload :Yi, 'when_exe/region/chinese'
|
280
|
+
autoload :TenrekiA, 'when_exe/region/chinese'
|
281
|
+
autoload :TenrekiB, 'when_exe/region/chinese'
|
282
|
+
autoload :Korean, 'when_exe/region/korean'
|
283
|
+
autoload :Tibetan, 'when_exe/region/tibetan'
|
284
|
+
autoload :Thai, 'when_exe/region/thai'
|
285
|
+
autoload :ThaiP, 'when_exe/region/thai'
|
286
|
+
autoload :ThaiC, 'when_exe/region/thai'
|
287
|
+
autoload :ThaiT, 'when_exe/region/thai'
|
288
|
+
autoload :Tenganan, 'when_exe/region/balinese'
|
289
|
+
autoload :Pranatamangsa, 'when_exe/region/javanese'
|
290
|
+
autoload :IndianNationalSolar, 'when_exe/region/indian'
|
291
|
+
autoload :Nanakshahi, 'when_exe/region/indian'
|
292
|
+
autoload :RevisedBengali, 'when_exe/region/indian'
|
293
|
+
autoload :HinduLuniSolar, 'when_exe/region/indian'
|
294
|
+
autoload :HinduSolar, 'when_exe/region/indian'
|
295
|
+
autoload :Jalali, 'when_exe/region/iranian'
|
296
|
+
autoload :TableBasedJalali, 'when_exe/region/iranian'
|
297
|
+
autoload :Borji, 'when_exe/region/iranian'
|
298
|
+
autoload :TableBasedBorji, 'when_exe/region/iranian'
|
299
|
+
autoload :SolarHijri, 'when_exe/region/iranian'
|
300
|
+
autoload :SolarHijriAlgorithmic, 'when_exe/region/iranian'
|
301
|
+
autoload :Zoroastrian, 'when_exe/region/zoroastrian'
|
302
|
+
autoload :Qadimi, 'when_exe/region/zoroastrian'
|
303
|
+
autoload :Shahanshahi, 'when_exe/region/zoroastrian'
|
304
|
+
autoload :Fasli, 'when_exe/region/zoroastrian'
|
305
|
+
autoload :Bahai, 'when_exe/region/bahai'
|
306
|
+
autoload :TabularIslamic, 'when_exe/region/islamic'
|
307
|
+
autoload :EphemerisBasedIslamic, 'when_exe/region/islamic'
|
308
|
+
autoload :Jewish, 'when_exe/region/jewish'
|
309
|
+
autoload :Hebrew, 'when_exe/region/jewish'
|
310
|
+
autoload :Armenian, 'when_exe/region/armenian'
|
311
|
+
autoload :Babylonian, 'when_exe/region/babylonian'
|
312
|
+
autoload :BabylonianPD, 'when_exe/region/babylonian'
|
313
|
+
autoload :Seleucid, 'when_exe/region/babylonian'
|
314
|
+
autoload :SeleucidPD, 'when_exe/region/babylonian'
|
315
|
+
autoload :Ptolemaic, 'when_exe/region/coptic'
|
316
|
+
autoload :Coptic, 'when_exe/region/coptic'
|
317
|
+
autoload :JulianA, 'when_exe/region/roman'
|
318
|
+
autoload :JulianB, 'when_exe/region/roman'
|
319
|
+
autoload :JulianC, 'when_exe/region/roman'
|
320
|
+
autoload :Roman, 'when_exe/region/roman'
|
321
|
+
autoload :Gregorian, 'when_exe/region/christian'
|
322
|
+
autoload :FrenchRepublican, 'when_exe/region/french'
|
323
|
+
autoload :World, 'when_exe/region/world'
|
324
|
+
autoload :LongCount, 'when_exe/region/mayan'
|
325
|
+
autoload :Positivist, 'when_exe/region/positivist'
|
326
|
+
autoload :InternationalFixed, 'when_exe/region/international_fixed'
|
327
|
+
autoload :WorldSeason, 'when_exe/region/world_season'
|
328
|
+
autoload :Pax, 'when_exe/region/pax'
|
329
|
+
autoload :Tranquility, 'when_exe/region/tranquility'
|
330
|
+
autoload :HankeHenry, 'when_exe/region/hanke_henry'
|
331
|
+
autoload :Discordian, 'when_exe/region/discordian'
|
332
|
+
autoload :Shire, 'when_exe/region/shire'
|
333
|
+
autoload :Sym454, 'when_exe/region/symmetry'
|
334
|
+
autoload :Sym010, 'when_exe/region/symmetry'
|
335
|
+
autoload :Dee, 'when_exe/region/dee'
|
336
|
+
autoload :DeeCecil, 'when_exe/region/dee'
|
337
|
+
autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
|
338
|
+
autoload :Yerm, 'when_exe/region/yerm'
|
339
|
+
autoload :Goddess, 'when_exe/region/goddess'
|
340
|
+
autoload :Darian, 'when_exe/region/martian'
|
341
|
+
autoload :WeekDate, 'when_exe/region/weekdate'
|
342
|
+
|
343
|
+
_time_systems = {
|
344
|
+
'LMT' => nil, # Local Mean Time
|
345
|
+
'LAT' => nil, # Local Apparent Time
|
346
|
+
'THS' => nil, # Temporal Hour System
|
347
|
+
'MTC' => 'when_exe/region/martian', # Martian Time, Coordinated
|
348
|
+
}
|
349
|
+
TimeSystems = _time_systems.keys.join('|')
|
350
|
+
_time_systems.each_pair do |key, required|
|
351
|
+
autoload key.to_sym, required if required
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
class CalendarNote
|
356
|
+
autoload :SolarTerms, 'when_exe/ephemeris/notes'
|
357
|
+
autoload :LunarPhases, 'when_exe/ephemeris/notes'
|
358
|
+
autoload :Ephemeris, 'when_exe/ephemeris/notes'
|
359
|
+
autoload :Japanese, 'when_exe/region/japanese/notes'
|
360
|
+
autoload :CommonWithRokuyo, 'when_exe/region/japanese/weeks'
|
361
|
+
autoload :RokuyoWeek, 'when_exe/region/japanese/weeks'
|
362
|
+
autoload :Yis, 'when_exe/region/chinese'
|
363
|
+
autoload :Balinese, 'when_exe/region/balinese'
|
364
|
+
autoload :Javanese, 'when_exe/region/javanese'
|
365
|
+
autoload :Tibetan, 'when_exe/region/tibetan'
|
366
|
+
autoload :Bahai, 'when_exe/region/bahai'
|
367
|
+
autoload :Roman, 'when_exe/region/roman'
|
368
|
+
autoload :Mayan, 'when_exe/region/mayan'
|
369
|
+
autoload :DiscordianWeek, 'when_exe/region/discordian'
|
370
|
+
autoload :CommonWithSovietFiveDay, 'when_exe/region/soviet'
|
371
|
+
autoload :SovietFiveDayWeek, 'when_exe/region/soviet'
|
372
|
+
autoload :CommonWithSovietSixDay, 'when_exe/region/soviet'
|
373
|
+
autoload :SovietSixDayWeek, 'when_exe/region/soviet'
|
374
|
+
# autoload :Yerm, 'when_exe/region/yerm'
|
375
|
+
autoload :WorldWeek, 'when_exe/region/world'
|
376
|
+
autoload :PositivistWeek, 'when_exe/region/positivist'
|
377
|
+
autoload :InternationalFixedWeek, 'when_exe/region/international_fixed'
|
378
|
+
autoload :TranquilityWeek, 'when_exe/region/tranquility'
|
379
|
+
autoload :WorldSeasonWeek, 'when_exe/region/world_season'
|
380
|
+
autoload :ShireWeek, 'when_exe/region/shire'
|
381
|
+
|
382
|
+
Default = [['_m:Calendar::Month'], ['Common::Week']]
|
383
|
+
JulianDay = [['Common::Week', 'Common::干支']]
|
384
|
+
Chinese = [['Common::干支'], ['_m:Calendar::Month'], ['Common::Week', 'Common::干支']]
|
385
|
+
end
|
386
|
+
|
387
|
+
module Coordinates
|
388
|
+
autoload :Tibetan, 'when_exe/region/tibetan'
|
389
|
+
autoload :Yi, 'when_exe/region/chinese'
|
390
|
+
autoload :Javanese, 'when_exe/region/javanese'
|
391
|
+
autoload :Indian, 'when_exe/region/indian'
|
392
|
+
autoload :Iranian, 'when_exe/region/iranian'
|
393
|
+
autoload :Bahai, 'when_exe/region/bahai'
|
394
|
+
autoload :Roman, 'when_exe/region/roman'
|
395
|
+
autoload :Mayan, 'when_exe/region/mayan'
|
396
|
+
|
397
|
+
# default index for day coordinate
|
398
|
+
DefaultDayIndex = Index.new
|
399
|
+
|
400
|
+
# default indices for date coordinates
|
401
|
+
DefaultDateIndices = [
|
402
|
+
Index.new(When::Parts::Resource._instance('_m:Calendar::Month'), {:unit =>12}),
|
403
|
+
DefaultDayIndex
|
404
|
+
]
|
405
|
+
|
406
|
+
# default indices for time coordinates
|
407
|
+
DefaultTimeIndices = [
|
408
|
+
Index.new({:base=>0, :unit=>24}),
|
409
|
+
Index.new({:base=>0, :unit=>60}),
|
410
|
+
Index.new({:base=>0, :unit=>60})
|
411
|
+
]
|
412
|
+
end
|
413
|
+
|
414
|
+
module TM
|
415
|
+
class OrdinalReferenceSystem
|
416
|
+
autoload :GeologicalAge, 'when_exe/region/geologicalage'
|
417
|
+
end
|
418
|
+
|
419
|
+
class CalendarEra
|
420
|
+
autoload :Japanese, 'when_exe/region/japanese/epochs'
|
421
|
+
autoload :JapanesePrimeMinister, 'when_exe/region/japanese/epochs'
|
422
|
+
autoload :NihonKoki, 'when_exe/region/japanese/nihon_shoki'
|
423
|
+
autoload :NihonShoki, 'when_exe/region/japanese/nihon_shoki'
|
424
|
+
autoload :JapaneseSolar, 'when_exe/region/japanese/twins'
|
425
|
+
autoload :JapaneseLuniSolar, 'when_exe/region/japanese/twins'
|
426
|
+
autoload :Chinese, 'when_exe/region/chinese/epochs'
|
427
|
+
autoload :ChineseSolar, 'when_exe/region/chinese/twins'
|
428
|
+
autoload :ChineseLuniSolar, 'when_exe/region/chinese/twins'
|
429
|
+
autoload :Ryukyu, 'when_exe/region/ryukyu'
|
430
|
+
autoload :Korean, 'when_exe/region/korean'
|
431
|
+
autoload :Vietnamese, 'when_exe/region/vietnamese'
|
432
|
+
autoload :Manchurian, 'when_exe/region/east_asian'
|
433
|
+
autoload :Rouran, 'when_exe/region/east_asian'
|
434
|
+
autoload :Gaochang, 'when_exe/region/east_asian'
|
435
|
+
autoload :Yunnan, 'when_exe/region/east_asian'
|
436
|
+
autoload :WesternXia, 'when_exe/region/east_asian'
|
437
|
+
autoload :KaraKhitan, 'when_exe/region/east_asian'
|
438
|
+
# autoload :Tibetan, 'when_exe/region/tibetan'
|
439
|
+
autoload :BalineseLuniSolar, 'when_exe/region/balinese'
|
440
|
+
autoload :JavaneseLunar, 'when_exe/region/javanese'
|
441
|
+
autoload :Iranian, 'when_exe/region/iranian'
|
442
|
+
autoload :Hijra, 'when_exe/region/islamic'
|
443
|
+
autoload :Jewish, 'when_exe/region/jewish'
|
444
|
+
autoload :AncientOrient, 'when_exe/region/babylonian'
|
445
|
+
autoload :Roman, 'when_exe/region/roman'
|
446
|
+
autoload :Julian, 'when_exe/region/roman'
|
447
|
+
autoload :Pope, 'when_exe/region/pope'
|
448
|
+
autoload :Byzantine, 'when_exe/region/christian'
|
449
|
+
autoload :LongCount, 'when_exe/region/mayan'
|
450
|
+
|
451
|
+
# Defualt search path for Epochs and Eras
|
452
|
+
DefaultEpochs = ['Common', 'ModernJapanese',
|
453
|
+
'Hijra', 'Jewish', 'Iranian',
|
454
|
+
'Roman', 'Byzantine', 'AncientOrient', 'LongCount',
|
455
|
+
'BalineseLuniSolar', 'JavaneseLunar',
|
456
|
+
'Japanese', 'NihonKoki', 'NihonShoki',
|
457
|
+
'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
|
458
|
+
'JapaneseLuniSolar', 'JapaneseSolar',
|
459
|
+
'ChineseLuniSolar', 'ChineseSolar',
|
460
|
+
'Manchurian', 'Rouran', 'Gaochang',
|
461
|
+
'Yunnan', 'WesternXia', 'KaraKhitan', # 'Tibetan',
|
462
|
+
'Pope', 'JapanesePrimeMinister']
|
463
|
+
|
464
|
+
# Defualt events for Epochs and Eras
|
465
|
+
DefaultEvents = Hash[*([['@A', 'Accession' ],
|
466
|
+
['@FE', 'FelicitousEvent' ],
|
467
|
+
['@ND', 'NaturalDisaster' ],
|
468
|
+
['@IY', 'InauspiciousYear'],
|
469
|
+
['@F', 'Foundation' ],
|
470
|
+
['@CR', 'CalendarReform' ],
|
471
|
+
['@CE', 'CalendarEpoch' ]].map {|e|
|
472
|
+
[e[0], When::Parts::Resource._instance('EpochEvents::'+e[1], '_m:')]
|
473
|
+
}.flatten)]
|
474
|
+
|
475
|
+
# Common Era
|
476
|
+
Common = [{}, self, [
|
477
|
+
'area:Common#{?Reform=Reform}',
|
478
|
+
['[BeforeCommonEra=en:BCE_(disambiguation),*alias:BCE]0.1.1'],
|
479
|
+
['[CommonEra=en:Common_Era,*alias:CE]1.1.1', '@CE', '01-01-01^Julian'],
|
480
|
+
['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', '@CR', '#{Reform:1582.10.15}^Gregorian']
|
481
|
+
]]
|
482
|
+
|
483
|
+
# Modern Japanese Eras after the calendar reform to the Gregorian Calendar
|
484
|
+
ModernJapanese = [self, [
|
485
|
+
'area:[ModernJapanese]',
|
486
|
+
['[M=,alias:明=ja:%%<明治>]6.01.01', '@CR', '1873-01-01^Gregorian?note=Default'],
|
487
|
+
['[T=,alias:大=ja:%%<大正>]1.07.30', '@A', '1912-07-30'],
|
488
|
+
['[S=,alias:昭=ja:%%<昭和>]1.12.25', '@A', '1926-12-25'],
|
489
|
+
['[H=,alias:平=ja:%%<平成>]1.01.08', '@A', '1989-01-08']
|
490
|
+
]]
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
#
|
495
|
+
# Module Functions
|
496
|
+
#
|
497
|
+
module_function
|
498
|
+
|
499
|
+
# Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
|
500
|
+
#
|
501
|
+
# @param [String] specification When.exe Standard Representation または ユリウス日JDN として解釈して生成する
|
502
|
+
# @param [Numeric] specification ユリウス日として解釈して生成する
|
503
|
+
# @param [Array] specification 要素を個別に解釈して生成したオブジェクトのArrayを返す
|
504
|
+
# @param [When::TM::TemporalPosition, When::Parts::GeometricComplex] specification specificationをそのまま返す
|
505
|
+
# @param [When::TM::TemporalPosition] specification specification.any_otherを返す
|
506
|
+
#
|
507
|
+
# @param [Hash] options 暦法や時法などの指定 (see {When::TM::TemporalPosition._instance})
|
508
|
+
#
|
509
|
+
# @return [When::TM::TemporalPosition, When::TM::Duration, When::Parts::GeometricComplex or Array<them>]
|
510
|
+
#
|
511
|
+
def when?(specification, options={})
|
512
|
+
|
513
|
+
# フォーマットごとの処理
|
514
|
+
case specification
|
515
|
+
when TM::TemporalPosition, Parts::GeometricComplex ; specification
|
516
|
+
when TM::Position ; specification.any_other
|
517
|
+
when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
|
518
|
+
when /\Atoday(\^{1,2}(.+))?\z/i ; today($2 ? {:frame=>$2}.update(options) : options)
|
519
|
+
when /\Anow(\^{1,2}(.+))?\z/i ; now( $2 ? {:frame=>$2}.update(options) : options)
|
520
|
+
when /(JDN|MJD|SDN|CEP)(\z|\^)/i; TM::JulianDate.parse(specification, options)
|
521
|
+
when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
|
522
|
+
when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
|
523
|
+
when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
|
524
|
+
else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
# When::TM::TemporalPosition の生成
|
529
|
+
#
|
530
|
+
# @overload TemporalPosition(*args, options={})
|
531
|
+
# @param [String or [String, Integer], Numeric, ...] args
|
532
|
+
# [String] 年号
|
533
|
+
# [Array<String, Integer>] 年号と 0 年の通年
|
534
|
+
# [Numeric] 年月日時分秒(途中で打ち切り可)
|
535
|
+
# @param [Hash] options 暦法や時法などの指定
|
536
|
+
# @option options [Symbol] :invalid
|
537
|
+
# [:raise 日時が存在しない場合例外発生 ]
|
538
|
+
# [:check 日時が存在しない場合 nil を返す ]
|
539
|
+
# [その他/nil 日時が存在することを確認しない(デフォルト)]
|
540
|
+
# @see When::TM::TemporalPosition._instance
|
541
|
+
#
|
542
|
+
# @return [When::TM::TemporalPosition]
|
543
|
+
# @raise [ArgumentError]
|
544
|
+
# options[ :invalid ] が :raise で、日時が存在しない場合
|
545
|
+
#
|
546
|
+
def TemporalPosition(*args)
|
547
|
+
TM::TemporalPosition._temporal_position(*args)
|
548
|
+
end
|
549
|
+
|
550
|
+
alias :tm_pos :TemporalPosition
|
551
|
+
module_function :tm_pos
|
552
|
+
|
553
|
+
# 指定日時に対応する When::TM::TemporalPosition の生成
|
554
|
+
# (When::TM::DateAndTime of specified Time)
|
555
|
+
#
|
556
|
+
# @param [::Time] time 変換元の日時のTimeオブジェクト
|
557
|
+
# @param [Float] time 1970-01-01T00:00:00Z からの経過秒数
|
558
|
+
# @param [Hash] options 暦法や時法などの指定
|
559
|
+
# @see When::TM::TemporalPosition._instance
|
560
|
+
#
|
561
|
+
# @return [When::TM::DateAndTime]
|
562
|
+
#
|
563
|
+
def at(time, options={})
|
564
|
+
options = options._attr if options.kind_of?(TM::TemporalPosition)
|
565
|
+
options[:frame] ||= 'Gregorian'
|
566
|
+
options[:frame] = Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
|
567
|
+
options[:clock] ||= Clock(time.utc_offset) if time.kind_of?(::Time)
|
568
|
+
jdt = TM::JulianDate.universal_time(time.to_f * TM::IntervalLength::SECOND, {:frame=>TM::Clock.get_clock(options)})
|
569
|
+
options[:clock] = jdt.frame
|
570
|
+
date = options[:frame].jul_trans(jdt, options)
|
571
|
+
date = TM::CalDate.new(date.cal_date, options) if options[:precision] &&
|
572
|
+
options[:precision] <= DAY
|
573
|
+
return date
|
574
|
+
end
|
575
|
+
|
576
|
+
# 現在日時に対応する When::TM::TemporalPosition の生成
|
577
|
+
# (When::TM::DateAndTime of now)
|
578
|
+
# @note メソッド実行時の「現在日時」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
|
579
|
+
#
|
580
|
+
# @param [Hash] options 暦法や時法などの指定
|
581
|
+
# @see When::TM::TemporalPosition._instance
|
582
|
+
#
|
583
|
+
# @return [When::TM::DateAndTime]
|
584
|
+
#
|
585
|
+
def now(options={})
|
586
|
+
When.at(Time.now, options)
|
587
|
+
end
|
588
|
+
|
589
|
+
# 本日に対応する When::TM::CalDate の生成
|
590
|
+
# (When::TM::CalDate of today)
|
591
|
+
# @note メソッド実行時の「本日」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
|
592
|
+
# @note options で時間帯を指定しても「本日」の決定に使用するのみで、戻り値には反映されない
|
593
|
+
#
|
594
|
+
# @param [Hash] options 暦法や時法などの指定
|
595
|
+
# @see When::TM::TemporalPosition._instance
|
596
|
+
#
|
597
|
+
# @return [When::TM::CalDate]
|
598
|
+
#
|
599
|
+
def today(options={})
|
600
|
+
now(options.merge({:precision=>DAY}))
|
601
|
+
end
|
602
|
+
|
603
|
+
# When::TM::Duration の生成
|
604
|
+
#
|
605
|
+
# @param [String] period When.exe Standard Representation として解釈して生成する
|
606
|
+
# @param [Numeric] period When::TM::IntervalLength::SYSTEM 単位の値として解釈して生成する
|
607
|
+
# @param [Array] period 要素を個別に解釈して生成したオブジェクトのArrayを返す
|
608
|
+
# @param [When::TM::Duration] period 処理を行わず、そのまま返す
|
609
|
+
# @param [Hash] options 現時点では未使用
|
610
|
+
#
|
611
|
+
# @return [When::TM::Duration or Array<them>]
|
612
|
+
#
|
613
|
+
def Duration(period, options={})
|
614
|
+
case period
|
615
|
+
when Array
|
616
|
+
period.map {|e| Duration(e, options)}
|
617
|
+
|
618
|
+
when TM::Duration
|
619
|
+
period
|
620
|
+
|
621
|
+
when 0
|
622
|
+
TM::IntervalLength.new(0, 'day')
|
623
|
+
|
624
|
+
when Numeric
|
625
|
+
[TM::Duration::YEAR, TM::Duration::MONTH, TM::Duration::WEEK, TM::Duration::DAY,
|
626
|
+
TM::Duration::HOUR, TM::Duration::MINUTE, TM::Duration::SECOND].each do |unit|
|
627
|
+
div, mod = period.divmod(unit)
|
628
|
+
return TM::IntervalLength.new(div, TM::Duration::Unit.invert[unit]) if mod == 0
|
629
|
+
end
|
630
|
+
TM::IntervalLength.new(period, 'system')
|
631
|
+
|
632
|
+
when String
|
633
|
+
# IntervalLength
|
634
|
+
args = TM::IntervalLength._to_array(period)
|
635
|
+
return TM::IntervalLength.new(*args) if args
|
636
|
+
|
637
|
+
# PeriodDuration
|
638
|
+
sign, *args = TM::PeriodDuration._to_array(period)
|
639
|
+
raise TypeError, "Argument 'period' is not a Duration" unless (sign)
|
640
|
+
args << options
|
641
|
+
duration = TM::PeriodDuration.new(*args)
|
642
|
+
return (sign >= 0) ? duration : -duration
|
643
|
+
|
644
|
+
else
|
645
|
+
nil
|
646
|
+
end
|
647
|
+
end
|
648
|
+
|
649
|
+
# When::TM::Calendar の生成/参照
|
650
|
+
#
|
651
|
+
# @param [String] calendar 暦法を表す文字列
|
652
|
+
#
|
653
|
+
# @return [When::TM::Calendar] calendar に対応する When::TM::Calendar オブジェクト
|
654
|
+
#
|
655
|
+
def Calendar(calendar)
|
656
|
+
Parts::Resource._instance(calendar, '_c:')
|
657
|
+
end
|
658
|
+
|
659
|
+
# When::CalendarNote の生成/参照
|
660
|
+
#
|
661
|
+
# @param [String] note 暦注リストを表す文字列
|
662
|
+
#
|
663
|
+
# @return [When::CalendarNote] note に対応する When::CalendarNote オブジェクト
|
664
|
+
#
|
665
|
+
def CalendarNote(note)
|
666
|
+
Parts::Resource._instance(note, '_n:')
|
667
|
+
end
|
668
|
+
|
669
|
+
# When::TM::CalendarEra の生成/参照
|
670
|
+
#
|
671
|
+
# @param [String] era 暦年代を表す文字列
|
672
|
+
#
|
673
|
+
# @return [When::TM::CalendarEra] era に対応する When::TM::CalendarEra オブジェクト
|
674
|
+
#
|
675
|
+
def CalendarEra(era)
|
676
|
+
Parts::Resource._instance(era, '_e:') do |iri|
|
677
|
+
TM::CalendarEra.send(:_behalf_of, iri)
|
678
|
+
end
|
679
|
+
end
|
680
|
+
|
681
|
+
# When::TM::CalendarEra の検索
|
682
|
+
#
|
683
|
+
# @overload era(key, epoch=nil, reverse=nil, options={})
|
684
|
+
# @param [String, Regexp] key 検索する暦年代または、暦年代にマッチする正規表現
|
685
|
+
# @param [Integer] epoch 年数を昇順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
|
686
|
+
# @param [Integer] reverse 年数を降順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
|
687
|
+
# @param [Hash] options 以下の通り
|
688
|
+
# @option options [String] :area 暦年代の使用地域の指定(デフォルトは nil - 指定なし)
|
689
|
+
# @option options [String] :period 暦年代の使用時代の指定(デフォルトは nil - 指定なし)
|
690
|
+
# @option options [Integer] :count 何件ヒットするまで検索するかを指定(デフォルトは 1件)
|
691
|
+
# @option options [String] the_others 例えば When::TM::CalendarEra オブジェクトの epoch_of_use に 'name' などの
|
692
|
+
# 指定がある場合、:name に指定しておけば、検索での絞り込みに使用できる。
|
693
|
+
#
|
694
|
+
# @return [Array<When::TM::CalendarEra>] 検索結果を When::TM::CalendarEra オブジェクトの Array で返す
|
695
|
+
# @note ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを生成しつつ読み込んで検索する。
|
696
|
+
#
|
697
|
+
def era(*args)
|
698
|
+
TM::CalendarEra._instance(*args)
|
699
|
+
end
|
700
|
+
|
701
|
+
# When::TM::Clock の生成/参照
|
702
|
+
#
|
703
|
+
# @param [When::Parts::Timezone::Base] clock なにもせず clock をそのまま返す
|
704
|
+
# @param [String] clock 時法を表す文字列
|
705
|
+
# @param [Numeric] clock 秒を単位として表した時差(東経側を + とする)
|
706
|
+
#
|
707
|
+
# @return [When::Parts::Timezone::Base] 生成/参照した When::Parts::Timezone::Base オブジェクト
|
708
|
+
#
|
709
|
+
def Clock(clock)
|
710
|
+
case clock
|
711
|
+
when Parts::Timezone::Base ; return clock
|
712
|
+
when 'Z', 0 ; return UTC
|
713
|
+
when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock))
|
714
|
+
when /\A#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock)
|
715
|
+
when String ;
|
716
|
+
else ; raise TypeError, "Invalid Type: #{clock.class}"
|
717
|
+
end
|
718
|
+
c = TM::Clock[clock] || V::Timezone[clock]
|
719
|
+
return c if c
|
720
|
+
clock, options = clock.split('?')
|
721
|
+
hms = TM::Clock.to_hms(clock)
|
722
|
+
return Parts::Timezone[clock] unless hms
|
723
|
+
iri = "_tm:Clock?label=" + hms
|
724
|
+
iri += "&" + options if options
|
725
|
+
Parts::Resource._instance(iri)
|
726
|
+
end
|
727
|
+
|
728
|
+
# When::Coordinates::Spatial の生成/参照
|
729
|
+
#
|
730
|
+
# @overload Location(location)
|
731
|
+
# @param [When::Coordinates::Spatial] location なにもせず location をそのまま返す
|
732
|
+
# @param [String] location 空間位置の IRI (デフォルトプレフィクス _l:)
|
733
|
+
# @param [When::Parts::Timezone] 代表する都市の時間帯
|
734
|
+
#
|
735
|
+
# @overload Location(longitude, latitide, altitide=0, datum='Earth')
|
736
|
+
# @param [Numeric] longitude 経度 / 度 (東経を正とする)
|
737
|
+
# @param [Numeric] latitide 緯度 / 度 (北緯を正とする)
|
738
|
+
# @param [Numeric] altitide 高度 / m
|
739
|
+
# @param [When::Ephemeris::Datum] datum 座標系
|
740
|
+
# @param [String] datum 座標系の IRI (デフォルトプレフィクス _ep:)
|
741
|
+
#
|
742
|
+
# @note longitudeが経度を意味する文字列, latitude が緯度を意味する文字列の場合、
|
743
|
+
# 引数の順番によらず、それぞれ経度および緯度と解釈する
|
744
|
+
#
|
745
|
+
# @return [When::Coordinates::Spatial] 生成/参照した When::Coordinates::Spatial オブジェクト
|
746
|
+
#
|
747
|
+
def Location(*args)
|
748
|
+
case args[0]
|
749
|
+
when Coordinates::Spatial ; return args[0]
|
750
|
+
when Parts::Timezone ; return args[0].location
|
751
|
+
when String ; return Parts::Resource._instance(args[0], '_l:') if args.size == 1
|
752
|
+
when Numeric ;
|
753
|
+
else ; raise TypeError, "Invalid Type: #{args[0].class}"
|
754
|
+
end
|
755
|
+
rest = []
|
756
|
+
longitude = latitude = nil
|
757
|
+
args.each do |arg|
|
758
|
+
case arg
|
759
|
+
when /\A#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}\z/; longitude = arg
|
760
|
+
when /\A#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}\z/; latitude = arg
|
761
|
+
else ; rest << arg
|
762
|
+
end
|
763
|
+
end
|
764
|
+
longitude ||= rest.shift
|
765
|
+
latitude ||= rest.shift
|
766
|
+
raise ArgumentError, "too few arguments" unless longitude && latitude
|
767
|
+
altitude, datum = rest
|
768
|
+
iri = "_l:long=#{longitude}&lat=#{latitude}"
|
769
|
+
iri += "&alt=#{altitude}" if altitude
|
770
|
+
iri += "&datum=#{datum}" if datum
|
771
|
+
Parts::Resource._instance(iri)
|
772
|
+
end
|
773
|
+
|
774
|
+
# When::Coordinates::Border の生成/参照
|
775
|
+
#
|
776
|
+
# @param [String] border 年/日境界を表す文字列
|
777
|
+
#
|
778
|
+
# @return [When::Coordinates::Border] border に対応する When::Coordinates::Border オブジェクト
|
779
|
+
#
|
780
|
+
def Border(border)
|
781
|
+
case border
|
782
|
+
when Coordinates::Border ; return border
|
783
|
+
when /\([-\d]+?\)/ ; border = "_co:MultiBorder?borders=#{border}"
|
784
|
+
when /\A[^A-Z_]/i ; border = "_co:Border?border=#{border}"
|
785
|
+
end
|
786
|
+
|
787
|
+
Parts::Resource._instance(border, '_co:') do |iri|
|
788
|
+
Coordinates::CalendarBorder.send(:_behalf_of, iri)
|
789
|
+
end
|
790
|
+
end
|
791
|
+
|
792
|
+
#
|
793
|
+
# 曜日(剰余類)
|
794
|
+
#
|
795
|
+
# @param [Numeric] day 月曜を 0 とする七曜(剰余類)を返します
|
796
|
+
# @param [String] day 最初の3文字から決定した七曜(剰余類)を返します。
|
797
|
+
# 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
|
798
|
+
#
|
799
|
+
# @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類) または 名前の一致するその他の剰余類
|
800
|
+
#
|
801
|
+
def Residue(day)
|
802
|
+
When::Coordinates::Residue.to_residue(day)
|
803
|
+
end
|
804
|
+
alias :day_of_week :Residue
|
805
|
+
|
806
|
+
#
|
807
|
+
# 月名
|
808
|
+
#
|
809
|
+
# @param [Numeric] name 指定の月番号の月名を返します
|
810
|
+
# @param [String] name 最初の3文字から決定した月名を返します。
|
811
|
+
# 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
|
812
|
+
# (name が M17n なら name 自身をそのまま返します)
|
813
|
+
#
|
814
|
+
# @return [When::BasicTypes::M17n] 月名
|
815
|
+
#
|
816
|
+
def MonthName(name)
|
817
|
+
When::BasicTypes::M17n.month_name(name)
|
818
|
+
end
|
819
|
+
|
820
|
+
# When::BasicTypes::M17n の生成/参照
|
821
|
+
#
|
822
|
+
# @param [String] source 多言語対応文字列のIRI
|
823
|
+
#
|
824
|
+
# @return [When::BasicTypes::M17n] source に対応する When::BasicTypes::M17n オブジェクト
|
825
|
+
#
|
826
|
+
def M17n(source)
|
827
|
+
Parts::Resource._instance(source, '_m:')
|
828
|
+
end
|
829
|
+
|
830
|
+
# When::BasicTypes::M17n の生成/参照
|
831
|
+
#
|
832
|
+
# @param [When::BasicTypes::M17n] source 処理を行わず、そのままsourceを返す
|
833
|
+
# @param [String] source locale と 文字列の対応
|
834
|
+
# @param [Array] source 要素を個別に解釈して生成したオブジェクトのArrayを返す
|
835
|
+
# @param [Hash] namespace prefix の指定
|
836
|
+
# @param [Array] locale locale の定義順序の指定
|
837
|
+
# @param [Hash] options (see {When::BasicTypes::M17n.new}[link:When/BasicTypes/M17n.html#method-c-new])
|
838
|
+
#
|
839
|
+
# @return [When::BasicTypes::M17n or Array<them>]
|
840
|
+
#
|
841
|
+
def m17n(source, namespace=nil, locale=nil, options={})
|
842
|
+
case source
|
843
|
+
when Array ; BasicTypes::M17n.new(source, namespace, locale, options)
|
844
|
+
when BasicTypes::M17n ; source
|
845
|
+
when String
|
846
|
+
source = EncodingConversion.to_internal_encoding(source)
|
847
|
+
return self[$1] if source =~ /\A\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource)
|
848
|
+
return Parts::Resource[$1] if source =~ /\A\s*\[::([^\]]+)\]/
|
849
|
+
BasicTypes::M17n.new(source, namespace, locale, options)
|
850
|
+
else ; raise TypeError, "Invalid Type: #{source.class}"
|
851
|
+
end
|
852
|
+
end
|
853
|
+
|
854
|
+
# Wikipedia を参照して When::BasicTypes::M17n を生成する
|
855
|
+
#
|
856
|
+
# @param [String] title Wikipedia の項目名
|
857
|
+
# @param [Hash] options 以下の通り
|
858
|
+
# @option options [String] :locale Wikipedia の言語(デフォルト 'en' - 英語)
|
859
|
+
# @option options [Numeric, nil] :interval Wikipedia サイトへのアクセス制御(デフォルト When::Locale.wikipedia_interval)
|
860
|
+
# @option options [Object] :その他 キャッシュファイルへの追加書き出し要素
|
861
|
+
#
|
862
|
+
# @return [When::BasicTypes::M17n] 項目に対応する多言語対応文字列
|
863
|
+
#
|
864
|
+
# @note 生成した多言語対応文字列の what が nil でない場合、
|
865
|
+
# その項目の位置情報を表わす When::Coordinates::Spatial を指す
|
866
|
+
#
|
867
|
+
def Wikipedia(title, options={})
|
868
|
+
locale = options.delete(:locale) || 'en'
|
869
|
+
title = EncodingConversion.to_internal_encoding(title)
|
870
|
+
entry, query = title.split('?', 2)
|
871
|
+
url = "http://#{locale}.wikipedia.org/wiki/#{URI.encode(entry).gsub(' ', '_')}"
|
872
|
+
Locale.send(:wikipedia_object, url, options) unless options.empty?
|
873
|
+
url += '?' + query if query
|
874
|
+
object = Parts::Resource._instance(url)
|
875
|
+
object.to_m17n
|
876
|
+
end
|
877
|
+
|
878
|
+
# When::Parts::Resource の生成/参照
|
879
|
+
#
|
880
|
+
# @param [String] iri IRI を表す文字列
|
881
|
+
# @param [String] namespace デフォルトの namespace
|
882
|
+
#
|
883
|
+
# @return [When::Parts::Resourc] iri (または namespace:iri) に対応する When::Parts::Resource オブジェクト
|
884
|
+
#
|
885
|
+
def Resource(iri, namespace=nil)
|
886
|
+
Parts::Resource._instance(iri, namespace)
|
887
|
+
end
|
888
|
+
alias :IRI :Resource
|
889
|
+
|
890
|
+
# When::Coordinates::Index の生成
|
891
|
+
#
|
892
|
+
# @overload Index(terms=nil, name='Month', options)
|
893
|
+
# @param [String] terms trunk の用語空間名
|
894
|
+
# @param [String] name trunk の要素配列名
|
895
|
+
# @param [Hash] options
|
896
|
+
# @option options [Array] :trunk 幹の要素(省略時は使用しない)
|
897
|
+
# @option options [Hash] :branch 枝の要素(省略時は使用しない)
|
898
|
+
# @option options [Integer] :unit 要素の数(省略時は不定)
|
899
|
+
# @option options [Integer] :base 要素の最初の添え字(0 or 1(デフォルト))
|
900
|
+
# @option options [Integer] :shift 幹の要素のローテート数(省略時はローテートしない)
|
901
|
+
#
|
902
|
+
# @return [When::Coordinates::Index]
|
903
|
+
#
|
904
|
+
def Index(*args)
|
905
|
+
Coordinates::Index.new(*args)
|
906
|
+
end
|
907
|
+
|
908
|
+
# When::Coordinates::Pair の生成
|
909
|
+
#
|
910
|
+
# @param [Numeric, String] trunk 幹の要素
|
911
|
+
# @param [Numeric, String] branch 枝の要素
|
912
|
+
# @see When::Coordinates::Pair._force_pair
|
913
|
+
#
|
914
|
+
# @return [When::Coordinates::Pair]
|
915
|
+
#
|
916
|
+
def Pair(trunk, branch=nil)
|
917
|
+
Coordinates::Pair._force_pair(trunk, branch)
|
918
|
+
end
|
919
|
+
|
920
|
+
# When 直下に定数として時法・暦法を定義する
|
921
|
+
_define_common_calendar_types
|
922
|
+
|
923
|
+
end
|