when_exe 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/locales.rb +2 -2
- data/bin/when.rb +2 -2
- data/lib/when_exe.rb +161 -55
- data/lib/when_exe/basictypes.rb +34 -26
- data/lib/when_exe/calendarnote.rb +654 -0
- data/lib/when_exe/calendartypes.rb +49 -474
- data/lib/when_exe/coordinates.rb +141 -34
- data/lib/when_exe/core/compatibility.rb +22 -2
- data/lib/when_exe/core/extension.rb +47 -3
- data/lib/when_exe/ephemeris.rb +82 -109
- data/lib/when_exe/googlecalendar.rb +1 -1
- data/lib/when_exe/icalendar.rb +26 -14
- data/lib/when_exe/inspect.rb +82 -68
- data/lib/when_exe/locales/af.rb +1 -1
- data/lib/when_exe/locales/ar.rb +1 -1
- data/lib/when_exe/locales/az.rb +1 -1
- data/lib/when_exe/locales/bg.rb +1 -1
- data/lib/when_exe/locales/bn.rb +1 -1
- data/lib/when_exe/locales/bs.rb +1 -1
- data/lib/when_exe/locales/ca.rb +1 -1
- data/lib/when_exe/locales/cs.rb +1 -1
- data/lib/when_exe/locales/cy.rb +1 -1
- data/lib/when_exe/locales/da.rb +1 -1
- data/lib/when_exe/locales/de.rb +1 -1
- data/lib/when_exe/locales/de_AT.rb +1 -1
- data/lib/when_exe/locales/de_CH.rb +1 -1
- data/lib/when_exe/locales/el.rb +1 -1
- data/lib/when_exe/locales/en.rb +1 -1
- data/lib/when_exe/locales/en_AU.rb +1 -1
- data/lib/when_exe/locales/en_CA.rb +1 -1
- data/lib/when_exe/locales/en_GB.rb +1 -1
- data/lib/when_exe/locales/en_IE.rb +1 -1
- data/lib/when_exe/locales/en_IN.rb +1 -1
- data/lib/when_exe/locales/en_NZ.rb +1 -1
- data/lib/when_exe/locales/en_US.rb +1 -1
- data/lib/when_exe/locales/eo.rb +1 -1
- data/lib/when_exe/locales/es.rb +1 -1
- data/lib/when_exe/locales/es_419.rb +1 -1
- data/lib/when_exe/locales/es_AR.rb +1 -1
- data/lib/when_exe/locales/es_CL.rb +1 -1
- data/lib/when_exe/locales/es_CO.rb +1 -1
- data/lib/when_exe/locales/es_CR.rb +1 -1
- data/lib/when_exe/locales/es_EC.rb +1 -1
- data/lib/when_exe/locales/es_MX.rb +1 -1
- data/lib/when_exe/locales/es_PA.rb +1 -1
- data/lib/when_exe/locales/es_PE.rb +1 -1
- data/lib/when_exe/locales/es_VE.rb +1 -1
- data/lib/when_exe/locales/et.rb +1 -1
- data/lib/when_exe/locales/eu.rb +1 -1
- data/lib/when_exe/locales/fa.rb +1 -1
- data/lib/when_exe/locales/fi.rb +1 -1
- data/lib/when_exe/locales/fr.rb +1 -1
- data/lib/when_exe/locales/fr_CA.rb +1 -1
- data/lib/when_exe/locales/fr_CH.rb +1 -1
- data/lib/when_exe/locales/gl.rb +1 -1
- data/lib/when_exe/locales/he.rb +1 -1
- data/lib/when_exe/locales/hi.rb +1 -1
- data/lib/when_exe/locales/hi_IN.rb +1 -1
- data/lib/when_exe/locales/hr.rb +1 -1
- data/lib/when_exe/locales/hu.rb +1 -1
- data/lib/when_exe/locales/id.rb +1 -1
- data/lib/when_exe/locales/is.rb +1 -1
- data/lib/when_exe/locales/it.rb +1 -1
- data/lib/when_exe/locales/it_CH.rb +1 -1
- data/lib/when_exe/locales/ja.rb +1 -1
- data/lib/when_exe/locales/kn.rb +1 -1
- data/lib/when_exe/locales/ko.rb +1 -1
- data/lib/when_exe/locales/lo.rb +1 -1
- data/lib/when_exe/locales/locales.rb +1 -1
- data/lib/when_exe/locales/lt.rb +1 -1
- data/lib/when_exe/locales/lv.rb +1 -1
- data/lib/when_exe/locales/mk.rb +1 -1
- data/lib/when_exe/locales/mn.rb +1 -1
- data/lib/when_exe/locales/ms.rb +1 -1
- data/lib/when_exe/locales/nb.rb +1 -1
- data/lib/when_exe/locales/ne.rb +1 -1
- data/lib/when_exe/locales/nl.rb +1 -1
- data/lib/when_exe/locales/nn.rb +1 -1
- data/lib/when_exe/locales/or.rb +1 -1
- data/lib/when_exe/locales/pl.rb +1 -1
- data/lib/when_exe/locales/pt.rb +1 -1
- data/lib/when_exe/locales/pt_BR.rb +1 -1
- data/lib/when_exe/locales/rm.rb +1 -1
- data/lib/when_exe/locales/ro.rb +1 -1
- data/lib/when_exe/locales/ru.rb +1 -1
- data/lib/when_exe/locales/sk.rb +1 -1
- data/lib/when_exe/locales/sl.rb +1 -1
- data/lib/when_exe/locales/sr.rb +1 -1
- data/lib/when_exe/locales/sv.rb +1 -1
- data/lib/when_exe/locales/sw.rb +1 -1
- data/lib/when_exe/locales/th.rb +1 -1
- data/lib/when_exe/locales/tl.rb +1 -1
- data/lib/when_exe/locales/tr.rb +1 -1
- data/lib/when_exe/locales/uk.rb +1 -1
- data/lib/when_exe/locales/ur.rb +1 -1
- data/lib/when_exe/locales/uz.rb +1 -1
- data/lib/when_exe/locales/vi.rb +1 -1
- data/lib/when_exe/locales/wo.rb +1 -1
- data/lib/when_exe/locales/zh_CN.rb +1 -1
- data/lib/when_exe/locales/zh_HK.rb +1 -1
- data/lib/when_exe/locales/zh_TW.rb +1 -1
- data/lib/when_exe/mini_application.rb +6 -2
- data/lib/when_exe/parts/enumerator.rb +13 -8
- data/lib/when_exe/parts/geometric_complex.rb +3 -5
- data/lib/when_exe/parts/locale.rb +185 -28
- data/lib/when_exe/parts/method_cash.rb +20 -10
- data/lib/when_exe/parts/resource.rb +154 -76
- data/lib/when_exe/parts/timezone.rb +11 -6
- data/lib/when_exe/region/bahai.rb +2 -2
- data/lib/when_exe/region/balinese.rb +296 -296
- data/lib/when_exe/region/chinese.rb +564 -564
- data/lib/when_exe/region/chinese_calendar.rb +5 -1
- data/lib/when_exe/region/chinese_epoch.rb +47 -102
- data/lib/when_exe/region/chinese_twin.rb +798 -0
- data/lib/when_exe/region/christian.rb +314 -338
- data/lib/when_exe/region/coptic.rb +88 -0
- data/lib/when_exe/region/ephemeric_notes.rb +322 -307
- data/lib/when_exe/region/french.rb +2 -2
- data/lib/when_exe/region/indian.rb +361 -272
- data/lib/when_exe/region/iranian.rb +2 -2
- data/lib/when_exe/region/islamic.rb +3 -3
- data/lib/when_exe/region/japanese.rb +1 -1
- data/lib/when_exe/region/japanese_notes.rb +165 -103
- data/lib/when_exe/region/japanese_residues.rb +56 -55
- data/lib/when_exe/region/japanese_twin.rb +228 -0
- data/lib/when_exe/region/javanese.rb +2 -2
- data/lib/when_exe/region/jewish.rb +2 -2
- data/lib/when_exe/region/korean.rb +4 -4
- data/lib/when_exe/region/m17n.rb +19 -19
- data/lib/when_exe/region/martian.rb +21 -9
- data/lib/when_exe/region/mayan.rb +19 -11
- data/lib/when_exe/region/moon.rb +7 -7
- data/lib/when_exe/region/nihon_shoki.rb +7 -7
- data/lib/when_exe/region/roman.rb +100 -100
- data/lib/when_exe/region/shire.rb +130 -147
- data/lib/when_exe/region/thai.rb +2 -2
- data/lib/when_exe/region/tibetan.rb +2 -2
- data/lib/when_exe/region/vietnamese.rb +383 -114
- data/lib/when_exe/region/world.rb +112 -129
- data/lib/when_exe/timestandard.rb +12 -1
- data/lib/when_exe/tmposition.rb +28 -14
- data/lib/when_exe/tmreference.rb +96 -93
- data/lib/when_exe/version.rb +1 -1
- data/test/examples/Terms.m17n +2 -2
- data/test/examples/sample.json +16 -0
- data/test/examples/sample.xml +1 -1
- data/test/test.rb +4 -0
- data/test/test/basictypes.rb +2 -2
- data/test/test/calendarnote.rb +69 -0
- data/test/test/calendartypes.rb +41 -1
- data/test/test/coordinates.rb +12 -1
- data/test/test/ephemeris.rb +13 -66
- data/test/test/icalendar.rb +3 -3
- data/test/test/inspect.rb +1 -1
- data/test/test/parts.rb +7 -4
- data/test/test/region/chinese.rb +45 -0
- data/test/test/region/coptic.rb +27 -0
- data/test/test/region/indian.rb +1 -1
- data/test/test/region/japanese.rb +4 -4
- data/test/test/region/jewish.rb +1 -1
- data/test/test/region/m17n.rb +7 -5
- data/test/test/region/residue.rb +2 -2
- data/test/test/region/vietnamese.rb +102 -0
- data/test/test/timestandard.rb +81 -0
- data/test/test/tmposition.rb +1 -1
- data/test/test/tmreference.rb +1 -1
- data/when_exe.gemspec +2 -2
- metadata +16 -7
data/bin/locales.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
=begin
|
4
|
-
Copyright (C) 2011-
|
4
|
+
Copyright (C) 2011-2014 Takashi SUGA
|
5
5
|
|
6
6
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
7
7
|
=end
|
@@ -14,7 +14,7 @@ require 'net/https'
|
|
14
14
|
HEADER = <<HEADER
|
15
15
|
# -*- coding: utf-8 -*-
|
16
16
|
=begin
|
17
|
-
Copyright (C) 2012-
|
17
|
+
Copyright (C) 2012-2014 Takashi SUGA
|
18
18
|
|
19
19
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
20
20
|
=end
|
data/bin/when.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
=begin
|
4
|
-
Copyright (C) 2011-
|
4
|
+
Copyright (C) 2011-2014 Takashi SUGA
|
5
5
|
|
6
6
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
7
7
|
=end
|
@@ -12,5 +12,5 @@ require 'when_exe/mini_application'
|
|
12
12
|
args = ARGV.map {|arg| arg.encode('UTF-8')}
|
13
13
|
config = When.config
|
14
14
|
server, port = config['?']
|
15
|
-
result = !port ? When.free_conv(*args) : args == [] ? When.server(port) : When.client(server, port, args.join(' '))
|
15
|
+
result = !port || !Object.const_defined?(:JSON) ? When.free_conv(*args) : args == [] ? When.server(port) : When.client(server, port, args.join(' '))
|
16
16
|
pp When::Parts::Locale.translate(result, config['!']) if result
|
data/lib/when_exe.rb
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
7
7
|
|
8
|
+
begin
|
9
|
+
require 'json'
|
10
|
+
rescue LoadError
|
11
|
+
end
|
8
12
|
begin
|
9
13
|
require 'rubygems'
|
10
14
|
rescue LoadError
|
@@ -20,12 +24,12 @@ begin
|
|
20
24
|
rescue LoadError, NoMethodError
|
21
25
|
end
|
22
26
|
|
23
|
-
autoload :URI,
|
24
|
-
autoload :OpenURI,
|
25
|
-
autoload :OpenSSL,
|
26
|
-
autoload :
|
27
|
-
autoload :REXML,
|
28
|
-
autoload :Mutex,
|
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)
|
29
33
|
|
30
34
|
$:.unshift(File.dirname(__FILE__)) unless
|
31
35
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
@@ -46,8 +50,8 @@ module When
|
|
46
50
|
|
47
51
|
# Initializations
|
48
52
|
#
|
49
|
-
# @param [Hash] options
|
50
|
-
# @option options [When::
|
53
|
+
# @param [Hash] options 以下の通り
|
54
|
+
# @option options [When::Parts::Timezone::Base] :local デフォルトの地方時
|
51
55
|
# @option options [When::Coordinates::Spatial] :location デフォルトの空間位置
|
52
56
|
# @option options [When::TM::IntervalLength] :until V::Event::Enumerator の until
|
53
57
|
# @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
|
@@ -55,9 +59,13 @@ module When
|
|
55
59
|
# @option options [Array<String>] :order CalendarEra の検索順序 ([ IRI of When::TM::CalendarEra ])
|
56
60
|
# @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
|
57
61
|
# @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
|
62
|
+
# @option options [String] :base_uri Base URI for When_exe Resources (Default When::SourceURI)
|
63
|
+
# @option options [String] :root_dir Root Directory for When_exe Resources Cash data (Default When::RootDir)
|
58
64
|
# @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
|
59
65
|
# @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
|
60
66
|
# @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
|
67
|
+
# @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
|
68
|
+
# @option options [true] :escape すべて毎回 method_missing を発生させる
|
61
69
|
#
|
62
70
|
# @return [void]
|
63
71
|
#
|
@@ -67,8 +75,8 @@ module When
|
|
67
75
|
#
|
68
76
|
def _setup_(options={})
|
69
77
|
@multi_thread = options[:multi_thread]
|
70
|
-
Parts::MethodCash._setup_(options
|
71
|
-
Parts::Resource._setup_
|
78
|
+
Parts::MethodCash._setup_(options)
|
79
|
+
Parts::Resource._setup_(options)
|
72
80
|
Parts::Locale._setup_(options)
|
73
81
|
Coordinates::Spatial._setup_(options[:location])
|
74
82
|
TM::CalendarEra._setup_(options[:order])
|
@@ -80,10 +88,35 @@ module When
|
|
80
88
|
Parts::Timezone._setup_
|
81
89
|
TimeStandard._setup_(options[:leap_seconds])
|
82
90
|
end
|
91
|
+
|
92
|
+
# 設定情報を取得する
|
93
|
+
#
|
94
|
+
# @return [Hash] 設定情報
|
95
|
+
#
|
96
|
+
def _setup_info
|
97
|
+
{:multi_thread => @multi_thread}.
|
98
|
+
update(Parts::MethodCash._setup_info).
|
99
|
+
update(Parts::Resource._setup_info).
|
100
|
+
update(Parts::Locale._setup_info).
|
101
|
+
update(Coordinates::Spatial._setup_info).
|
102
|
+
update(TM::CalendarEra._setup_info).
|
103
|
+
update(TM::Clock._setup_info).
|
104
|
+
update(TM::TemporalPosition._setup_info).
|
105
|
+
update(V::Event._setup_info).
|
106
|
+
update(TimeStandard._setup_info)
|
107
|
+
end
|
83
108
|
end
|
84
109
|
|
110
|
+
#
|
111
|
+
# when_exe 用 International Resource Identifier
|
112
|
+
#
|
85
113
|
SourceURI = "http://hosi.org/When/"
|
86
114
|
|
115
|
+
#
|
116
|
+
# ライブラリのあるディレクトリ
|
117
|
+
#
|
118
|
+
RootDir = File.dirname(__FILE__).sub(/\/[^\/]*$/,'')
|
119
|
+
|
87
120
|
require 'when_exe/version'
|
88
121
|
require 'when_exe/parts/enumerator'
|
89
122
|
require 'when_exe/parts/locale'
|
@@ -102,6 +135,7 @@ module When
|
|
102
135
|
require 'when_exe/tmposition'
|
103
136
|
require 'when_exe/tmreference'
|
104
137
|
require 'when_exe/calendartypes'
|
138
|
+
require 'when_exe/calendarnote'
|
105
139
|
require 'when_exe/locales/locales'
|
106
140
|
require 'when_exe/region/m17n'
|
107
141
|
require 'when_exe/region/residue'
|
@@ -138,7 +172,7 @@ module When
|
|
138
172
|
autoload :IslamicTerms, 'when_exe/region/islamic'
|
139
173
|
autoload :JewishTerms, 'when_exe/region/jewish'
|
140
174
|
autoload :RomanTerms, 'when_exe/region/roman'
|
141
|
-
autoload :
|
175
|
+
autoload :CopticTerms, 'when_exe/region/coptic'
|
142
176
|
autoload :FrenchTerms, 'when_exe/region/french'
|
143
177
|
autoload :WorldTerms, 'when_exe/region/world'
|
144
178
|
autoload :ShireTerms, 'when_exe/region/shire'
|
@@ -148,9 +182,10 @@ module When
|
|
148
182
|
|
149
183
|
module CalendarTypes
|
150
184
|
autoload :Japanese, 'when_exe/region/japanese'
|
185
|
+
autoload :JapaneseTwin, 'when_exe/region/japanese_twin'
|
186
|
+
autoload :ChineseTwin, 'when_exe/region/chinese_twin'
|
151
187
|
autoload :ChineseSolar, 'when_exe/region/chinese'
|
152
188
|
autoload :ChineseLuniSolar, 'when_exe/region/chinese'
|
153
|
-
autoload :Chinese, 'when_exe/region/chinese'
|
154
189
|
autoload :Yi, 'when_exe/region/chinese'
|
155
190
|
autoload :Tibetan, 'when_exe/region/tibetan'
|
156
191
|
autoload :ThaiB, 'when_exe/region/thai'
|
@@ -165,6 +200,7 @@ module When
|
|
165
200
|
autoload :TabularIslamic, 'when_exe/region/islamic'
|
166
201
|
autoload :EphemerisBasedIslamic, 'when_exe/region/islamic'
|
167
202
|
autoload :Jewish, 'when_exe/region/jewish'
|
203
|
+
autoload :Coptic, 'when_exe/region/coptic'
|
168
204
|
autoload :JulianA, 'when_exe/region/roman'
|
169
205
|
autoload :JulianB, 'when_exe/region/roman'
|
170
206
|
autoload :JulianC, 'when_exe/region/roman'
|
@@ -186,28 +222,28 @@ module When
|
|
186
222
|
_time_systems.each_pair do |key, required|
|
187
223
|
autoload key.to_sym, required if required
|
188
224
|
end
|
225
|
+
end
|
189
226
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
end
|
227
|
+
class CalendarNote
|
228
|
+
autoload :SolarTerms, 'when_exe/region/ephemeric_notes'
|
229
|
+
autoload :LunarPhases, 'when_exe/region/ephemeric_notes'
|
230
|
+
autoload :EphemericNote, 'when_exe/region/ephemeric_notes'
|
231
|
+
autoload :JapaneseNote, 'when_exe/region/japanese_notes'
|
232
|
+
autoload :BalineseNote, 'when_exe/region/balinese'
|
233
|
+
autoload :RomanNote, 'when_exe/region/roman'
|
234
|
+
autoload :WorldWeek, 'when_exe/region/world'
|
235
|
+
autoload :ShireWeek, 'when_exe/region/shire'
|
236
|
+
|
237
|
+
DefaultNotes = [['_m:CalendarTerms::Month'], ['CommonResidue::Week']]
|
238
|
+
JulianDayNotes = [['CommonResidue::Week', 'CommonResidue::干支']]
|
239
|
+
BahaiNotes = [['Bahai::YearName'], ['_m:BahaiTerms::Month'], ['CommonResidue::Week']]
|
240
|
+
JavaneseNotes = [['Javanese::Windu'], ['_m:CalendarTerms::Month'],
|
241
|
+
['Javanese::Pasaran', 'Javanese::Paringkelan', 'Javanese::Week', 'Javanese::Wuku']]
|
242
|
+
ChineseNotes = [['CommonResidue::干支'], ['_m:CalendarTerms::Month'], ['CommonResidue::Week', 'CommonResidue::干支']]
|
243
|
+
TibetanNotes = [['Tibetan::干支'], ['_m:CalendarTerms::Month'], ['CommonResidue::Week']]
|
244
|
+
YiNotes = [['Yi::YearName'], ['_m:CalendarTerms::Month'], ['CommonResidue::Week']]
|
245
|
+
MayanNotes = [{},['Mayan#{?Epoch=Epoch}::Trecena', 'Mayan#{?Epoch=Epoch}::Tzolk\'in',
|
246
|
+
'Mayan#{?Epoch=Epoch}::Lords_of_the_Night', 'Mayan#{?Epoch=Epoch}::Haab\'']]
|
211
247
|
end
|
212
248
|
|
213
249
|
module Coordinates
|
@@ -246,11 +282,11 @@ module When
|
|
246
282
|
autoload :JapanesePrimeMinister, 'when_exe/region/japanese'
|
247
283
|
autoload :NihonKoki, 'when_exe/region/nihon_shoki'
|
248
284
|
autoload :NihonShoki, 'when_exe/region/nihon_shoki'
|
249
|
-
autoload :JapaneseSolarSeries, 'when_exe/region/
|
250
|
-
autoload :JapaneseLuniSolarSeries, 'when_exe/region/
|
285
|
+
autoload :JapaneseSolarSeries, 'when_exe/region/japanese_twin'
|
286
|
+
autoload :JapaneseLuniSolarSeries, 'when_exe/region/japanese_twin'
|
251
287
|
autoload :Chinese, 'when_exe/region/chinese_epoch'
|
252
|
-
autoload :ChineseSolarSeries, 'when_exe/region/
|
253
|
-
autoload :ChineseLuniSolarSeries, 'when_exe/region/
|
288
|
+
autoload :ChineseSolarSeries, 'when_exe/region/chinese_twin'
|
289
|
+
autoload :ChineseLuniSolarSeries, 'when_exe/region/chinese_twin'
|
254
290
|
autoload :Ryukyu, 'when_exe/region/ryukyu'
|
255
291
|
autoload :Korean, 'when_exe/region/korean'
|
256
292
|
autoload :Vietnamese, 'when_exe/region/vietnamese'
|
@@ -274,10 +310,9 @@ module When
|
|
274
310
|
autoload :LongCount, 'when_exe/region/mayan'
|
275
311
|
|
276
312
|
# Defualt search path for Epochs and Eras
|
277
|
-
DefaultEpochs = ['Common', '
|
278
|
-
'IndianNationalSolar', 'Iranian', 'Hijra',
|
279
|
-
'Roman', 'Byzantine', 'French',
|
280
|
-
'LongCount', 'LongCount?Epoch=0D', 'LongCount?Epoch=2D',
|
313
|
+
DefaultEpochs = ['Common', 'ModernJapanese',
|
314
|
+
'IndianNationalSolar', 'Iranian', 'Hijra', 'Jewish',
|
315
|
+
'Roman', 'Byzantine', 'French', 'World', 'LongCount',
|
281
316
|
'BalineseLuniSolar', 'JavaneseLunar',
|
282
317
|
'Japanese', 'JapanesePrimeMinister', 'NihonKoki', 'NihonShoki',
|
283
318
|
'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
|
@@ -512,11 +547,11 @@ module When
|
|
512
547
|
Parts::Resource._instance(calendar, '_c:')
|
513
548
|
end
|
514
549
|
|
515
|
-
# When::
|
550
|
+
# When::CalendarNote の生成/参照
|
516
551
|
#
|
517
552
|
# @param [String] notes 暦注リストを表す文字列
|
518
553
|
#
|
519
|
-
# @return [When::
|
554
|
+
# @return [When::CalendarNote] notes に対応する When::CalendarNote オブジェクト
|
520
555
|
#
|
521
556
|
def CalendarNote(notes)
|
522
557
|
Parts::Resource._instance(notes, '_n:')
|
@@ -538,7 +573,7 @@ module When
|
|
538
573
|
# @param [String, Regexp] key 検索する暦年代または、暦年代にマッチする正規表現
|
539
574
|
# @param [Integer] epoch 年数を昇順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
|
540
575
|
# @param [Integer] reverse 年数を降順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
|
541
|
-
# @param [Hash] options
|
576
|
+
# @param [Hash] options 以下の通り
|
542
577
|
# @option options [String] :area 暦年代の使用地域の指定(デフォルトは nil - 指定なし)
|
543
578
|
# @option options [String] :period 暦年代の使用時代の指定(デフォルトは nil - 指定なし)
|
544
579
|
# @option options [Integer] :count 何件ヒットするまで検索するかを指定(デフォルトは 1件)
|
@@ -554,25 +589,27 @@ module When
|
|
554
589
|
|
555
590
|
# When::TM::Clock の生成/参照
|
556
591
|
#
|
592
|
+
# @param [When::Parts::Timezone::Base] clock なにもせず clock をそのまま返す
|
557
593
|
# @param [String] clock 時法を表す文字列
|
558
594
|
# @param [Numeric] clock 秒を単位として表した時差(東経側を + とする)
|
559
|
-
# @param [When::TM::Clock] clock なにもせず clock をそのまま返す
|
560
595
|
#
|
561
|
-
# @return [When::
|
596
|
+
# @return [When::Parts::Timezone::Base] 生成/参照した When::Parts::Timezone::Base オブジェクト
|
562
597
|
#
|
563
598
|
def Clock(clock)
|
564
599
|
case clock
|
565
|
-
when
|
566
|
-
when 'Z'
|
600
|
+
when Parts::Timezone::Base ; return clock
|
601
|
+
when 'Z', 0 ; return utc
|
602
|
+
when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock))
|
567
603
|
when /^#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock)
|
568
|
-
when
|
569
|
-
|
570
|
-
c = TM::Clock[clock] || V::Timezone[clock]
|
571
|
-
return c if c
|
572
|
-
clock, options = clock.split('?')
|
573
|
-
else ; raise TypeError, "Invalid Type: #{clock.class}"
|
604
|
+
when String ;
|
605
|
+
else ; raise TypeError, "Invalid Type: #{clock.class}"
|
574
606
|
end
|
575
|
-
|
607
|
+
c = TM::Clock[clock] || V::Timezone[clock]
|
608
|
+
return c if c
|
609
|
+
clock, options = clock.split('?')
|
610
|
+
hms = TM::Clock.to_hms(clock)
|
611
|
+
return Parts::Timezone[clock] unless hms
|
612
|
+
iri = "_tm:Clock?label=" + hms
|
576
613
|
iri += "&" + options if options
|
577
614
|
Parts::Resource._instance(iri)
|
578
615
|
end
|
@@ -585,6 +622,52 @@ module When
|
|
585
622
|
Parts::Resource._instance("_c:UTC")
|
586
623
|
end
|
587
624
|
|
625
|
+
# When::Coordinates::Spatial の生成/参照
|
626
|
+
#
|
627
|
+
# @overload Location(location)
|
628
|
+
# @param [When::Coordinates::Spatial] location なにもせず location をそのまま返す
|
629
|
+
# @param [String] location 空間位置の IRI (デフォルトプレフィクス _l:)
|
630
|
+
# @param [When::Parts::Timezone] 代表する都市の時間帯
|
631
|
+
#
|
632
|
+
# @overload Location(longitude, latitide, altitide=0, datum='Earth')
|
633
|
+
# @param [Numeric] longitude 経度 / 度 (東経を正とする)
|
634
|
+
# @param [Numeric] latitide 緯度 / 度 (北緯を正とする)
|
635
|
+
# @param [Numeric] altitide 高度 / m
|
636
|
+
# @param [When::Ephemeris::Datum] datum 座標系
|
637
|
+
# @param [String] datum 座標系の IRI (デフォルトプレフィクス _ep:)
|
638
|
+
#
|
639
|
+
# @note longitudeが経度を意味する文字列, latitude が緯度を意味する文字列の場合、
|
640
|
+
# 引数の順番によらず、それぞれ経度および緯度と解釈する
|
641
|
+
#
|
642
|
+
# @return [When::Coordinates::Spatial] 生成/参照した When::Coordinates::Spatial オブジェクト
|
643
|
+
#
|
644
|
+
def Location(*args)
|
645
|
+
case args[0]
|
646
|
+
when Coordinates::Spatial ; return args[0]
|
647
|
+
when Parts::Timezone ; return args[0].location
|
648
|
+
when String ; return Parts::Resource._instance(args[0], '_l:') if args.size == 1
|
649
|
+
when Numeric ;
|
650
|
+
else ; raise TypeError, "Invalid Type: #{args[0].class}"
|
651
|
+
end
|
652
|
+
rest = []
|
653
|
+
longitude = latitude = nil
|
654
|
+
args.each do |arg|
|
655
|
+
case arg
|
656
|
+
when /^#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}$/; longitude = arg
|
657
|
+
when /^#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}$/; latitude = arg
|
658
|
+
else ; rest << arg
|
659
|
+
end
|
660
|
+
end
|
661
|
+
longitude ||= rest.shift
|
662
|
+
latitude ||= rest.shift
|
663
|
+
raise ArgumentError, "too few arguments" unless longitude && latitude
|
664
|
+
altitude, datum = rest
|
665
|
+
iri = "_l:long=#{longitude}&lat=#{latitude}"
|
666
|
+
iri += "&alt=#{altitude}" if altitude
|
667
|
+
iri += "&datum=#{datum}" if datum
|
668
|
+
Parts::Resource._instance(iri)
|
669
|
+
end
|
670
|
+
|
588
671
|
#
|
589
672
|
# 曜日(剰余類)
|
590
673
|
#
|
@@ -646,6 +729,29 @@ module When
|
|
646
729
|
end
|
647
730
|
end
|
648
731
|
|
732
|
+
# Wikipedia を参照して When::BasicTypes::M17n を生成する
|
733
|
+
#
|
734
|
+
# @param [String] title Wikipedia の項目名
|
735
|
+
# @param [Hash] options 以下の通り
|
736
|
+
# @option options [String] :locale Wikipedia の言語(デフォルト 'en' - 英語)
|
737
|
+
# @option options [Numeric, nil] :interval Wikipedia サイトへのアクセス制御(デフォルト When::Parts::Locale.wikipedia_interval)
|
738
|
+
# @option options [Object] :その他 キャッシュファイルへの追加書き出し要素
|
739
|
+
#
|
740
|
+
# @return [When::BasicTypes::M17n] 項目に対応する多言語対応文字列
|
741
|
+
#
|
742
|
+
# @note 生成した多言語対応文字列の what が nil でない場合、
|
743
|
+
# その項目の位置情報を表わす When::Coordinates::Spatial を指す
|
744
|
+
#
|
745
|
+
def Wikipedia(title, options={})
|
746
|
+
locale = options.delete(:locale) || 'en'
|
747
|
+
entry, query = title.split('?', 2)
|
748
|
+
url = "http://#{locale}.wikipedia.org/wiki/#{URI.encode(entry).gsub(' ', '_')}"
|
749
|
+
Parts::Locale.send(:wikipedia_object, url, options) unless options.empty?
|
750
|
+
url += '?' + query if query
|
751
|
+
object = Parts::Resource._instance(url)
|
752
|
+
object.kind_of?(BasicTypes::M17n) ? object : object.label
|
753
|
+
end
|
754
|
+
|
649
755
|
# When::Parts::Resource の生成/参照
|
650
756
|
#
|
651
757
|
# @param [String] iri IRI を表す文字列
|
data/lib/when_exe/basictypes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-2014 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -23,7 +23,7 @@ module When
|
|
23
23
|
# When.exe Standard Representation 形式の表現を分解してArray化する
|
24
24
|
#
|
25
25
|
# @param [String] date_time 日時を表現する When.exe Standard Representation 形式の文字列
|
26
|
-
# @param [Hash] options
|
26
|
+
# @param [Hash] options 以下の通り
|
27
27
|
# @option options [String, Array<String, Integer>] :era_name デフォルトの年号(Integerは0年に対応する通年)
|
28
28
|
# @option options [Array<Numeric>] :abbr 上位省略形式で使用する上位部分
|
29
29
|
# @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
|
@@ -64,19 +64,19 @@ module When
|
|
64
64
|
|
65
65
|
case date_time
|
66
66
|
# basic date & time format (ISO 8601)
|
67
|
-
when /^([-+W\d]+)(?:(T([.,\d]+)?)([A-Z]
|
67
|
+
when /^([-+W\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?$/
|
68
68
|
d, t, time, clock = $~[1..4]
|
69
69
|
format, date = Date._to_array_basic_ISO8601(d, options)
|
70
70
|
|
71
71
|
# basic date & time format (JIS X0301)
|
72
|
-
when /^([.\d]+)(?:(T([.,\d]+)?)([A-Z]
|
72
|
+
when /^([.\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?$/
|
73
73
|
raise ArgumentError, "Wrong date format" unless options[:era_name]
|
74
74
|
d, t, time, clock = $~[1..4]
|
75
75
|
format, date = Date._to_array_basic_X0301(d, options)
|
76
76
|
era = options[:era_name]
|
77
77
|
|
78
78
|
# basic time format (ISO 8601)
|
79
|
-
when /^(T(-{0,2}[.,\d]+)?)([A-Z]
|
79
|
+
when /^(T(-{0,2}[.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?$/
|
80
80
|
t, time, clock = $~[1..3]
|
81
81
|
|
82
82
|
# not supported
|
@@ -93,18 +93,18 @@ module When
|
|
93
93
|
|
94
94
|
case date_time
|
95
95
|
# extended date & time format (ISO 8601)
|
96
|
-
when /^([-+*&%@!>=<?\dW.]+)(?:(T([:*=.,\d]+)?)([A-Z]
|
96
|
+
when /^([-+*&%@!>=<?\dW.]+)(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?$/
|
97
97
|
d, t, time, clock = $~[1..4]
|
98
98
|
format, date = Date._to_array_extended_ISO8601(d, options)
|
99
99
|
|
100
100
|
# extended date & time format (JIS X0301)
|
101
|
-
when /^((.+::)?(\[[^\]]+\]|[^-+\d]+))([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]
|
101
|
+
when /^((.+::)?(\[[^\]]+\]|[^-+\d]+))([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?$/
|
102
102
|
era, parent, child, d, t, time, clock = $~[1..7]
|
103
103
|
format, date, era = Date._to_array_extended_X0301(d, era, options)
|
104
104
|
era ||= options[:era_name] if (d =~ /\./)
|
105
105
|
|
106
106
|
# extended time format (ISO 8601)
|
107
|
-
when /^(T(-{0,2}[:*=.,\d]+)?)([A-Z]
|
107
|
+
when /^(T(-{0,2}[:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?$/
|
108
108
|
t, time, clock = $~[1..3]
|
109
109
|
|
110
110
|
# not supported
|
@@ -336,10 +336,12 @@ module When
|
|
336
336
|
# 時間帯の表現を正規化する
|
337
337
|
def _to_string_clock(clock)
|
338
338
|
return nil unless clock
|
339
|
-
return clock if (clock =~ /^[A-Z]
|
340
|
-
raise ArgumentError, "Wrong clock format: #{clock}" unless
|
341
|
-
|
342
|
-
|
339
|
+
return clock if (clock =~ /^[A-Z]+(\?.+)?$/)
|
340
|
+
raise ArgumentError, "Wrong clock format: #{clock}" unless clock =~ /^([-+])(\d{2})(?::?(\d{2}))?(?::?(\d{2}))?$/
|
341
|
+
sgn, h, m, s = $~[1..4]
|
342
|
+
zone = sgn + h + ':' + (m||'00')
|
343
|
+
zone += s if s
|
344
|
+
return zone
|
343
345
|
end
|
344
346
|
end
|
345
347
|
end
|
@@ -356,8 +358,9 @@ module When
|
|
356
358
|
# an optional codeSpace
|
357
359
|
#
|
358
360
|
# @return [String] anyURI (Optional)
|
359
|
-
|
361
|
+
attr_accessor :code_space
|
360
362
|
alias :codeSpace :code_space
|
363
|
+
private :code_space=
|
361
364
|
|
362
365
|
# オブジェクトの生成
|
363
366
|
#
|
@@ -418,24 +421,29 @@ module When
|
|
418
421
|
return nil
|
419
422
|
end
|
420
423
|
|
424
|
+
# @private
|
425
|
+
HashProperty = [:label, :names, :link, :access_key, :code_space]
|
426
|
+
|
421
427
|
#
|
422
|
-
#
|
428
|
+
# 代表名
|
423
429
|
#
|
424
|
-
# @return [
|
430
|
+
# @return [String]
|
425
431
|
#
|
426
|
-
|
427
|
-
self
|
428
|
-
end
|
429
|
-
alias :label :to_m17n
|
432
|
+
attr_reader :label
|
430
433
|
|
431
434
|
#
|
432
|
-
#
|
435
|
+
# 名前が意味するもの自体のオブジェクト
|
436
|
+
#
|
437
|
+
# @return [When::BasicTypes::Object]
|
438
|
+
#
|
439
|
+
alias :what :parent
|
440
|
+
|
433
441
|
#
|
434
|
-
#
|
442
|
+
# When::BasicTypes::M17n に変換する - 何もしないで自身を返す
|
435
443
|
#
|
436
444
|
# @return [When::BasicTypes::M17n]
|
437
445
|
#
|
438
|
-
def
|
446
|
+
def to_m17n
|
439
447
|
self
|
440
448
|
end
|
441
449
|
|
@@ -479,7 +487,9 @@ module When
|
|
479
487
|
rest, options = _attributes(args)
|
480
488
|
_sequence
|
481
489
|
|
482
|
-
return
|
490
|
+
return _pool[@label.to_s] ?
|
491
|
+
_copy_all(_pool[@label.to_s]) : # 階層になった Resource の代表ラベルのための生成
|
492
|
+
_copy(options) if @label # M17n#to_h の出力と書式互換の入力による生成
|
483
493
|
|
484
494
|
case rest[0]
|
485
495
|
when When::Parts::Resource::ContentLine
|
@@ -498,20 +508,18 @@ module When
|
|
498
508
|
@names ||= names.reverse
|
499
509
|
@namespace ||= namespace if namespace.kind_of?(Hash)
|
500
510
|
@locale ||= locale.reverse
|
501
|
-
@label = self
|
502
511
|
when nil ;
|
503
512
|
else
|
504
513
|
names, namespace, locale = rest
|
505
514
|
@names = names if names
|
506
515
|
@namespace ||= Parts::Locale._namespace(namespace) if namespace
|
507
516
|
@locale ||= Parts::Locale._locale(locale) if locale
|
508
|
-
@label = self
|
509
517
|
end
|
510
518
|
@namespace ||= {}
|
511
519
|
@locale ||= []
|
512
520
|
|
513
521
|
@code_space = @namespace['']
|
514
|
-
self[0..-1] = _names(@names, @namespace, @locale)
|
522
|
+
self[0..-1] = @label = _names(@names, @namespace, @locale)
|
515
523
|
end
|
516
524
|
end
|
517
525
|
|