when_exe 0.3.1 → 0.3.2
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.
- data/lib/when_exe.rb +98 -64
- data/lib/when_exe/basictypes.rb +2 -2
- data/lib/when_exe/calendartypes.rb +5 -2
- data/lib/when_exe/coordinates.rb +11 -1
- data/lib/when_exe/core/duration.rb +38 -0
- data/lib/when_exe/core/extension.rb +17 -4
- data/lib/when_exe/ephemeris.rb +49 -17
- data/lib/when_exe/icalendar.rb +19 -17
- data/lib/when_exe/inspect.rb +16 -4
- data/lib/when_exe/mini_application.rb +42 -4
- data/lib/when_exe/parts/locale.rb +30 -13
- data/lib/when_exe/parts/resource.rb +59 -36
- data/lib/when_exe/parts/timezone.rb +19 -13
- data/lib/when_exe/region/bahai.rb +5 -4
- data/lib/when_exe/region/balinese.rb +2 -2
- data/lib/when_exe/region/chinese.rb +11 -11
- data/lib/when_exe/region/chinese_calendar.rb +37 -79
- data/lib/when_exe/region/chinese_epoch.rb +832 -831
- data/lib/when_exe/region/christian.rb +6 -6
- data/lib/when_exe/region/far_east.rb +104 -104
- data/lib/when_exe/region/french.rb +4 -4
- data/lib/when_exe/region/geologicalage.rb +9 -8
- data/lib/when_exe/region/indian.rb +10 -10
- data/lib/when_exe/region/iranian.rb +3 -3
- data/lib/when_exe/region/islamic.rb +3 -3
- data/lib/when_exe/region/japanese.rb +376 -376
- data/lib/when_exe/region/japanese_notes.rb +60 -60
- data/lib/when_exe/region/javanese.rb +4 -4
- data/lib/when_exe/region/jewish.rb +2 -2
- data/lib/when_exe/region/korean.rb +204 -204
- data/lib/when_exe/region/m17n.rb +1 -1
- data/lib/when_exe/region/martian.rb +2 -2
- data/lib/when_exe/region/mayan.rb +1 -1
- data/lib/when_exe/region/nihon_shoki.rb +43 -43
- data/lib/when_exe/region/pope.rb +271 -271
- data/lib/when_exe/region/roman.rb +13 -12
- data/lib/when_exe/region/ryukyu.rb +47 -47
- data/lib/when_exe/region/shire.rb +4 -4
- data/lib/when_exe/region/thai.rb +2 -2
- data/lib/when_exe/region/tibetan.rb +3 -3
- data/lib/when_exe/region/vietnamese.rb +122 -122
- data/lib/when_exe/region/world.rb +2 -2
- data/lib/when_exe/timestandard.rb +112 -67
- data/lib/when_exe/tmobjects.rb +4 -0
- data/lib/when_exe/tmposition.rb +63 -10
- data/lib/when_exe/tmreference.rb +34 -13
- data/lib/when_exe/version.rb +1 -1
- data/test/test/icalendar.rb +29 -29
- data/test/test/region/m17n.rb +4 -4
- data/test/test/tmobjects.rb +9 -0
- data/test/test/tmposition.rb +3 -3
- data/when_exe.gemspec +1 -1
- metadata +4 -2
data/lib/when_exe/icalendar.rb
CHANGED
@@ -22,10 +22,10 @@
|
|
22
22
|
# ただし、この指定は BYxxx とは共存できない。
|
23
23
|
# * BYHOUR=h(,..)
|
24
24
|
# h に When.exe Standard Representation を使用できる
|
25
|
-
# example: 'BYHOUR=2
|
26
|
-
# 夏時間から標準時間への切り替え時に 夏時間の2
|
27
|
-
# example: 'BYHOUR=
|
28
|
-
# 夏時間から標準時間への切り替え時に 夏時間の
|
25
|
+
# example: 'BYHOUR=1,2'
|
26
|
+
# 夏時間から標準時間への切り替え時に 夏時間の1時,標準時間の2時 を生成
|
27
|
+
# example: 'BYHOUR=1,1=,2'
|
28
|
+
# 夏時間から標準時間への切り替え時に 夏時間の1時,標準時間の1時,標準時間の2時 を生成
|
29
29
|
# 他のソフトウェアとの互換性を損なう可能性があるが、本ライブラリは両方の動作の違いを
|
30
30
|
# 記述できる必要があると判断。
|
31
31
|
# * BYDAY/c=n*e±s(,..)
|
@@ -506,12 +506,14 @@ module When::V
|
|
506
506
|
# (When.now + default_until)を本メソッドで指定している。
|
507
507
|
# default_until の指定がない場合、default_until は 1000年と解釈する。
|
508
508
|
#
|
509
|
+
# @note
|
510
|
+
# 本メソッドでマルチスレッド対応の管理変数の初期化を行っている。
|
511
|
+
# このため、本メソッド自体はスレッドセーフでない。
|
512
|
+
#
|
509
513
|
def _setup_(default_until=nil)
|
510
514
|
@_lock_ = Mutex.new if When.multi_thread
|
511
|
-
@_lock_.lock if @_lock_
|
512
515
|
@_pool = {}
|
513
516
|
@default_until = default_until
|
514
|
-
@_lock_.unlock if @_lock_
|
515
517
|
end
|
516
518
|
end
|
517
519
|
|
@@ -614,13 +616,13 @@ module When::V
|
|
614
616
|
|
615
617
|
# 順次実行
|
616
618
|
#
|
617
|
-
# @overload
|
619
|
+
# @overload each()
|
618
620
|
#
|
619
|
-
# @overload
|
621
|
+
# @overload each(range, count_limit=nil)
|
620
622
|
# @param [Range, When::Parts::GeometricComplex] range 始点-range.first, 終点-range.last
|
621
623
|
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
622
624
|
#
|
623
|
-
# @overload
|
625
|
+
# @overload each(first, direction, count_limit)
|
624
626
|
# @param [When::TM::TemporalPosition] first 始点
|
625
627
|
# @param [Symbol] direction :forward - 昇順, :reverse - 降順
|
626
628
|
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
@@ -880,13 +882,8 @@ module When::V
|
|
880
882
|
zdate = yield(nprop.tzoffsetfrom.dup.tap{|clock| clock.tz_prop = nil})
|
881
883
|
end
|
882
884
|
deltad = zdate.universal_time - ndate.universal_time
|
883
|
-
|
884
|
-
|
885
|
-
return nprop.tzoffsetfrom
|
886
|
-
else
|
887
|
-
return nprop.tzoffsetto if (deltad >= 0)
|
888
|
-
return nprop.tzoffsetfrom
|
889
|
-
end
|
885
|
+
return nprop.tzoffsetto if (deltad >= 0)
|
886
|
+
return nprop.tzoffsetfrom
|
890
887
|
end
|
891
888
|
|
892
889
|
# @private
|
@@ -1365,8 +1362,13 @@ module When::V
|
|
1365
1362
|
period = ord-bound[index] if (index>0)
|
1366
1363
|
result = bound + When::TM::PeriodDuration.new(period, index)
|
1367
1364
|
if period > 0 && result.universal_time < lower_bound.universal_time
|
1365
|
+
clock = result.clock
|
1366
|
+
case clock.tz_prop
|
1367
|
+
when When::V::TimezoneProperty ; clock = clock.tz_prop.tzoffsetto
|
1368
|
+
when When::Parts::Timezone ; clock = clock.tz_prop.standard
|
1369
|
+
end
|
1368
1370
|
result = result._copy({:date=>result.cal_date, :validate=>:done, :events=>nil,
|
1369
|
-
:time=>result.clk_time._copy({:clock=>
|
1371
|
+
:time=>result.clk_time._copy({:clock=>clock})})
|
1370
1372
|
end
|
1371
1373
|
result
|
1372
1374
|
}
|
data/lib/when_exe/inspect.rb
CHANGED
@@ -92,7 +92,7 @@ module When
|
|
92
92
|
when Numeric, FalseClass, TrueClass ; element
|
93
93
|
else ; element.to_s
|
94
94
|
end
|
95
|
-
result =
|
95
|
+
result = When::Parts::Locale.translate(result,options[:locale]) if options[:locale] && result.kind_of?(String)
|
96
96
|
result
|
97
97
|
end
|
98
98
|
end
|
@@ -297,10 +297,18 @@ module When
|
|
297
297
|
begun = self.floor(MONTH,DAY) + When::TM::PeriodDuration.new([0,i,0])
|
298
298
|
ended = begun + DurationP1M
|
299
299
|
ended = ended.prev until begun.cal_date[MONTH-1] == ended.cal_date[MONTH-1]
|
300
|
+
if ended.to_i <= begun.to_i
|
301
|
+
ended = begun
|
302
|
+
loop do
|
303
|
+
succ = ended.succ
|
304
|
+
break unless succ.frame.equal?(begun.frame)
|
305
|
+
ended = succ
|
306
|
+
end
|
307
|
+
end
|
300
308
|
dates = [begun]
|
301
309
|
loop do
|
302
310
|
current = dates[-1].week_included(wkst)
|
303
|
-
if
|
311
|
+
if current.last.to_i > ended.to_i
|
304
312
|
dates[-1] = ended
|
305
313
|
break (dates.map {|date| date.week_included(wkst, {:Range=>begun.to_i..ended.to_i}, &block)}).
|
306
314
|
unshift(yield(begun, MONTH)).compact
|
@@ -1107,6 +1115,10 @@ module When
|
|
1107
1115
|
|
1108
1116
|
# event を 文字列化 - 日時で与えられた event を文字列化する
|
1109
1117
|
#
|
1118
|
+
# @param [When::TM::TemporalPosition] other 時系の歩度を比較する基準(nilは比較しない)
|
1119
|
+
#
|
1120
|
+
# @return [String]
|
1121
|
+
#
|
1110
1122
|
# @note
|
1111
1123
|
# events 配列なし - 日時をそのまま文字列化
|
1112
1124
|
# 日時の精度が日より細かい - イベント名(イベント時刻)
|
@@ -1117,7 +1129,7 @@ module When
|
|
1117
1129
|
return events[0] + '(' + clk_time.to_s[/[:*=0-9]+/] + ')' if precision > When::DAY
|
1118
1130
|
return events[0] unless other
|
1119
1131
|
other = JulianDate.dynamical_time(other.dynamical_time,
|
1120
|
-
{:time_standard=>time_standard}) unless rate_of_clock == other.rate_of_clock
|
1132
|
+
{:time_standard=>time_standard}) unless time_standard.rate_of_clock == other.time_standard.rate_of_clock
|
1121
1133
|
events[0] + '(' + (other.to_i - to_i).to_s + ')'
|
1122
1134
|
end
|
1123
1135
|
|
@@ -1162,7 +1174,7 @@ module When
|
|
1162
1174
|
date = Pair._format([format] + terms)
|
1163
1175
|
date.sub!(/([^\d])\(([-+\d]+)\)/, '(\2)\1') if era
|
1164
1176
|
date = date[0..-2] unless @frame.pair[precision-1] || date[-1..-1] != '.'
|
1165
|
-
date.gsub!(/\./, '-') if (@frame.indices.length <=
|
1177
|
+
date.gsub!(/\./, '-') if (@frame.indices.length <= DefaultDateIndices.length) && !era
|
1166
1178
|
return date
|
1167
1179
|
end
|
1168
1180
|
end
|
@@ -63,7 +63,9 @@ module When
|
|
63
63
|
start = Time.now
|
64
64
|
puts start._log_('%FT%X.%L') + ': Query - ' + When::Parts::Locale.translate(query, config['!'])
|
65
65
|
begin
|
66
|
-
|
66
|
+
result = free_conv(*query.split(/\s+/))
|
67
|
+
result = When::Parts::Locale.translate(result, config['!'])
|
68
|
+
client.puts JSON.generate(Array(_to_string(result))).to_s
|
67
69
|
stop = Time.now
|
68
70
|
puts stop._log_('%FT%X.%L') + ": Respond (%7.0f ms)" % (1000 * (stop.to_f - start.to_f))
|
69
71
|
rescue => err
|
@@ -94,10 +96,46 @@ module When
|
|
94
96
|
def client(server, port, query)
|
95
97
|
TCPSocket.open(server, port.to_i) do |socket|
|
96
98
|
socket.puts(query)
|
97
|
-
JSON.parse(socket.gets.force_encoding("UTF-8"))
|
99
|
+
results = JSON.parse(socket.gets.force_encoding("UTF-8"))
|
100
|
+
results = Hash[*results.flatten(1)] if results[0].kind_of?(Array)
|
101
|
+
_to_symbol(results)
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
105
|
+
# JSONで通信するために Symbol を String に変換する
|
106
|
+
def _to_string(source)
|
107
|
+
case source
|
108
|
+
when Array
|
109
|
+
source.map {|e| _to_string(e)}
|
110
|
+
when Hash
|
111
|
+
result = {}
|
112
|
+
source.each_pair {|k,v|
|
113
|
+
result[k.kind_of?(Symbol) ? '_sym_' + k.to_s : k] = _to_string(v)
|
114
|
+
}
|
115
|
+
result
|
116
|
+
else
|
117
|
+
source
|
118
|
+
end
|
119
|
+
end
|
120
|
+
private :_to_string
|
121
|
+
|
122
|
+
# JSONで通信するために String を Symbol に変換する
|
123
|
+
def _to_symbol(source)
|
124
|
+
case source
|
125
|
+
when Array
|
126
|
+
source.map {|e| _to_symbol(e)}
|
127
|
+
when Hash
|
128
|
+
result = {}
|
129
|
+
source.each_pair {|k,v|
|
130
|
+
result[k =~ /^_sym_(.+)$/ ? $1.to_sym : k] = _to_symbol(v)
|
131
|
+
}
|
132
|
+
result
|
133
|
+
else
|
134
|
+
source
|
135
|
+
end
|
136
|
+
end
|
137
|
+
private :_to_symbol
|
138
|
+
|
101
139
|
# 日付の自由変換
|
102
140
|
#
|
103
141
|
# @param [Array<String>] args コマンドライン入力
|
@@ -234,11 +272,11 @@ module When
|
|
234
272
|
list.map {|calendar|
|
235
273
|
calendar.kind_of?(Class) ?
|
236
274
|
yield(calendar.new(date)) :
|
237
|
-
yield(calendar ^ (calendar.rate_of_clock == date.rate_of_clock ? date.to_i : date))
|
275
|
+
yield(calendar ^ (calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date))
|
238
276
|
}
|
239
277
|
else
|
240
278
|
list.map {|calendar|
|
241
|
-
date_for_calendar = calendar ^ (calendar.rate_of_clock == date.rate_of_clock ? date.to_i : date)
|
279
|
+
date_for_calendar = calendar ^ (calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date)
|
242
280
|
methods.map {|method|
|
243
281
|
date_for_calendar.send(method[0].to_sym, method[1], &block)
|
244
282
|
}
|
@@ -19,7 +19,7 @@ module When::Parts
|
|
19
19
|
module Locale
|
20
20
|
|
21
21
|
# Locale 読み替えの初期設定
|
22
|
-
|
22
|
+
DefaultAlias = {'alias'=>'ja', '日本語'=>'ja', '英語'=>'en'}
|
23
23
|
|
24
24
|
# 漢字の包摂
|
25
25
|
DefaultUnification = {
|
@@ -52,12 +52,17 @@ module When::Parts
|
|
52
52
|
|
53
53
|
# When::Parts::Locale Module のグローバルな設定を行う
|
54
54
|
#
|
55
|
-
# @param [Hash]
|
56
|
-
#
|
57
|
-
#
|
55
|
+
# @param [Hash] options 下記の通り
|
56
|
+
# @option options [Hash] :alias Locale の読み替えパターンを Hash で指定する。
|
57
|
+
# @option options [Hash] :unification 漢字の包摂パターンを Hash で指定する。
|
58
58
|
#
|
59
|
-
|
60
|
-
|
59
|
+
# @note
|
60
|
+
# :alias の指定がない場合、aliases は DefaultAlias(モジュール定数)と解釈する。
|
61
|
+
# :unification の指定がない場合、unifications は DefaultUnification(モジュール定数)と解釈する。
|
62
|
+
#
|
63
|
+
def _setup_(options={})
|
64
|
+
@aliases = options[:alias] || DefaultAlias
|
65
|
+
@unifications = options[:unification] || DefaultUnification
|
61
66
|
end
|
62
67
|
|
63
68
|
# 特定 locale に対応した文字列の取得
|
@@ -72,6 +77,7 @@ module When::Parts
|
|
72
77
|
# @return [String] loc に対応した文字列
|
73
78
|
#
|
74
79
|
# @note source が Hash や Array の場合、その構成要素を変換して返す
|
80
|
+
# @note encode は通常大文字だが、大文字/小文字の変換は行わず指定されたまま使用している
|
75
81
|
#
|
76
82
|
def translate(source, loc='')
|
77
83
|
return source unless loc
|
@@ -103,7 +109,7 @@ module When::Parts
|
|
103
109
|
# @return [String] 文字を包摂した文字列
|
104
110
|
# @return [Regexp] 文字を包摂した正規表現
|
105
111
|
#
|
106
|
-
def ideographic_unification(source, pattern=
|
112
|
+
def ideographic_unification(source, pattern=_unification)
|
107
113
|
case source
|
108
114
|
when When::Parts::Locale
|
109
115
|
source.ideographic_unification(pattern)
|
@@ -196,11 +202,15 @@ module When::Parts
|
|
196
202
|
return hash[default]
|
197
203
|
end
|
198
204
|
|
199
|
-
private
|
205
|
+
# @private
|
206
|
+
def _unification
|
207
|
+
@unifications || DefaultUnification
|
208
|
+
end
|
200
209
|
|
201
210
|
def _alias
|
202
|
-
@aliases ||
|
211
|
+
@aliases || DefaultAlias
|
203
212
|
end
|
213
|
+
private :_alias
|
204
214
|
end
|
205
215
|
|
206
216
|
# ローケール指定時の文字列
|
@@ -385,7 +395,7 @@ module When::Parts
|
|
385
395
|
#
|
386
396
|
# @return [When::Parts::Locale] self
|
387
397
|
# @private
|
388
|
-
def ideographic_unification!(pattern=
|
398
|
+
def ideographic_unification!(pattern=_unification)
|
389
399
|
names = {}
|
390
400
|
@names.each_pair do |key, value|
|
391
401
|
names[key] = Locale.ideographic_unification(value, pattern)
|
@@ -403,7 +413,7 @@ module When::Parts
|
|
403
413
|
#
|
404
414
|
# @return [When::Parts::Locale] 包摂結果
|
405
415
|
#
|
406
|
-
def ideographic_unification(pattern=
|
416
|
+
def ideographic_unification(pattern=_unification)
|
407
417
|
dup.ideographic_unification!(pattern)
|
408
418
|
end
|
409
419
|
|
@@ -497,8 +507,8 @@ module When::Parts
|
|
497
507
|
prefix = namespace[$1]
|
498
508
|
ref.sub!(/^.+:/, prefix) if (prefix)
|
499
509
|
end
|
500
|
-
ref +=
|
501
|
-
@link[locale] = ref
|
510
|
+
ref += '%%<' + name + '>' if (ref =~ /[\/#:]$/)
|
511
|
+
@link[locale] = _encode(ref)
|
502
512
|
else ; raise ArgumentError, "Irregal locale format"
|
503
513
|
end
|
504
514
|
end
|
@@ -509,5 +519,12 @@ module When::Parts
|
|
509
519
|
|
510
520
|
return @names[mark[0] || mark[1] || mark[2]]
|
511
521
|
end
|
522
|
+
|
523
|
+
# encode URI from patterns %%(...) or %.(...)
|
524
|
+
def _encode(source)
|
525
|
+
source.gsub(/%.<.+?>/) do |match|
|
526
|
+
URI.encode(match[3..-2].gsub(match[1], '%'))
|
527
|
+
end
|
528
|
+
end
|
512
529
|
end
|
513
530
|
end
|
@@ -15,34 +15,6 @@ module When::Parts
|
|
15
15
|
#
|
16
16
|
module Resource
|
17
17
|
|
18
|
-
# 登録済み Prefix
|
19
|
-
Prefix = {'_w' => When::SourceURI + '/',
|
20
|
-
'_p' => When::SourceURI + 'Parts/',
|
21
|
-
'_b' => When::SourceURI + 'BasicTypes/',
|
22
|
-
'_m' => When::SourceURI + 'BasicTypes/M17n/',
|
23
|
-
'_co' => When::SourceURI + 'Coordinates/',
|
24
|
-
'_l' => When::SourceURI + 'Coordinates/Spatial?',
|
25
|
-
'_v' => When::SourceURI + 'V/',
|
26
|
-
'_rs' => When::SourceURI + 'RS/',
|
27
|
-
'_ex' => When::SourceURI + 'EX/',
|
28
|
-
'_tm' => When::SourceURI + 'TM/',
|
29
|
-
'_e' => When::SourceURI + 'TM/CalendarEra/',
|
30
|
-
'_t' => When::SourceURI + 'TimeStandard/',
|
31
|
-
'_ep' => When::SourceURI + 'Ephemeris/',
|
32
|
-
'_c' => When::SourceURI + 'CalendarTypes/',
|
33
|
-
'_n' => When::SourceURI + 'CalendarTypes/CalendarNote/',
|
34
|
-
'_sc' => When::SourceURI + 'Ephemeris/V50/'
|
35
|
-
}
|
36
|
-
|
37
|
-
# @private
|
38
|
-
PrefixKeys = Prefix.keys.sort.reverse.map {|k| k.downcase}
|
39
|
-
|
40
|
-
# @private
|
41
|
-
PrefixValues = Prefix.values.sort.reverse
|
42
|
-
|
43
|
-
# @private
|
44
|
-
PrefixIndex = Prefix.invert
|
45
|
-
|
46
18
|
# @private
|
47
19
|
LabelProperty = nil
|
48
20
|
|
@@ -90,11 +62,14 @@ module When::Parts
|
|
90
62
|
|
91
63
|
# 初期化
|
92
64
|
# @return [void]
|
65
|
+
#
|
66
|
+
# @note
|
67
|
+
# 本メソッドでマルチスレッド対応の管理変数の初期化を行っている。
|
68
|
+
# このため、本メソッド自体はスレッドセーフでない。
|
69
|
+
#
|
93
70
|
def _setup_
|
94
71
|
@_lock_ = Mutex.new if When.multi_thread
|
95
|
-
@_lock_.lock if @_lock_
|
96
72
|
@_pool = {}
|
97
|
-
@_lock_.unlock if @_lock_
|
98
73
|
end
|
99
74
|
|
100
75
|
# オブジェクト参照
|
@@ -152,6 +127,51 @@ module When::Parts
|
|
152
127
|
|
153
128
|
include Pool
|
154
129
|
|
130
|
+
# Base URI for When_exe Resources
|
131
|
+
#
|
132
|
+
# @return [String]
|
133
|
+
#
|
134
|
+
attr_reader :base_uri
|
135
|
+
|
136
|
+
# @private
|
137
|
+
attr_reader :_prefix, :_prefix_values, :_prefix_index
|
138
|
+
private :_prefix, :_prefix_values, :_prefix_index
|
139
|
+
|
140
|
+
# 初期化
|
141
|
+
#
|
142
|
+
# @param [String] base_uri Base URI for When_exe Resources
|
143
|
+
#
|
144
|
+
# @return [void]
|
145
|
+
#
|
146
|
+
# @note
|
147
|
+
# 本メソッドでマルチスレッド対応の管理変数の初期化を行っている。
|
148
|
+
# このため、本メソッド自体はスレッドセーフでない。
|
149
|
+
#
|
150
|
+
def _setup_(base_uri=When::SourceURI)
|
151
|
+
super()
|
152
|
+
@_prefix = {
|
153
|
+
'_w' => base_uri + '/',
|
154
|
+
'_p' => base_uri + 'Parts/',
|
155
|
+
'_b' => base_uri + 'BasicTypes/',
|
156
|
+
'_m' => base_uri + 'BasicTypes/M17n/',
|
157
|
+
'_co' => base_uri + 'Coordinates/',
|
158
|
+
'_l' => base_uri + 'Coordinates/Spatial?',
|
159
|
+
'_v' => base_uri + 'V/',
|
160
|
+
'_rs' => base_uri + 'RS/',
|
161
|
+
'_ex' => base_uri + 'EX/',
|
162
|
+
'_tm' => base_uri + 'TM/',
|
163
|
+
'_e' => base_uri + 'TM/CalendarEra/',
|
164
|
+
'_t' => base_uri + 'TimeStandard/',
|
165
|
+
'_ep' => base_uri + 'Ephemeris/',
|
166
|
+
'_c' => base_uri + 'CalendarTypes/',
|
167
|
+
'_n' => base_uri + 'CalendarTypes/CalendarNote/',
|
168
|
+
'_sc' => base_uri + 'Ephemeris/V50/'
|
169
|
+
}
|
170
|
+
@base_uri = base_uri
|
171
|
+
@_prefix_values = @_prefix.values.sort.reverse
|
172
|
+
@_prefix_index = @_prefix.invert
|
173
|
+
end
|
174
|
+
|
155
175
|
# オブジェクト生成&参照
|
156
176
|
#
|
157
177
|
# 指定した iri の When::Parts::Resource オブジェクトを取得する。
|
@@ -163,6 +183,8 @@ module When::Parts
|
|
163
183
|
# @return [When::Parts::Resource]
|
164
184
|
#
|
165
185
|
def _instance(iri, namespace=nil)
|
186
|
+
_setup_ unless @_pool
|
187
|
+
|
166
188
|
# 配列は個別に処理
|
167
189
|
return iri.map {|e| _instance(e, namespace)} if iri.kind_of?(Array)
|
168
190
|
|
@@ -199,12 +221,13 @@ module When::Parts
|
|
199
221
|
|
200
222
|
# @private
|
201
223
|
def _path_with_prefix(obj, simple=true)
|
202
|
-
|
224
|
+
_setup_ unless @_pool
|
225
|
+
path = obj.kind_of?(Class) ? obj.to_s.sub(/^When::/, base_uri).gsub(/::/, '/') :
|
203
226
|
obj.iri
|
204
227
|
return path unless simple
|
205
|
-
|
228
|
+
_prefix_values.each do |value|
|
206
229
|
index = path.index(value)
|
207
|
-
return
|
230
|
+
return _prefix_index[value] + ':' + path[value.length..-1] if index
|
208
231
|
end
|
209
232
|
return path
|
210
233
|
end
|
@@ -238,11 +261,11 @@ module When::Parts
|
|
238
261
|
prefix = '_' + prefix.downcase
|
239
262
|
klass = klass.capitalize if klass == klass.upcase
|
240
263
|
end
|
241
|
-
path =
|
264
|
+
path = _prefix[prefix] + klass if (_prefix[prefix])
|
242
265
|
elsif capitalize && path =~ /^(v[^\/]+|daylight$|standard$)/i
|
243
266
|
klass = path.sub(/^v/i, '').capitalize
|
244
|
-
path =
|
245
|
-
|
267
|
+
path = _prefix['_v'] + klass if When::V.const_defined?(klass) &&
|
268
|
+
When::V.const_get(klass).kind_of?(Class)
|
246
269
|
end
|
247
270
|
return path
|
248
271
|
end
|