when_exe 0.4.1 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +36 -33
- data/bin/locales.rb +1 -1
- data/bin/make_ttl.rb.config +1 -1
- data/lib/when_exe.rb +27 -16
- data/lib/when_exe/basictypes.rb +772 -771
- data/lib/when_exe/calendartypes.rb +1485 -1453
- data/lib/when_exe/coordinates.rb +5 -0
- data/lib/when_exe/core/compatibility.rb +1 -1
- data/lib/when_exe/core/duration.rb +147 -116
- data/lib/when_exe/core/extension.rb +499 -497
- data/lib/when_exe/ephemeris.rb +1952 -1951
- data/lib/when_exe/ephemeris/eclipse.rb +5 -4
- data/lib/when_exe/ephemeris/notes.rb +457 -421
- data/lib/when_exe/ephemeris/planets.rb +585 -585
- data/lib/when_exe/ephemeris/sun.rb +214 -214
- data/lib/when_exe/google_api.rb +153 -0
- data/lib/when_exe/icalendar.rb +1640 -1632
- data/lib/when_exe/inspect.rb +42 -20
- data/lib/when_exe/linkeddata.rb +28 -7
- data/lib/when_exe/locales/autoload.rb +2 -1
- data/lib/when_exe/locales/locale.rb +35 -15
- data/lib/when_exe/locales/zh.rb +77 -0
- data/lib/when_exe/mini_application.rb +3 -1
- data/lib/when_exe/{googlecalendar.rb → obsolete/googlecalendar.rb} +144 -144
- data/lib/when_exe/parts/enumerator.rb +498 -486
- data/lib/when_exe/parts/geometric_complex.rb +397 -397
- data/lib/when_exe/parts/timezone.rb +246 -241
- data/lib/when_exe/region/armenian.rb +55 -56
- data/lib/when_exe/region/babylonian.rb +406 -405
- data/lib/when_exe/region/bahai.rb +107 -106
- data/lib/when_exe/region/balinese.rb +624 -622
- data/lib/when_exe/region/chinese.rb +1071 -1026
- data/lib/when_exe/region/chinese/epochs.rb +28 -28
- data/lib/when_exe/region/chinese/notes.rb +219 -0
- data/lib/when_exe/region/chinese/twins.rb +803 -803
- data/lib/when_exe/region/christian.rb +21 -15
- data/lib/when_exe/region/coptic.rb +107 -106
- data/lib/when_exe/region/discordian.rb +218 -218
- data/lib/when_exe/region/east_asian.rb +1 -1
- data/lib/when_exe/region/french.rb +126 -56
- data/lib/when_exe/region/geologicalage.rb +639 -639
- data/lib/when_exe/region/goddess.rb +60 -58
- data/lib/when_exe/region/hanke_henry.rb +2 -2
- data/lib/when_exe/region/indian.rb +1225 -1222
- data/lib/when_exe/region/international_fixed.rb +96 -97
- data/lib/when_exe/region/iranian.rb +206 -203
- data/lib/when_exe/region/islamic.rb +102 -102
- data/lib/when_exe/region/japanese.rb +126 -71
- data/lib/when_exe/region/japanese/epochs.rb +426 -426
- data/lib/when_exe/region/japanese/notes.rb +101 -81
- data/lib/when_exe/region/japanese/residues.rb +1345 -1311
- data/lib/when_exe/region/japanese/twins.rb +225 -225
- data/lib/when_exe/region/japanese/weeks.rb +112 -112
- data/lib/when_exe/region/javanese.rb +230 -230
- data/lib/when_exe/region/jewish.rb +130 -131
- data/lib/when_exe/region/m17n.rb +114 -114
- data/lib/when_exe/region/martian.rb +258 -258
- data/lib/when_exe/region/mayan.rb +11 -8
- data/lib/when_exe/region/pax.rb +4 -5
- data/lib/when_exe/region/pope.rb +1 -1
- data/lib/when_exe/region/positivist.rb +100 -100
- data/lib/when_exe/region/residue.rb +162 -162
- data/lib/when_exe/region/roman.rb +333 -333
- data/lib/when_exe/region/{soviet.rb → russian.rb} +221 -209
- data/lib/when_exe/region/shire.rb +222 -223
- data/lib/when_exe/region/symmetry.rb +50 -50
- data/lib/when_exe/region/thai.rb +336 -336
- data/lib/when_exe/region/tibetan.rb +315 -316
- data/lib/when_exe/region/tranquility.rb +207 -208
- data/lib/when_exe/region/vanishing_leprechaun.rb +3 -1
- data/lib/when_exe/region/vietnamese.rb +449 -440
- data/lib/when_exe/region/weekdate.rb +80 -80
- data/lib/when_exe/region/world.rb +170 -171
- data/lib/when_exe/region/world_season.rb +89 -89
- data/lib/when_exe/region/yerm.rb +3 -3
- data/lib/when_exe/region/zoroastrian.rb +205 -205
- data/lib/when_exe/timestandard.rb +708 -707
- data/lib/when_exe/tmduration.rb +338 -338
- data/lib/when_exe/tmobjects.rb +1356 -1356
- data/lib/when_exe/tmposition.rb +66 -31
- data/lib/when_exe/version.rb +16 -2
- data/test/examples/Residue.m17n +83 -83
- data/test/examples/Terms.m17n +2 -2
- data/test/test.rb +2 -2
- data/test/test/google_api.rb +65 -0
- data/test/test/linkeddata.rb +1 -1
- data/test/test/{googlecalendar.rb → obsolete/googlecalendar.rb} +194 -194
- data/test/test/region/indian.rb +90 -85
- data/test/test/region/m17n.rb +7 -7
- data/test/test/region/mayan.rb +195 -195
- data/test/test/region/residue.rb +153 -153
- data/test/test/tmposition.rb +11 -1
- data/when_exe.gemspec +2 -2
- metadata +95 -8
- data/test/test.rb.config +0 -1
data/lib/when_exe/inspect.rb
CHANGED
|
@@ -30,6 +30,25 @@ module When
|
|
|
30
30
|
label
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# suffix 付の名前
|
|
34
|
+
#
|
|
35
|
+
# @param [When::BasicTypes::M17n] format 書式
|
|
36
|
+
# @param [String, Array<String>] locale 文字列化を行う locale の指定(デフォルト : オブジェクト生成時に保持している locale すべて)
|
|
37
|
+
#
|
|
38
|
+
# @return [String]
|
|
39
|
+
#
|
|
40
|
+
def suffixed_label(format, locale=nil)
|
|
41
|
+
if @suffix
|
|
42
|
+
@suffix = When.Resource(@suffix).to_m17n unless @suffix.kind_of?(When::Parts::Resource) || @suffix !~ /:/
|
|
43
|
+
format = m17n([format]*self.keys.length, nil, nil, {:locale=>self.keys}) if format.instance_of?(String)
|
|
44
|
+
format._printf([label, @suffix], locale)
|
|
45
|
+
elsif locale
|
|
46
|
+
label.translate(locale)
|
|
47
|
+
else
|
|
48
|
+
label
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
33
52
|
#
|
|
34
53
|
# オブジェクトの内容を Hash 化
|
|
35
54
|
#
|
|
@@ -688,17 +707,17 @@ module When
|
|
|
688
707
|
hash
|
|
689
708
|
end
|
|
690
709
|
|
|
691
|
-
# 指定の書式による多言語対応文字列化 -
|
|
710
|
+
# 指定の書式による多言語対応文字列化 - format で指定した書式で多言語対応文字列化する
|
|
692
711
|
#
|
|
693
|
-
# @param [When::BasicTypes::M17n]
|
|
712
|
+
# @param [When::BasicTypes::M17n] format 書式
|
|
694
713
|
# @param [String, Array<String>] locale 文字列化を行う locale の指定(デフォルト : オブジェクト生成時に保持している locale すべて)
|
|
695
714
|
#
|
|
696
715
|
# @return [When::BasicTypes::M17n]
|
|
697
716
|
#
|
|
698
|
-
def strftime(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
_strftime(k,
|
|
717
|
+
def strftime(format=@frame.strftime, locale=nil)
|
|
718
|
+
format = m17n([format]*self.keys.length, nil, nil, {:locale=>self.keys}) if format.instance_of?(String)
|
|
719
|
+
format._printf([], locale) do |k, *t|
|
|
720
|
+
_strftime(k, format, [''])
|
|
702
721
|
end
|
|
703
722
|
end
|
|
704
723
|
|
|
@@ -823,36 +842,36 @@ module When
|
|
|
823
842
|
# 指定の書式による多言語対応文字列化
|
|
824
843
|
#
|
|
825
844
|
# @param [String] locale 文字列化を行う locale
|
|
826
|
-
# @param [When::BasicTypes::M17n]
|
|
845
|
+
# @param [When::BasicTypes::M17n] format 書式
|
|
827
846
|
#
|
|
828
847
|
# @return [Array] 書式と文字列化項目からなる配列
|
|
829
848
|
#
|
|
830
|
-
def _strftime(locale,
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
849
|
+
def _strftime(locale, format, t)
|
|
850
|
+
pattern, *terms = t
|
|
851
|
+
format = format.translate(locale) if format.kind_of?(When::BasicTypes::M17n)
|
|
852
|
+
format.scan(/(%[O\d]*(?:\.(\d+))?.)|(.)/) do |c,e,s|
|
|
834
853
|
case c
|
|
835
854
|
when /\A%%/
|
|
836
|
-
|
|
855
|
+
pattern += '%%'
|
|
837
856
|
when /\A%/
|
|
838
857
|
action = TemporalPosition.format[c[-1..-1]]
|
|
839
858
|
case action
|
|
840
859
|
when Array
|
|
841
|
-
|
|
860
|
+
pattern += action[0]
|
|
842
861
|
terms << _term(action[1], locale, c[1..-2].to_i, e||3)
|
|
843
862
|
when String
|
|
844
863
|
action = action.translate(locale) if action.kind_of?(When::BasicTypes::M17n)
|
|
845
864
|
if (action =~ /%/)
|
|
846
|
-
|
|
865
|
+
pattern, *terms = _strftime(locale, action, [pattern] + terms)
|
|
847
866
|
else
|
|
848
|
-
|
|
867
|
+
pattern += action
|
|
849
868
|
end
|
|
850
869
|
end
|
|
851
870
|
else
|
|
852
|
-
|
|
871
|
+
pattern += s
|
|
853
872
|
end
|
|
854
873
|
end
|
|
855
|
-
[
|
|
874
|
+
[pattern] + terms
|
|
856
875
|
end
|
|
857
876
|
|
|
858
877
|
#
|
|
@@ -1049,11 +1068,14 @@ module When
|
|
|
1049
1068
|
#
|
|
1050
1069
|
# 参照ラベル
|
|
1051
1070
|
#
|
|
1071
|
+
# @param [When::BasicTypes::M17n] format 書式
|
|
1072
|
+
# @param [String, Array<String>] locale 文字列化を行う locale の指定(デフォルト : オブジェクト生成時に保持している locale すべて)
|
|
1073
|
+
#
|
|
1052
1074
|
# @return [When::BasicTypes::M17n]
|
|
1053
1075
|
#
|
|
1054
|
-
def reference_label
|
|
1055
|
-
return @calendar_era.hierarchy.map {|e| e.label} if @calendar_era
|
|
1056
|
-
return [@frame.label] if @frame.label
|
|
1076
|
+
def reference_label(format=nil, locale=nil)
|
|
1077
|
+
return @calendar_era.hierarchy.map {|e| format ? e.suffixed_label(format, locale) : e.label} if @calendar_era
|
|
1078
|
+
return [format ? @frame.suffixed_label(format, locale) : @frame.label] if @frame.label
|
|
1057
1079
|
[When::BasicTypes::M17n.new(@frame.class.to_s.split(/::/)[-1])]
|
|
1058
1080
|
end
|
|
1059
1081
|
|
data/lib/when_exe/linkeddata.rb
CHANGED
|
@@ -215,7 +215,7 @@ module When
|
|
|
215
215
|
child.each do |c|
|
|
216
216
|
next if c.iri =~ / /
|
|
217
217
|
iri = c.child ? c.iri : self.iri
|
|
218
|
-
prefixes[((c.kind_of?(When::BasicTypes::M17n) ? c : c.label)
|
|
218
|
+
prefixes[((c.kind_of?(When::BasicTypes::M17n) ? c : c.label).label_for_prefix).split(/ +/).first] = [iri + '::']
|
|
219
219
|
end
|
|
220
220
|
prefixes
|
|
221
221
|
end
|
|
@@ -234,7 +234,10 @@ module When
|
|
|
234
234
|
|
|
235
235
|
# 自身を root とするグラフの jsonld を表現する Hash を生成する
|
|
236
236
|
#
|
|
237
|
-
# @param [Hash] options
|
|
237
|
+
# @param [Hash] options 以下の通り
|
|
238
|
+
# @option options [Boolean] :include 自身が含むResourceオブジェクトをグラフに含める(デフォルト nil)
|
|
239
|
+
# @option options [Object] @... そのまま戻り値のHashに追加
|
|
240
|
+
# @option options [Symbol] その他 {When::TM::CalDate#to_jsonld_hash} などを参照
|
|
238
241
|
#
|
|
239
242
|
# @return [Hash] jsonld を表現する Hash
|
|
240
243
|
#
|
|
@@ -245,7 +248,10 @@ module When
|
|
|
245
248
|
# Resourceオブジェクトの jsonld をグラフに追加する
|
|
246
249
|
#
|
|
247
250
|
# @param [Array<Hash>] graph 個別のResourceオブジェクトの jsonld hash の Array
|
|
248
|
-
# @param [Hash] options {
|
|
251
|
+
# @param [Hash] options { 以下の通り
|
|
252
|
+
# @option options [Boolean] :include 自身が含むResourceオブジェクトをグラフに含める(デフォルト nil)
|
|
253
|
+
# @option options [Object] @... そのまま戻り値のHashに追加
|
|
254
|
+
# @option options [Symbol] その他 {When::TM::CalDate#to_jsonld_hash} などを参照
|
|
249
255
|
#
|
|
250
256
|
# @return [Array] jsonld hash の Array
|
|
251
257
|
#
|
|
@@ -368,7 +374,7 @@ module When
|
|
|
368
374
|
Array(value).each do |prefix|
|
|
369
375
|
start = source.index(prefix)
|
|
370
376
|
body = source[prefix.length..-1]
|
|
371
|
-
return key + ':' + body if start == 0 && body !~
|
|
377
|
+
return key + ':' + body if start == 0 && body !~ /[:#\/]/
|
|
372
378
|
end
|
|
373
379
|
end
|
|
374
380
|
return source unless context
|
|
@@ -379,7 +385,7 @@ module When
|
|
|
379
385
|
elsif namespace && namespace.index(When::Parts::Resource.base_uri) == 0
|
|
380
386
|
label = begin When.Resource(namespace.sub(/::\z/, '')) rescue return source end
|
|
381
387
|
label = label.label unless label.kind_of?(When::BasicTypes::M17n)
|
|
382
|
-
prefix = label.to_m17n
|
|
388
|
+
prefix = label.to_m17n.label_for_prefix
|
|
383
389
|
return source unless prefix =~ /\A[-A-Z\d_]+\z/i
|
|
384
390
|
else
|
|
385
391
|
return source
|
|
@@ -397,6 +403,15 @@ module When
|
|
|
397
403
|
#
|
|
398
404
|
class BasicTypes::M17n
|
|
399
405
|
|
|
406
|
+
#
|
|
407
|
+
# namespace に対応させる文字列を取得する
|
|
408
|
+
#
|
|
409
|
+
# @return [String] prefix 用の文字列
|
|
410
|
+
#
|
|
411
|
+
def label_for_prefix
|
|
412
|
+
names['prefix'] || names['alias'] || names['en'] || names['']
|
|
413
|
+
end
|
|
414
|
+
|
|
400
415
|
private
|
|
401
416
|
|
|
402
417
|
#
|
|
@@ -463,7 +478,10 @@ module When
|
|
|
463
478
|
|
|
464
479
|
# 自身を root とするグラフの jsonld を表現する Hash を生成する
|
|
465
480
|
#
|
|
466
|
-
# @param [Hash] options
|
|
481
|
+
# @param [Hash] options 以下の通り
|
|
482
|
+
# @option options [Boolean] :include 自身が含むResourceオブジェクトをグラフに含める(デフォルト nil)
|
|
483
|
+
# @option options [Object] @... そのまま戻り値のHashに追加
|
|
484
|
+
# @option options [Symbol] その他 {When::TM::CalDate#to_jsonld_hash} などを参照
|
|
467
485
|
#
|
|
468
486
|
# @return [Hash] jsonld を表現する Hash
|
|
469
487
|
#
|
|
@@ -475,7 +493,10 @@ module When
|
|
|
475
493
|
# CalDateオブジェクトの jsonld をグラフに追加する
|
|
476
494
|
#
|
|
477
495
|
# @param [Array<Hash>] graph 個別のCalDateオブジェクトの jsonld hash の Array
|
|
478
|
-
# @param [Hash] options
|
|
496
|
+
# @param [Hash] options 以下の通り
|
|
497
|
+
# @option options [Boolean] :include 自身が含むResourceオブジェクトをグラフに含める(デフォルト nil)
|
|
498
|
+
# @option options [Object] @... そのまま戻り値のHashに追加
|
|
499
|
+
# @option options [Symbol] その他 {When::TM::CalDate#to_jsonld_hash} などを参照
|
|
479
500
|
#
|
|
480
501
|
# @return [Array] jsonld hash の Array
|
|
481
502
|
#
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
=begin
|
|
3
|
-
Copyright (C) 2012-
|
|
3
|
+
Copyright (C) 2012-2015 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
|
|
@@ -94,6 +94,7 @@ module When
|
|
|
94
94
|
autoload :Locale_uz, 'when_exe/locales/uz'
|
|
95
95
|
autoload :Locale_vi, 'when_exe/locales/vi'
|
|
96
96
|
autoload :Locale_wo, 'when_exe/locales/wo'
|
|
97
|
+
autoload :Locale_zh, 'when_exe/locales/zh'
|
|
97
98
|
autoload :Locale_zh_CN, 'when_exe/locales/zh_CN'
|
|
98
99
|
autoload :Locale_zh_HK, 'when_exe/locales/zh_HK'
|
|
99
100
|
autoload :Locale_zh_TW, 'when_exe/locales/zh_TW'
|
|
@@ -20,6 +20,12 @@ module When
|
|
|
20
20
|
# Locale 読み替えの初期設定
|
|
21
21
|
DefaultAlias = {'alias'=>'ja', '日本語'=>'ja', '英語'=>'en'}
|
|
22
22
|
|
|
23
|
+
# 東アジアの国別コード
|
|
24
|
+
EastAsiaCC = %w(gan hak ii kr kp ko vn ja zh)
|
|
25
|
+
|
|
26
|
+
# 東アジア判定正規表現
|
|
27
|
+
RegExpEastAsia = /\A(#{EastAsiaCC.join('|')})/
|
|
28
|
+
|
|
23
29
|
# 省略時 Namespace
|
|
24
30
|
DefaultNamespaces = Hash.new {|hash, key|
|
|
25
31
|
hash[key] = "http://#{key}.wikipedia.org/wiki/"
|
|
@@ -40,7 +46,7 @@ module When
|
|
|
40
46
|
'竜'=>'龍'
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
# Escape
|
|
49
|
+
# Escape for RFC6868
|
|
44
50
|
# @private
|
|
45
51
|
Escape = {
|
|
46
52
|
"\\\\" => "\\",
|
|
@@ -69,7 +75,7 @@ module When
|
|
|
69
75
|
#
|
|
70
76
|
# @param [Hash] options 下記の通り
|
|
71
77
|
# @option options [Hash] :alias Locale の読み替えパターンを Hash で指定する。
|
|
72
|
-
# @option options [
|
|
78
|
+
# @option options [Hash] :namespace_foramt 名前空間定義の省略時に名前空間生成に用いる書式
|
|
73
79
|
# @option options [Hash] :unification 漢字の包摂パターンを Hash で指定する。
|
|
74
80
|
# @option options [Numeric] :wikipedia_interval Wikipedia の連続的な参照を抑制するための遅延時間/秒
|
|
75
81
|
#
|
|
@@ -185,9 +191,7 @@ module When
|
|
|
185
191
|
# source の配列化
|
|
186
192
|
if source.kind_of?(String)
|
|
187
193
|
source = $1 if (source=~/\A\s*\[?(.+?)\]?\s*\z/m)
|
|
188
|
-
source = source
|
|
189
|
-
(token||'').gsub(/\\./) {|escape| Escape[escape] || escape}
|
|
190
|
-
}
|
|
194
|
+
source = _split_with_rfc6868_escape(source)
|
|
191
195
|
end
|
|
192
196
|
|
|
193
197
|
# 各Localeの展開
|
|
@@ -231,6 +235,14 @@ module When
|
|
|
231
235
|
list.unshift(line)
|
|
232
236
|
end
|
|
233
237
|
|
|
238
|
+
# rfc6868 による Escape を含んだ文字列 ".., .., .." を分割する
|
|
239
|
+
# @private
|
|
240
|
+
def _split_with_rfc6868_escape(source)
|
|
241
|
+
source.scan(/((?:[^\\\n\r,]|\\.)+)(?:[\n\r,]+(?!\z))?|[\n\r,]+/m).flatten.map {|token|
|
|
242
|
+
(token||'').gsub(/\\./) {|escape| Escape[escape] || escape}
|
|
243
|
+
}
|
|
244
|
+
end
|
|
245
|
+
|
|
234
246
|
# locale 指定を解析して Hash の値を取り出す
|
|
235
247
|
# @private
|
|
236
248
|
def _hash_value(hash, locale, defaults=['', 'en'])
|
|
@@ -652,12 +664,20 @@ module When
|
|
|
652
664
|
label = Locale._hash_value(@names, locale, [])
|
|
653
665
|
return label if label
|
|
654
666
|
foreign = Locale._get_locale(locale, @access_key)
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
667
|
+
if foreign
|
|
668
|
+
english = @names['en'] || @names['']
|
|
669
|
+
addition = english.dup.sub!(/\A#{Locale._get_locale('en', @access_key)['en']}/, '')
|
|
670
|
+
foreign[locale] += addition if addition
|
|
671
|
+
update(foreign)
|
|
672
|
+
Locale._hash_value(@names, locale)
|
|
673
|
+
else
|
|
674
|
+
case locale
|
|
675
|
+
when /\Aja/ ;
|
|
676
|
+
when RegExpEastAsia ; return @names['zh'] if @names['zh']
|
|
677
|
+
else ; return @names['en'] if @names['en']
|
|
678
|
+
end
|
|
679
|
+
@names['']
|
|
680
|
+
end
|
|
661
681
|
end
|
|
662
682
|
|
|
663
683
|
private
|
|
@@ -676,7 +696,7 @@ module When
|
|
|
676
696
|
@values = [names]
|
|
677
697
|
return names
|
|
678
698
|
end
|
|
679
|
-
names = $1.split(/[\n\r
|
|
699
|
+
names = $1.split(/[\n\r]+/).map {|line| Locale._split_with_rfc6868_escape(line)}.flatten
|
|
680
700
|
end
|
|
681
701
|
|
|
682
702
|
mark = []
|
|
@@ -741,11 +761,11 @@ module When
|
|
|
741
761
|
name
|
|
742
762
|
end
|
|
743
763
|
|
|
744
|
-
# encode URI from patterns %%(...) or %.(...)
|
|
764
|
+
# encode URI from patterns %%(...) or %.(...) and replace space to '_'
|
|
745
765
|
def _encode(source)
|
|
746
|
-
source.gsub(/%.<.+?>/)
|
|
766
|
+
source.gsub(' ','_').gsub(/%.<.+?>/) { |match|
|
|
747
767
|
URI.encode(match[3..-2]).gsub('%', match[1..1])
|
|
748
|
-
|
|
768
|
+
}
|
|
749
769
|
end
|
|
750
770
|
end
|
|
751
771
|
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
=begin
|
|
3
|
+
Copyright (C) 2012-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
|
+
module When
|
|
9
|
+
module Locale
|
|
10
|
+
|
|
11
|
+
# from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/zh-HK.yml
|
|
12
|
+
|
|
13
|
+
Locale_zh =
|
|
14
|
+
{"date"=>
|
|
15
|
+
{"abbr_day_names"=>["日", "一", "二", "三", "四", "五", "六"],
|
|
16
|
+
"abbr_month_names"=>
|
|
17
|
+
[nil,
|
|
18
|
+
"1月",
|
|
19
|
+
"2月",
|
|
20
|
+
"3月",
|
|
21
|
+
"4月",
|
|
22
|
+
"5月",
|
|
23
|
+
"6月",
|
|
24
|
+
"7月",
|
|
25
|
+
"8月",
|
|
26
|
+
"9月",
|
|
27
|
+
"10月",
|
|
28
|
+
"11月",
|
|
29
|
+
"12月"],
|
|
30
|
+
"day_names"=>["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
|
|
31
|
+
"formats"=>{"default"=>"%Y-%m-%d", "long"=>"%Y年%b%d日", "short"=>"%b%d日"},
|
|
32
|
+
"month_names"=>
|
|
33
|
+
[nil,
|
|
34
|
+
"一月",
|
|
35
|
+
"二月",
|
|
36
|
+
"三月",
|
|
37
|
+
"四月",
|
|
38
|
+
"五月",
|
|
39
|
+
"六月",
|
|
40
|
+
"七月",
|
|
41
|
+
"八月",
|
|
42
|
+
"九月",
|
|
43
|
+
"十月",
|
|
44
|
+
"十一月",
|
|
45
|
+
"十二月"],
|
|
46
|
+
"order"=>[:year, :month, :day]},
|
|
47
|
+
"time"=>
|
|
48
|
+
{"am"=>"上午",
|
|
49
|
+
"formats"=>
|
|
50
|
+
{"default"=>"%Y年%b%d日 %A %H:%M:%S %Z",
|
|
51
|
+
"long"=>"%Y年%b%d日 %H:%M",
|
|
52
|
+
"short"=>"%b%d日 %H:%M",
|
|
53
|
+
"time"=>"%H:%M:%S %Z"},
|
|
54
|
+
"pm"=>"下午"},
|
|
55
|
+
"datetime"=>
|
|
56
|
+
{"distance_in_words"=>
|
|
57
|
+
{"about_x_hours"=>{"one"=>"約一小時", "other"=>"約%{count}小時"},
|
|
58
|
+
"about_x_months"=>{"one"=>"約一個月", "other"=>"約%{count}個月"},
|
|
59
|
+
"about_x_years"=>{"one"=>"約一年", "other"=>"約%{count}年"},
|
|
60
|
+
"almost_x_years"=>{"one"=>"接近一年", "other"=>"接近%{count}年"},
|
|
61
|
+
"half_a_minute"=>"半分鐘",
|
|
62
|
+
"less_than_x_minutes"=>{"one"=>"不到一分鐘", "other"=>"不到%{count}分鐘"},
|
|
63
|
+
"less_than_x_seconds"=>{"one"=>"不到一秒", "other"=>"不到%{count}秒"},
|
|
64
|
+
"over_x_years"=>{"one"=>"超過一年", "other"=>"超過%{count}年"},
|
|
65
|
+
"x_days"=>{"one"=>"一天", "other"=>"%{count}天"},
|
|
66
|
+
"x_minutes"=>{"one"=>"一分鐘", "other"=>"%{count}分鐘"},
|
|
67
|
+
"x_months"=>{"one"=>"一個月", "other"=>"%{count}個月"},
|
|
68
|
+
"x_seconds"=>{"one"=>"一秒", "other"=>"%{count}秒"}},
|
|
69
|
+
"prompts"=>
|
|
70
|
+
{"day"=>"日",
|
|
71
|
+
"hour"=>"時",
|
|
72
|
+
"minute"=>"分",
|
|
73
|
+
"month"=>"月",
|
|
74
|
+
"second"=>"秒",
|
|
75
|
+
"year"=>"年"}}}
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -240,7 +240,7 @@ module When
|
|
|
240
240
|
case list[i]
|
|
241
241
|
when When::TM::Calendar ; list.slice!(i) if options[:extent] && !list[i].domain[''].include?(date)
|
|
242
242
|
when Class ;
|
|
243
|
-
|
|
243
|
+
when When::TM::CalendarEra
|
|
244
244
|
eras = (date ^ list[i]).delete_if {|e| !e.leaf?}
|
|
245
245
|
unless options[:go_back] == :All
|
|
246
246
|
if options[:go_back] == :After
|
|
@@ -250,6 +250,8 @@ module When
|
|
|
250
250
|
end
|
|
251
251
|
end
|
|
252
252
|
list[i,1] = eras.map {|e| e.calendar_era}
|
|
253
|
+
else
|
|
254
|
+
list[i,1] = list[i].child
|
|
253
255
|
end
|
|
254
256
|
end
|
|
255
257
|
|
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
=begin
|
|
3
|
-
Copyright (C) 2012-2014 Takashi SUGA
|
|
4
|
-
|
|
5
|
-
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
|
6
|
-
=end
|
|
7
|
-
|
|
8
|
-
begin
|
|
9
|
-
require 'gcalapi'
|
|
10
|
-
rescue LoadError
|
|
11
|
-
raise LoadError, "Please install gcalapi from https://github.com/suchowan/gcalapi"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
# gcalapi の GoogleCalendar モジュールへの機能追加
|
|
16
|
-
#
|
|
17
|
-
module GoogleCalendar
|
|
18
|
-
|
|
19
|
-
#
|
|
20
|
-
# gcalapi の GoogleCalendar::Event クラスへの機能追加
|
|
21
|
-
#
|
|
22
|
-
class Event
|
|
23
|
-
# 繰り返しイベントの定義
|
|
24
|
-
# @return [Array<String>]
|
|
25
|
-
attr_accessor :recurrence
|
|
26
|
-
|
|
27
|
-
Event::ATTRIBUTES_MAP["recurrence"] = { "element" => "gd:recurrence"}
|
|
28
|
-
|
|
29
|
-
# @private
|
|
30
|
-
alias :_instance_to_xml :instance_to_xml
|
|
31
|
-
|
|
32
|
-
# @private
|
|
33
|
-
def instance_to_xml
|
|
34
|
-
_instance_to_xml
|
|
35
|
-
@xml.root.elements[recurrence ? "gd:when" : "gd:recurrence"].remove
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# When::V::Event オブジェクトへの変換
|
|
39
|
-
#
|
|
40
|
-
# @return [When::V::Event]
|
|
41
|
-
#
|
|
42
|
-
def to_vevent
|
|
43
|
-
options = {'summary'=>@title, 'description'=>@desc, 'location'=>@where}
|
|
44
|
-
if @recurrence
|
|
45
|
-
@recurrence.each_line do |line|
|
|
46
|
-
options[$1.downcase] ||= $2 if line =~ /^(DTSTART|DTEND|RRULE).(.+)$/i
|
|
47
|
-
end
|
|
48
|
-
else
|
|
49
|
-
options.update({'dtstart'=>When.when?(@st), 'dtend'=>When.when?(@en)})
|
|
50
|
-
end
|
|
51
|
-
When::V::Event.new(options)
|
|
52
|
-
end
|
|
53
|
-
alias :vevent :to_vevent
|
|
54
|
-
|
|
55
|
-
# イベントのステータス
|
|
56
|
-
#
|
|
57
|
-
# @return [String]
|
|
58
|
-
# [ 'confirmed' - 有効 ]
|
|
59
|
-
# [ 'canceled' - 無効 ]
|
|
60
|
-
#
|
|
61
|
-
def event_status
|
|
62
|
-
@xml.root.elements['gd:eventStatus'].attributes['value'][/[^.]+$/]
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
#
|
|
67
|
-
# gcalapi の GoogleCalendar::Calendar クラスへの機能追加
|
|
68
|
-
#
|
|
69
|
-
class Calendar
|
|
70
|
-
# イベントを順に取り出す enumerator
|
|
71
|
-
#
|
|
72
|
-
# @param [Hash] conditions
|
|
73
|
-
# @option conditions [String, When::TM::TemporalPosition] 'start-min' 最初のイベント開始日時(省略時は現在時刻)
|
|
74
|
-
# @option conditions [String, When::TM::TemporalPosition] 'start-max' 最後のイベント開始日時(省略時は制限なし)
|
|
75
|
-
# @option conditions [String] 'sortorder'
|
|
76
|
-
# [ 'a' - asend(省略時) ]
|
|
77
|
-
# [ 'd' - desend ]
|
|
78
|
-
#
|
|
79
|
-
# @return [Enumerator]
|
|
80
|
-
#
|
|
81
|
-
def enum_for(conditions={})
|
|
82
|
-
conditions['start-min'] ||= When.now
|
|
83
|
-
conditions['sortorder'] ||= 'a'
|
|
84
|
-
conditions['orderby'] = 'starttime'
|
|
85
|
-
direction = (conditions['sortorder'] == 'd') ? :reverse : :forward
|
|
86
|
-
first = When.when?(conditions['start-min'])
|
|
87
|
-
conditions['start-min'] = (When::Gregorian ^ first).to_s
|
|
88
|
-
if conditions['start-max']
|
|
89
|
-
last = When.when?(conditions['start-max'])
|
|
90
|
-
inner_args = [first...last]
|
|
91
|
-
conditions['start-max'] = (When::Gregorian ^ last).to_s
|
|
92
|
-
else
|
|
93
|
-
inner_args = [first, direction]
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
confirmed = []
|
|
97
|
-
canceled = []
|
|
98
|
-
self.events(conditions).each do |event|
|
|
99
|
-
case event.event_status
|
|
100
|
-
when 'canceled' ; canceled << event
|
|
101
|
-
else ; confirmed << event
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
outer_args = [first, direction]
|
|
105
|
-
outer_args << {:exevent => canceled.map {|event| event.to_vevent}} if canceled.length > 0
|
|
106
|
-
|
|
107
|
-
When::Parts::Enumerator::Integrated.new(self, confirmed.map {|event|
|
|
108
|
-
event.to_vevent.enum_for(*inner_args)
|
|
109
|
-
}, *outer_args)
|
|
110
|
-
end
|
|
111
|
-
alias :to_enum :enum_for
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
module When::V
|
|
116
|
-
class Event
|
|
117
|
-
|
|
118
|
-
# GoogleCalendar::Event オブジェクトへの変換
|
|
119
|
-
#
|
|
120
|
-
# @param [GoogleCalendar::Calendar] cal
|
|
121
|
-
#
|
|
122
|
-
# @return [GoogleCalendar::Event]
|
|
123
|
-
#
|
|
124
|
-
def to_gcalevent(cal)
|
|
125
|
-
event = cal.create_event
|
|
126
|
-
event.title = summary if respond_to?(:summary)
|
|
127
|
-
event.desc = description if respond_to?(:description)
|
|
128
|
-
event.where = location if respond_to?(:location)
|
|
129
|
-
if rrule.size == 0
|
|
130
|
-
event.st = dtstart.to_time
|
|
131
|
-
event.en = dtend.to_time
|
|
132
|
-
else
|
|
133
|
-
event.recurrence =
|
|
134
|
-
(['RRULE:' + property['rrule'][0].object] +
|
|
135
|
-
['dtstart', 'dtend'].map {|key|
|
|
136
|
-
value = property[key].attribute['.']
|
|
137
|
-
key.upcase + (value =~ /=/ ? ';' : ':') + value
|
|
138
|
-
}).join("\n") + "\n"
|
|
139
|
-
end
|
|
140
|
-
event
|
|
141
|
-
end
|
|
142
|
-
alias :gcalevent :to_gcalevent
|
|
143
|
-
end
|
|
144
|
-
end
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
=begin
|
|
3
|
+
Copyright (C) 2012-2014 Takashi SUGA
|
|
4
|
+
|
|
5
|
+
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
|
6
|
+
=end
|
|
7
|
+
|
|
8
|
+
begin
|
|
9
|
+
require 'gcalapi'
|
|
10
|
+
rescue LoadError
|
|
11
|
+
raise LoadError, "Please install gcalapi from https://github.com/suchowan/gcalapi"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# gcalapi の GoogleCalendar モジュールへの機能追加
|
|
16
|
+
#
|
|
17
|
+
module GoogleCalendar
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# gcalapi の GoogleCalendar::Event クラスへの機能追加
|
|
21
|
+
#
|
|
22
|
+
class Event
|
|
23
|
+
# 繰り返しイベントの定義
|
|
24
|
+
# @return [Array<String>]
|
|
25
|
+
attr_accessor :recurrence
|
|
26
|
+
|
|
27
|
+
Event::ATTRIBUTES_MAP["recurrence"] = { "element" => "gd:recurrence"}
|
|
28
|
+
|
|
29
|
+
# @private
|
|
30
|
+
alias :_instance_to_xml :instance_to_xml
|
|
31
|
+
|
|
32
|
+
# @private
|
|
33
|
+
def instance_to_xml
|
|
34
|
+
_instance_to_xml
|
|
35
|
+
@xml.root.elements[recurrence ? "gd:when" : "gd:recurrence"].remove
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# When::V::Event オブジェクトへの変換
|
|
39
|
+
#
|
|
40
|
+
# @return [When::V::Event]
|
|
41
|
+
#
|
|
42
|
+
def to_vevent
|
|
43
|
+
options = {'summary'=>@title, 'description'=>@desc, 'location'=>@where}
|
|
44
|
+
if @recurrence
|
|
45
|
+
@recurrence.each_line do |line|
|
|
46
|
+
options[$1.downcase] ||= $2 if line =~ /^(DTSTART|DTEND|RRULE).(.+)$/i
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
options.update({'dtstart'=>When.when?(@st), 'dtend'=>When.when?(@en)})
|
|
50
|
+
end
|
|
51
|
+
When::V::Event.new(options)
|
|
52
|
+
end
|
|
53
|
+
alias :vevent :to_vevent
|
|
54
|
+
|
|
55
|
+
# イベントのステータス
|
|
56
|
+
#
|
|
57
|
+
# @return [String]
|
|
58
|
+
# [ 'confirmed' - 有効 ]
|
|
59
|
+
# [ 'canceled' - 無効 ]
|
|
60
|
+
#
|
|
61
|
+
def event_status
|
|
62
|
+
@xml.root.elements['gd:eventStatus'].attributes['value'][/[^.]+$/]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
#
|
|
67
|
+
# gcalapi の GoogleCalendar::Calendar クラスへの機能追加
|
|
68
|
+
#
|
|
69
|
+
class Calendar
|
|
70
|
+
# イベントを順に取り出す enumerator
|
|
71
|
+
#
|
|
72
|
+
# @param [Hash] conditions
|
|
73
|
+
# @option conditions [String, When::TM::TemporalPosition] 'start-min' 最初のイベント開始日時(省略時は現在時刻)
|
|
74
|
+
# @option conditions [String, When::TM::TemporalPosition] 'start-max' 最後のイベント開始日時(省略時は制限なし)
|
|
75
|
+
# @option conditions [String] 'sortorder'
|
|
76
|
+
# [ 'a' - asend(省略時) ]
|
|
77
|
+
# [ 'd' - desend ]
|
|
78
|
+
#
|
|
79
|
+
# @return [Enumerator]
|
|
80
|
+
#
|
|
81
|
+
def enum_for(conditions={})
|
|
82
|
+
conditions['start-min'] ||= When.now
|
|
83
|
+
conditions['sortorder'] ||= 'a'
|
|
84
|
+
conditions['orderby'] = 'starttime'
|
|
85
|
+
direction = (conditions['sortorder'] == 'd') ? :reverse : :forward
|
|
86
|
+
first = When.when?(conditions['start-min'])
|
|
87
|
+
conditions['start-min'] = (When::Gregorian ^ first).to_s
|
|
88
|
+
if conditions['start-max']
|
|
89
|
+
last = When.when?(conditions['start-max'])
|
|
90
|
+
inner_args = [first...last]
|
|
91
|
+
conditions['start-max'] = (When::Gregorian ^ last).to_s
|
|
92
|
+
else
|
|
93
|
+
inner_args = [first, direction]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
confirmed = []
|
|
97
|
+
canceled = []
|
|
98
|
+
self.events(conditions).each do |event|
|
|
99
|
+
case event.event_status
|
|
100
|
+
when 'canceled' ; canceled << event
|
|
101
|
+
else ; confirmed << event
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
outer_args = [first, direction]
|
|
105
|
+
outer_args << {:exevent => canceled.map {|event| event.to_vevent}} if canceled.length > 0
|
|
106
|
+
|
|
107
|
+
When::Parts::Enumerator::Integrated.new(self, confirmed.map {|event|
|
|
108
|
+
event.to_vevent.enum_for(*inner_args)
|
|
109
|
+
}, *outer_args)
|
|
110
|
+
end
|
|
111
|
+
alias :to_enum :enum_for
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
module When::V
|
|
116
|
+
class Event
|
|
117
|
+
|
|
118
|
+
# GoogleCalendar::Event オブジェクトへの変換
|
|
119
|
+
#
|
|
120
|
+
# @param [GoogleCalendar::Calendar] cal
|
|
121
|
+
#
|
|
122
|
+
# @return [GoogleCalendar::Event]
|
|
123
|
+
#
|
|
124
|
+
def to_gcalevent(cal)
|
|
125
|
+
event = cal.create_event
|
|
126
|
+
event.title = summary if respond_to?(:summary)
|
|
127
|
+
event.desc = description if respond_to?(:description)
|
|
128
|
+
event.where = location if respond_to?(:location)
|
|
129
|
+
if rrule.size == 0
|
|
130
|
+
event.st = dtstart.to_time
|
|
131
|
+
event.en = dtend.to_time
|
|
132
|
+
else
|
|
133
|
+
event.recurrence =
|
|
134
|
+
(['RRULE:' + property['rrule'][0].object] +
|
|
135
|
+
['dtstart', 'dtend'].map {|key|
|
|
136
|
+
value = property[key].attribute['.']
|
|
137
|
+
key.upcase + (value =~ /=/ ? ';' : ':') + value
|
|
138
|
+
}).join("\n") + "\n"
|
|
139
|
+
end
|
|
140
|
+
event
|
|
141
|
+
end
|
|
142
|
+
alias :gcalevent :to_gcalevent
|
|
143
|
+
end
|
|
144
|
+
end
|