when_exe 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -33
  3. data/bin/locales.rb +1 -1
  4. data/bin/make_ttl.rb.config +1 -1
  5. data/lib/when_exe.rb +27 -16
  6. data/lib/when_exe/basictypes.rb +772 -771
  7. data/lib/when_exe/calendartypes.rb +1485 -1453
  8. data/lib/when_exe/coordinates.rb +5 -0
  9. data/lib/when_exe/core/compatibility.rb +1 -1
  10. data/lib/when_exe/core/duration.rb +147 -116
  11. data/lib/when_exe/core/extension.rb +499 -497
  12. data/lib/when_exe/ephemeris.rb +1952 -1951
  13. data/lib/when_exe/ephemeris/eclipse.rb +5 -4
  14. data/lib/when_exe/ephemeris/notes.rb +457 -421
  15. data/lib/when_exe/ephemeris/planets.rb +585 -585
  16. data/lib/when_exe/ephemeris/sun.rb +214 -214
  17. data/lib/when_exe/google_api.rb +153 -0
  18. data/lib/when_exe/icalendar.rb +1640 -1632
  19. data/lib/when_exe/inspect.rb +42 -20
  20. data/lib/when_exe/linkeddata.rb +28 -7
  21. data/lib/when_exe/locales/autoload.rb +2 -1
  22. data/lib/when_exe/locales/locale.rb +35 -15
  23. data/lib/when_exe/locales/zh.rb +77 -0
  24. data/lib/when_exe/mini_application.rb +3 -1
  25. data/lib/when_exe/{googlecalendar.rb → obsolete/googlecalendar.rb} +144 -144
  26. data/lib/when_exe/parts/enumerator.rb +498 -486
  27. data/lib/when_exe/parts/geometric_complex.rb +397 -397
  28. data/lib/when_exe/parts/timezone.rb +246 -241
  29. data/lib/when_exe/region/armenian.rb +55 -56
  30. data/lib/when_exe/region/babylonian.rb +406 -405
  31. data/lib/when_exe/region/bahai.rb +107 -106
  32. data/lib/when_exe/region/balinese.rb +624 -622
  33. data/lib/when_exe/region/chinese.rb +1071 -1026
  34. data/lib/when_exe/region/chinese/epochs.rb +28 -28
  35. data/lib/when_exe/region/chinese/notes.rb +219 -0
  36. data/lib/when_exe/region/chinese/twins.rb +803 -803
  37. data/lib/when_exe/region/christian.rb +21 -15
  38. data/lib/when_exe/region/coptic.rb +107 -106
  39. data/lib/when_exe/region/discordian.rb +218 -218
  40. data/lib/when_exe/region/east_asian.rb +1 -1
  41. data/lib/when_exe/region/french.rb +126 -56
  42. data/lib/when_exe/region/geologicalage.rb +639 -639
  43. data/lib/when_exe/region/goddess.rb +60 -58
  44. data/lib/when_exe/region/hanke_henry.rb +2 -2
  45. data/lib/when_exe/region/indian.rb +1225 -1222
  46. data/lib/when_exe/region/international_fixed.rb +96 -97
  47. data/lib/when_exe/region/iranian.rb +206 -203
  48. data/lib/when_exe/region/islamic.rb +102 -102
  49. data/lib/when_exe/region/japanese.rb +126 -71
  50. data/lib/when_exe/region/japanese/epochs.rb +426 -426
  51. data/lib/when_exe/region/japanese/notes.rb +101 -81
  52. data/lib/when_exe/region/japanese/residues.rb +1345 -1311
  53. data/lib/when_exe/region/japanese/twins.rb +225 -225
  54. data/lib/when_exe/region/japanese/weeks.rb +112 -112
  55. data/lib/when_exe/region/javanese.rb +230 -230
  56. data/lib/when_exe/region/jewish.rb +130 -131
  57. data/lib/when_exe/region/m17n.rb +114 -114
  58. data/lib/when_exe/region/martian.rb +258 -258
  59. data/lib/when_exe/region/mayan.rb +11 -8
  60. data/lib/when_exe/region/pax.rb +4 -5
  61. data/lib/when_exe/region/pope.rb +1 -1
  62. data/lib/when_exe/region/positivist.rb +100 -100
  63. data/lib/when_exe/region/residue.rb +162 -162
  64. data/lib/when_exe/region/roman.rb +333 -333
  65. data/lib/when_exe/region/{soviet.rb → russian.rb} +221 -209
  66. data/lib/when_exe/region/shire.rb +222 -223
  67. data/lib/when_exe/region/symmetry.rb +50 -50
  68. data/lib/when_exe/region/thai.rb +336 -336
  69. data/lib/when_exe/region/tibetan.rb +315 -316
  70. data/lib/when_exe/region/tranquility.rb +207 -208
  71. data/lib/when_exe/region/vanishing_leprechaun.rb +3 -1
  72. data/lib/when_exe/region/vietnamese.rb +449 -440
  73. data/lib/when_exe/region/weekdate.rb +80 -80
  74. data/lib/when_exe/region/world.rb +170 -171
  75. data/lib/when_exe/region/world_season.rb +89 -89
  76. data/lib/when_exe/region/yerm.rb +3 -3
  77. data/lib/when_exe/region/zoroastrian.rb +205 -205
  78. data/lib/when_exe/timestandard.rb +708 -707
  79. data/lib/when_exe/tmduration.rb +338 -338
  80. data/lib/when_exe/tmobjects.rb +1356 -1356
  81. data/lib/when_exe/tmposition.rb +66 -31
  82. data/lib/when_exe/version.rb +16 -2
  83. data/test/examples/Residue.m17n +83 -83
  84. data/test/examples/Terms.m17n +2 -2
  85. data/test/test.rb +2 -2
  86. data/test/test/google_api.rb +65 -0
  87. data/test/test/linkeddata.rb +1 -1
  88. data/test/test/{googlecalendar.rb → obsolete/googlecalendar.rb} +194 -194
  89. data/test/test/region/indian.rb +90 -85
  90. data/test/test/region/m17n.rb +7 -7
  91. data/test/test/region/mayan.rb +195 -195
  92. data/test/test/region/residue.rb +153 -153
  93. data/test/test/tmposition.rb +11 -1
  94. data/when_exe.gemspec +2 -2
  95. metadata +95 -8
  96. data/test/test.rb.config +0 -1
@@ -1482,6 +1482,11 @@ module When::Coordinates
1482
1482
  # 要素の正規化
1483
1483
  def _normalize(args=[], options={})
1484
1484
 
1485
+ # 同一視
1486
+ @long ||= @longitude
1487
+ @lat ||= @latitude
1488
+ @alt ||= @altitude
1489
+
1485
1490
  # 時間帯による指定
1486
1491
  @tz = When::Parts::Timezone.tz_info[@tz] if @tz.kind_of?(String)
1487
1492
  if @tz
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2013-2014 Takashi SUGA
3
+ Copyright (C) 2013-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
@@ -1,116 +1,147 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2013 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
- =end
7
-
8
- #
9
- # When::TM::Duration のための標準クラスの拡張
10
- #
11
-
12
- #
13
- # When::TM::Duration
14
- #
15
- # @private
16
- class When::TM::Duration
17
- def rational_duration
18
- unless @rational_duration
19
- sec = duration / When::TM::Duration::SECOND
20
- mod = sec % When::TM::Duration::DAY.to_i
21
- if mod == 0 || mod != mod.to_i
22
- @rational_duration = @duration / When::TM::Duration::DAY
23
- else
24
- @rational_duration = Rational(sec.to_i, 86400)
25
- end
26
- end
27
-
28
- @rational_duration
29
- end
30
- end
31
-
32
- #
33
- # Extensions to Date class
34
- #
35
- # @private
36
- if ::Object.const_defined?(:Date) && ::Date.method_defined?(:+)
37
- class Date
38
-
39
- alias :_plus_ :+
40
- def +(other)
41
- other.kind_of?(When::TM::Duration) ? self + other.rational_duration : self._plus_(other)
42
- end
43
-
44
-
45
- alias :_minus_ :-
46
- def -(other)
47
- case other
48
- when When::TM::Duration ; self - other.rational_duration
49
- when When::TimeValue ; self._minus_(other.to_date_or_datetime)
50
- else ; self._minus_(other)
51
- end
52
- end
53
- end
54
- end
55
-
56
- #
57
- # Extensions to Time class
58
- #
59
- # @private
60
- class Time
61
-
62
- alias :_plus_ :+
63
- def +(other)
64
- other.kind_of?(When::TM::Duration) ? self + other.to_f : self._plus_(other)
65
- end
66
-
67
-
68
- alias :_minus_ :-
69
- def -(other)
70
- other.kind_of?(When::TM::Duration) ? self - other.to_f : self._minus_(other)
71
- end
72
- end
73
-
74
- #
75
- # Extensions to Numeric class
76
- #
77
- class Numeric
78
-
79
- #
80
- # メソッド名に相当する単位で表した When::TM::Duration
81
- # @method unit_duration
82
- # @return [When::TM::Duration]
83
- # @note unit second, minute, hour, day, week または
84
- # seconds, minutes, hours, days, weeks に読み替える
85
- # @note core/duration
86
-
87
- # @private
88
- When::TM::Duration::Unit.keys.each do |key|
89
-
90
- module_eval %Q{
91
- # for When::TM::Duration
92
- def #{key}_duration
93
- When::TM::Duration.new(self * When::TM::Duration::Unit['#{key}'])
94
- end
95
- alias :#{key}s_duration :#{key}_duration
96
- }
97
- end
98
- end
99
-
100
- #
101
- # Extensions to Array class
102
- #
103
- class Array
104
-
105
- #
106
- # self Array<日, 時, 分, 秒> とみなして When::TM::Duration を生成
107
- #
108
- # @return [When::TM::Duration]
109
- #
110
- # @note core/duration
111
- #
112
- def duration
113
- When::TM::Duration.dhms(*self)
114
- end
115
- alias :to_duration :duration
116
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2013-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
+ #
9
+ # When::TM::Duration のための標準クラスの拡張
10
+ #
11
+
12
+ #
13
+ # When::TM::Duration
14
+ #
15
+ # @private
16
+ class When::TM::Duration
17
+ def rational_duration
18
+ unless @rational_duration
19
+ sec = duration / When::TM::Duration::SECOND
20
+ mod = sec % When::TM::Duration::DAY.to_i
21
+ if mod == 0 || mod != mod.to_i
22
+ @rational_duration = @duration / When::TM::Duration::DAY
23
+ else
24
+ @rational_duration = Rational(sec.to_i, 86400)
25
+ end
26
+ end
27
+
28
+ @rational_duration
29
+ end
30
+ end
31
+
32
+ #
33
+ # Extensions to Date class
34
+ #
35
+ # @private
36
+ if ::Object.const_defined?(:Date) && ::Date.method_defined?(:+)
37
+ class Date
38
+
39
+ # @private
40
+ alias :_plus_ :+
41
+
42
+ # 加算
43
+ #
44
+ # @param [When::TM::Duration] other 加える時間間隔(他の型の場合は動作に変更なし)
45
+ #
46
+ # @return [::Date]
47
+ #
48
+ def +(other)
49
+ other.kind_of?(When::TM::Duration) ? self + other.rational_duration : self._plus_(other)
50
+ end
51
+
52
+
53
+ # @private
54
+ alias :_minus_ :-
55
+
56
+ # 減算
57
+ #
58
+ # @param [When::TM::Duration] other 減じる時間間隔(他の型の場合は動作に変更なし)
59
+ #
60
+ # @return [::Date]
61
+ #
62
+ def -(other)
63
+ case other
64
+ when When::TM::Duration ; self - other.rational_duration
65
+ when When::TimeValue ; self._minus_(other.to_date_or_datetime)
66
+ else ; self._minus_(other)
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ #
73
+ # Extensions to Time class
74
+ #
75
+ # @private
76
+ class Time
77
+
78
+ # @private
79
+ alias :_plus_ :+
80
+
81
+ # 加算
82
+ #
83
+ # @param [When::TM::Duration] other 加える時間間隔(他の型の場合は動作に変更なし)
84
+ #
85
+ # @return [::Time]
86
+ #
87
+ def +(other)
88
+ other.kind_of?(When::TM::Duration) ? self + other.to_f : self._plus_(other)
89
+ end
90
+
91
+ # @private
92
+ alias :_minus_ :-
93
+
94
+ # 減算
95
+ #
96
+ # @param [When::TM::Duration] other 減じる時間間隔(他の型の場合は動作に変更なし)
97
+ #
98
+ # @return [::Time]
99
+ #
100
+ def -(other)
101
+ other.kind_of?(When::TM::Duration) ? self - other.to_f : self._minus_(other)
102
+ end
103
+ end
104
+
105
+ #
106
+ # Extensions to Numeric class
107
+ #
108
+ class Numeric
109
+
110
+ #
111
+ # メソッド名に相当する単位で表した When::TM::Duration
112
+ # @method unit_duration
113
+ # @return [When::TM::Duration]
114
+ # @note unit は second, minute, hour, day, week または
115
+ # seconds, minutes, hours, days, weeks に読み替える
116
+ # @note core/duration
117
+
118
+ # @private
119
+ When::TM::Duration::Unit.keys.each do |key|
120
+
121
+ module_eval %Q{
122
+ # for When::TM::Duration
123
+ def #{key}_duration
124
+ When::TM::Duration.new(self * When::TM::Duration::Unit['#{key}'])
125
+ end
126
+ alias :#{key}s_duration :#{key}_duration
127
+ }
128
+ end
129
+ end
130
+
131
+ #
132
+ # Extensions to Array class
133
+ #
134
+ class Array
135
+
136
+ #
137
+ # self を Array<日, 時, 分, 秒> とみなして When::TM::Duration を生成
138
+ #
139
+ # @return [When::TM::Duration]
140
+ #
141
+ # @note core/duration
142
+ #
143
+ def duration
144
+ When::TM::Duration.dhms(*self)
145
+ end
146
+ alias :to_duration :duration
147
+ end
@@ -1,497 +1,499 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2013-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
- require 'when_exe/core/duration'
9
-
10
- #
11
- # 標準クラスの拡張
12
- #
13
-
14
- #
15
- # Extensions to Time class
16
- #
17
- class Time
18
- #
19
- # 対応する When::TM::JulianDate を生成
20
- #
21
- # @param [Hash] options 以下の通り
22
- # @option options [When::TM::Clock] :clock
23
- # @option options [When::Parts::Timezone] :tz
24
- #
25
- # @return [When::TM::JulianDate]
26
- #
27
- # @note core/extension
28
- #
29
- def julian_date(options={})
30
- options[:clock] ||= Clock(self.utc_offset)
31
- When::TM::JulianDate.universal_time(self.to_f * When::TM::IntervalLength::SECOND, options)
32
- end
33
- alias :to_julian_date :julian_date
34
-
35
- #
36
- # 対応する When::TM::DateAndTime を生成
37
- #
38
- # @param [Hash] options 暦法や時法などの指定
39
- #
40
- # @see When::TM::TemporalPosition._instance
41
- #
42
- # @return [When::TM::DateAndTime]
43
- #
44
- # @note core/extension
45
- #
46
- def tm_pos(options={})
47
- When.at(self, options)
48
- end
49
- alias :to_tm_pos :tm_pos
50
- end
51
-
52
- #
53
- # Extensions to Date class
54
- #
55
- if ::Object.const_defined?(:Date) && ::Date.method_defined?(:+)
56
- class Date
57
-
58
- if When::TM.const_defined?(:TemporalPosition)
59
-
60
- include When::TM::TemporalPosition::Conversion
61
-
62
- #
63
- # 対応する When::TM::CalDate or DateAndTime を生成
64
- #
65
- # @param [Hash] options 暦法や時法などの指定
66
- # see {When::TM::TemporalPosition._instance}
67
- #
68
- # @return [When::TM::CalDate, When::TM::DateAndTime]
69
- #
70
- # @note 暦法の指定がない場合、start メソッドの値によって
71
- # Julian / Gregorian / Civil 暦法を選択する
72
- #
73
- def tm_pos(options={})
74
- options[:frame] ||= When::CalendarTypes::Christian._default_start(self)
75
- super(options)
76
- end
77
- alias :to_tm_pos :tm_pos
78
- end
79
-
80
- alias :__method_missing :method_missing
81
-
82
- # その他のメソッド
83
- #
84
- # @note
85
- # self で定義されていないメソッドは
86
- # tm_pos で変換して処理する
87
- #
88
- def method_missing(name, *args, &block)
89
- return __method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
90
- self.class.module_eval %Q{
91
- def #{name}(*args, &block)
92
- result = tm_pos.send("#{name}", *args, &block)
93
- result.kind_of?(When::TimeValue) ? result.to_date_or_datetime : result
94
- end
95
- } unless When::Parts::MethodCash.escape(name)
96
- result = tm_pos.send(name, *args, &block)
97
- result.kind_of?(When::TimeValue) ? result.to_date_or_datetime : result
98
- end
99
- end
100
- end
101
-
102
- #
103
- # Extensions to Numeric class
104
- #
105
- class Numeric
106
-
107
- include When::TM::TemporalPosition::Conversion if When::TM.const_defined?(:TemporalPosition)
108
-
109
- #
110
- # 曜日(剰余類)
111
- #
112
- # @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類)
113
- #
114
- # @note core/extension
115
- #
116
- def to_day_of_week
117
- When::Coordinates::Residue.day_of_week(self)
118
- end
119
- alias :day_of_week :to_day_of_week
120
-
121
- #
122
- # 月名
123
- #
124
- # self が 月番号の月名を返します
125
- #
126
- # @return [When::BasicTypes::M17n] 月名
127
- #
128
- # @note core/extension
129
- #
130
- def to_month_name
131
- When::BasicTypes::M17n.month_name(self)
132
- end
133
- alias :month_name :to_month_name
134
-
135
- # self を幹の要素と解釈してWhen::Coordinates::Pair を生成
136
- #
137
- # @see When::Coordinates::Pair._force_pair
138
- #
139
- # @return [When::Coordinates::Pair]
140
- #
141
- def to_pair(branch=nil)
142
- Coordinates::Pair._force_pair(self, branch)
143
- end
144
- alias :pair :to_pair
145
-
146
- #
147
- # self を秒数とみなして When::Parts::Timezone::Base を取得
148
- #
149
- # @return [When::Parts::Timezone::Base]
150
- #
151
- # @note core/extension
152
- #
153
- def clock
154
- When.Clock(self)
155
- end
156
- alias :to_clock :clock
157
-
158
- # メソッド名に相当する単位で表した When::TM::IntervalLength
159
- # @method unit_interval_length
160
- # @return [When::TM::IntervalLength]
161
- #
162
- # @note unit は second, minute, hour, day, week または
163
- # seconds, minutes, hours, days, weeks に読み替える
164
- #
165
- # @note core/extension
166
-
167
- # メソッド名に相当する単位で表した When::TM::PeriodDuration
168
- # @method unit_period_duration
169
- # @return [When::TM::PeriodDuration]
170
- #
171
- # @note unit は second, minute, hour, day, week, month, year または
172
- # seconds, minutes, hours, days, weeks, months, years に読み替える
173
- #
174
- # @note core/extension
175
-
176
- # @private
177
- When::TM::Duration::Unit.keys.each do |key|
178
-
179
- module_eval %Q{
180
- # for When::TM::IntervalLength
181
- def #{key}_interval_length
182
- When::TM::IntervalLength.new(self, '#{key}')
183
- end
184
- alias :#{key}s_interval_length :#{key}_interval_length
185
-
186
- # for When::TM::PeriodDuration
187
- def #{key}_period_duration
188
- When::TM::PeriodDuration.new(self, When::#{key.upcase})
189
- end
190
- alias :#{key}s_period_duration :#{key}_period_duration
191
- }
192
- end
193
- end
194
-
195
- #
196
- # Extensions to String class
197
- #
198
- class String
199
-
200
- include When::EncodingConversion
201
-
202
- #
203
- # self を When::BasicTypes::M17n に変換する
204
- #
205
- # @return [When::BasicTypes::M17n]
206
- #
207
- # @note core/extension
208
- #
209
- def to_m17n
210
- When::BasicTypes::M17n.new(self)
211
- end
212
-
213
- # 特定 locale に対応した文字列の取得
214
- #
215
- # @param [String] loc locale の指定
216
- #
217
- # @return [String] loc に対応した文字列
218
- #
219
- # @note core/extension
220
- #
221
- def translate(loc='')
222
- return encode($1) if loc =~ /\.(.+)\z/
223
- return self
224
- end
225
- alias :/ :translate
226
-
227
- # 包摂リストに登録されている文字を包摂する
228
- #
229
- # @param [Hash] pattern 包摂ルール
230
- #
231
- # @return [String] 包摂結果
232
- #
233
- def ideographic_unification(pattern=When::Locale._unification)
234
- When::Locale.ideographic_unification(self, pattern)
235
- end
236
-
237
- #
238
- # self を IRI とみなして When::Parts::Resource を取得
239
- #
240
- # @param [String] namespace デフォルトの namespace
241
- #
242
- # @return [When::Parts::Resource]
243
- #
244
- # @note core/extension
245
- #
246
- def resource(namespace=nil)
247
- When::Parts::Resource._instance(self, namespace)
248
- end
249
- alias :to_resource :resource
250
-
251
- #
252
- # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::Calendar を取得
253
- #
254
- # @return [When::TM::Calendar]
255
- #
256
- # @note core/extension
257
- #
258
- def calendar
259
- When::Parts::Resource._instance(self, '_c:')
260
- end
261
- alias :to_calendar :calendar
262
-
263
- #
264
- # self を時間帯文字列とみなして When::Parts::Timezone::Base を取得
265
- #
266
- # @return [When::Parts::Timezone::Base]
267
- #
268
- # @note core/extension
269
- #
270
- def clock
271
- When.Clock(self)
272
- end
273
- alias :to_clock :clock
274
-
275
- #
276
- # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::CalendarNote を取得
277
- #
278
- # @return [When::TM::CalendarNote]
279
- #
280
- # @note core/extension
281
- #
282
- def calendar_note
283
- When::Parts::Resource._instance(self, '_n:')
284
- end
285
- alias :to_calendar_note :calendar_note
286
-
287
- #
288
- # self をプレフィクス '_e:' を省略した IRI とみなして When::TM::CalendarEra を取得
289
- #
290
- # @return [When::TM::CalendarEra]
291
- #
292
- # @note core/extension
293
- #
294
- def calendar_era
295
- When::Parts::Resource._instance(self, '_e:')
296
- end
297
- alias :to_calendar_era :calendar_era
298
-
299
- #
300
- # self をプレフィクス '_m:' を省略した IRI とみなして When::BasicTypes::M17n を取得
301
- #
302
- # @return [When::BasicTypes::M17n]
303
- #
304
- # @note core/extension
305
- #
306
- def m17n
307
- When::Parts::Resource._instance(self, '_m:')
308
- end
309
-
310
- # self を幹と枝の要素と解釈してWhen::Coordinates::Pair を生成
311
- #
312
- # @see When::Coordinates::Pair._force_pair
313
- #
314
- # @return [When::Coordinates::Pair]
315
- #
316
- def to_pair
317
- Coordinates::Pair._force_pair(self)
318
- end
319
- alias :pair :to_pair
320
-
321
- #
322
- # self を検索する暦年代とみなして登録された When::TM::CalendarEraを検索
323
- #
324
- # @overload calendar_era(options={}
325
- # @param [Hash] options
326
- # see alse {When.era}
327
- #
328
- # @return [Array<When::TM::CalendarEra>]
329
- #
330
- # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
331
- # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
332
- # 生成しつつ読み込んで検索する。
333
- #
334
- # @note core/extension
335
- #
336
- def era(*args)
337
- When::TM::CalendarEra._instance(*([self] + args))
338
- end
339
- alias :to_era :era
340
-
341
- #
342
- # self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成
343
- #
344
- # @param [Hash] options 暦法や時法などの指定
345
- #
346
- # @see When::TM::TemporalPosition._instance
347
- #
348
- # @return [When::TM::TemporalPosition]
349
- #
350
- # @note core/extension
351
- #
352
- def when?(options={})
353
- When.when?(self, options)
354
- end
355
- alias :tm_pos :when?
356
- alias :to_tm_pos :when?
357
-
358
- #
359
- # 曜日(剰余類)
360
- #
361
- # self の最初の3文字から決定した七曜(剰余類)を返します。
362
- # 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
363
- #
364
- # @return [When::Coordinates::Residue]
365
- # [ 月曜を 0 とする七曜(剰余類) ]
366
- # [ 名前の一致するその他の剰余類 ]
367
- #
368
- # @note core/extension
369
- #
370
- def to_residue
371
- When::Coordinates::Residue.to_residue(self)
372
- end
373
- alias :residue :to_residue
374
- alias :day_of_week :to_residue
375
-
376
- #
377
- # 月名
378
- #
379
- # self の最初の3文字から決定した月名を返します。
380
- # 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
381
- # (self が M17n なら name 自身をそのまま返します)
382
- #
383
- # @return [When::BasicTypes::M17n] 月名
384
- #
385
- # @note core/extension
386
- #
387
- def to_month_name
388
- When::BasicTypes::M17n.month_name(self)
389
- end
390
- alias :month_name :to_month_name
391
-
392
- #
393
- # self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成し“^”演算を実行
394
- #
395
- # @return [When::TM::TemporalPosition の “^”演算結果]
396
- #
397
- # @note core/extension
398
- #
399
- def ^(other)
400
- When::TM::TemporalPosition._instance(self, {}) ^ other
401
- end
402
- end
403
-
404
- #
405
- # Extensions to Regexp class
406
- #
407
- class Regexp
408
-
409
- include When::EncodingConversion
410
-
411
- #
412
- # self を検索する暦年代にマッチする正規表現とみなして登録された When::TM::CalendarEraを検索
413
- #
414
- # @overload calendar_era(options={}
415
- # @param [Hash] options
416
- # see also {When.era}
417
- #
418
- # @return [Array<When::TM::CalendarEra>]
419
- #
420
- # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
421
- # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
422
- # 生成しつつ読み込んで検索する。
423
- #
424
- # @note core/extension
425
- #
426
- def era(*args)
427
- When::TM::CalendarEra._instance(*([self] + args))
428
- end
429
- alias :to_era :era
430
-
431
- # 包摂リストに登録されている文字を包摂する
432
- #
433
- # @param [Hash] pattern 包摂ルール
434
- #
435
- # @return [Regexp] 包摂結果
436
- #
437
- def ideographic_unification(pattern=When::Locale._unification)
438
- When::Locale.ideographic_unification(self, pattern)
439
- end
440
- end
441
-
442
- #
443
- # Extensions to Array class
444
- #
445
- class Array
446
- #
447
- # self を暦要素の Array とみなして [When::TM::TemporalPosition] を生成
448
- #
449
- # @param [Hash] options 暦法や時法などの指定
450
- # @option options [Symbol] :invalid
451
- # [:raise 日時が存在しない場合例外発生 ]
452
- # [:check 日時が存在しない場合 nil を返す ]
453
- # [その他/nil 日時が存在することを確認しない(デフォルト)]
454
- # see also {When::TM::TemporalPosition._instance}
455
- #
456
- # @return [When::TM::TemporalPosition]
457
- # @raise [ArgumentError]
458
- # options[ :invalid ] が :raise で、日時が存在しない場合
459
- #
460
- # @note core/extension
461
- #
462
- def tm_pos(options={})
463
- When.TemporalPosition(*(self.dup << options))
464
- end
465
- alias :to_tm_pos :tm_pos
466
-
467
- # self を[幹,枝]と解釈してWhen::Coordinates::Pair を生成
468
- #
469
- # @see When::Coordinates::Pair._force_pair
470
- #
471
- # @return [When::Coordinates::Pair]
472
- #
473
- def to_pair
474
- Coordinates::Pair._force_pair(*self)
475
- end
476
- alias :pair :to_pair
477
- end
478
-
479
- #
480
- # Extensions to Module class
481
- #
482
- class Module
483
- unless method_defined?(:_const_missing)
484
- alias :_const_missing :const_missing
485
-
486
- #
487
- # When 直下に定数として定義する時法・暦法(暗黙的追加)
488
- #
489
- def const_missing(name)
490
- if When.const_defined?(name)
491
- _const_missing(name)
492
- else
493
- When.const_missing(name)
494
- end
495
- end
496
- end
497
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2013-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
+ require 'when_exe/core/duration'
9
+
10
+ #
11
+ # 標準クラスの拡張
12
+ #
13
+
14
+ #
15
+ # Extensions to Time class
16
+ #
17
+ class Time
18
+ #
19
+ # 対応する When::TM::JulianDate を生成
20
+ #
21
+ # @param [Hash] options 以下の通り
22
+ # @option options [When::TM::Clock] :clock
23
+ # @option options [When::Parts::Timezone] :tz
24
+ #
25
+ # @return [When::TM::JulianDate]
26
+ #
27
+ # @note core/extension
28
+ #
29
+ def julian_date(options={})
30
+ options[:clock] ||= Clock(self.utc_offset)
31
+ When::TM::JulianDate.universal_time(self.to_f * When::TM::IntervalLength::SECOND, options)
32
+ end
33
+ alias :to_julian_date :julian_date
34
+
35
+ #
36
+ # 対応する When::TM::DateAndTime を生成
37
+ #
38
+ # @param [Hash] options 暦法や時法などの指定
39
+ #
40
+ # @see When::TM::TemporalPosition._instance
41
+ #
42
+ # @return [When::TM::DateAndTime]
43
+ #
44
+ # @note core/extension
45
+ #
46
+ def tm_pos(options={})
47
+ When.at(self, options)
48
+ end
49
+ alias :to_tm_pos :tm_pos
50
+ end
51
+
52
+ #
53
+ # Extensions to Date class
54
+ #
55
+ if ::Object.const_defined?(:Date) && ::Date.method_defined?(:+)
56
+ class Date
57
+
58
+ if When::TM.const_defined?(:TemporalPosition)
59
+
60
+ include When::TM::TemporalPosition::Conversion
61
+
62
+ #
63
+ # 対応する When::TM::CalDate or DateAndTime を生成
64
+ #
65
+ # @param [Hash] options 暦法や時法などの指定
66
+ # see {When::TM::TemporalPosition._instance}
67
+ #
68
+ # @return [When::TM::CalDate, When::TM::DateAndTime]
69
+ #
70
+ # @note 暦法の指定がない場合、start メソッドの値によって
71
+ # Julian / Gregorian / Civil 暦法を選択する
72
+ #
73
+ def tm_pos(options={})
74
+ options[:frame] ||= When::CalendarTypes::Christian._default_start(self)
75
+ super(options)
76
+ end
77
+ alias :to_tm_pos :tm_pos
78
+ end
79
+
80
+ private
81
+
82
+ alias :__method_missing :method_missing
83
+
84
+ # その他のメソッド
85
+ #
86
+ # @note
87
+ # self で定義されていないメソッドは
88
+ # tm_pos で変換して処理する
89
+ #
90
+ def method_missing(name, *args, &block)
91
+ return __method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
92
+ self.class.module_eval %Q{
93
+ def #{name}(*args, &block)
94
+ result = tm_pos.send("#{name}", *args, &block)
95
+ result.kind_of?(When::TimeValue) ? result.to_date_or_datetime : result
96
+ end
97
+ } unless When::Parts::MethodCash.escape(name)
98
+ result = tm_pos.send(name, *args, &block)
99
+ result.kind_of?(When::TimeValue) ? result.to_date_or_datetime : result
100
+ end
101
+ end
102
+ end
103
+
104
+ #
105
+ # Extensions to Numeric class
106
+ #
107
+ class Numeric
108
+
109
+ include When::TM::TemporalPosition::Conversion if When::TM.const_defined?(:TemporalPosition)
110
+
111
+ #
112
+ # 曜日(剰余類)
113
+ #
114
+ # @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類)
115
+ #
116
+ # @note core/extension
117
+ #
118
+ def to_day_of_week
119
+ When::Coordinates::Residue.day_of_week(self)
120
+ end
121
+ alias :day_of_week :to_day_of_week
122
+
123
+ #
124
+ # 月名
125
+ #
126
+ # self 月番号の月名を返します
127
+ #
128
+ # @return [When::BasicTypes::M17n] 月名
129
+ #
130
+ # @note core/extension
131
+ #
132
+ def to_month_name
133
+ When::BasicTypes::M17n.month_name(self)
134
+ end
135
+ alias :month_name :to_month_name
136
+
137
+ # self を幹の要素と解釈してWhen::Coordinates::Pair を生成
138
+ #
139
+ # @see When::Coordinates::Pair._force_pair
140
+ #
141
+ # @return [When::Coordinates::Pair]
142
+ #
143
+ def to_pair(branch=nil)
144
+ Coordinates::Pair._force_pair(self, branch)
145
+ end
146
+ alias :pair :to_pair
147
+
148
+ #
149
+ # self を秒数とみなして When::Parts::Timezone::Base を取得
150
+ #
151
+ # @return [When::Parts::Timezone::Base]
152
+ #
153
+ # @note core/extension
154
+ #
155
+ def clock
156
+ When.Clock(self)
157
+ end
158
+ alias :to_clock :clock
159
+
160
+ # メソッド名に相当する単位で表した When::TM::IntervalLength
161
+ # @method unit_interval_length
162
+ # @return [When::TM::IntervalLength]
163
+ #
164
+ # @note unit は second, minute, hour, day, week または
165
+ # seconds, minutes, hours, days, weeks に読み替える
166
+ #
167
+ # @note core/extension
168
+
169
+ # メソッド名に相当する単位で表した When::TM::PeriodDuration
170
+ # @method unit_period_duration
171
+ # @return [When::TM::PeriodDuration]
172
+ #
173
+ # @note unit は second, minute, hour, day, week, month, year または
174
+ # seconds, minutes, hours, days, weeks, months, years に読み替える
175
+ #
176
+ # @note core/extension
177
+
178
+ # @private
179
+ When::TM::Duration::Unit.keys.each do |key|
180
+
181
+ module_eval %Q{
182
+ # for When::TM::IntervalLength
183
+ def #{key}_interval_length
184
+ When::TM::IntervalLength.new(self, '#{key}')
185
+ end
186
+ alias :#{key}s_interval_length :#{key}_interval_length
187
+
188
+ # for When::TM::PeriodDuration
189
+ def #{key}_period_duration
190
+ When::TM::PeriodDuration.new(self, When::#{key.upcase})
191
+ end
192
+ alias :#{key}s_period_duration :#{key}_period_duration
193
+ }
194
+ end
195
+ end
196
+
197
+ #
198
+ # Extensions to String class
199
+ #
200
+ class String
201
+
202
+ include When::EncodingConversion
203
+
204
+ #
205
+ # self When::BasicTypes::M17n に変換する
206
+ #
207
+ # @return [When::BasicTypes::M17n]
208
+ #
209
+ # @note core/extension
210
+ #
211
+ def to_m17n
212
+ When::BasicTypes::M17n.new(self)
213
+ end
214
+
215
+ # 特定 locale に対応した文字列の取得
216
+ #
217
+ # @param [String] loc locale の指定
218
+ #
219
+ # @return [String] loc に対応した文字列
220
+ #
221
+ # @note core/extension
222
+ #
223
+ def translate(loc='')
224
+ return encode($1) if loc =~ /\.(.+)\z/
225
+ return self
226
+ end
227
+ alias :/ :translate
228
+
229
+ # 包摂リストに登録されている文字を包摂する
230
+ #
231
+ # @param [Hash] pattern 包摂ルール
232
+ #
233
+ # @return [String] 包摂結果
234
+ #
235
+ def ideographic_unification(pattern=When::Locale._unification)
236
+ When::Locale.ideographic_unification(self, pattern)
237
+ end
238
+
239
+ #
240
+ # self IRI とみなして When::Parts::Resource を取得
241
+ #
242
+ # @param [String] namespace デフォルトの namespace
243
+ #
244
+ # @return [When::Parts::Resource]
245
+ #
246
+ # @note core/extension
247
+ #
248
+ def resource(namespace=nil)
249
+ When::Parts::Resource._instance(self, namespace)
250
+ end
251
+ alias :to_resource :resource
252
+
253
+ #
254
+ # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::Calendar を取得
255
+ #
256
+ # @return [When::TM::Calendar]
257
+ #
258
+ # @note core/extension
259
+ #
260
+ def calendar
261
+ When::Parts::Resource._instance(self, '_c:')
262
+ end
263
+ alias :to_calendar :calendar
264
+
265
+ #
266
+ # self を時間帯文字列とみなして When::Parts::Timezone::Base を取得
267
+ #
268
+ # @return [When::Parts::Timezone::Base]
269
+ #
270
+ # @note core/extension
271
+ #
272
+ def clock
273
+ When.Clock(self)
274
+ end
275
+ alias :to_clock :clock
276
+
277
+ #
278
+ # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::CalendarNote を取得
279
+ #
280
+ # @return [When::TM::CalendarNote]
281
+ #
282
+ # @note core/extension
283
+ #
284
+ def calendar_note
285
+ When::Parts::Resource._instance(self, '_n:')
286
+ end
287
+ alias :to_calendar_note :calendar_note
288
+
289
+ #
290
+ # self をプレフィクス '_e:' を省略した IRI とみなして When::TM::CalendarEra を取得
291
+ #
292
+ # @return [When::TM::CalendarEra]
293
+ #
294
+ # @note core/extension
295
+ #
296
+ def calendar_era
297
+ When::Parts::Resource._instance(self, '_e:')
298
+ end
299
+ alias :to_calendar_era :calendar_era
300
+
301
+ #
302
+ # self をプレフィクス '_m:' を省略した IRI とみなして When::BasicTypes::M17n を取得
303
+ #
304
+ # @return [When::BasicTypes::M17n]
305
+ #
306
+ # @note core/extension
307
+ #
308
+ def m17n
309
+ When::Parts::Resource._instance(self, '_m:')
310
+ end
311
+
312
+ # self を幹と枝の要素と解釈してWhen::Coordinates::Pair を生成
313
+ #
314
+ # @see When::Coordinates::Pair._force_pair
315
+ #
316
+ # @return [When::Coordinates::Pair]
317
+ #
318
+ def to_pair
319
+ Coordinates::Pair._force_pair(self)
320
+ end
321
+ alias :pair :to_pair
322
+
323
+ #
324
+ # self を検索する暦年代とみなして登録された When::TM::CalendarEraを検索
325
+ #
326
+ # @overload calendar_era(options={}
327
+ # @param [Hash] options
328
+ # see alse {When.era}
329
+ #
330
+ # @return [Array<When::TM::CalendarEra>]
331
+ #
332
+ # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
333
+ # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
334
+ # 生成しつつ読み込んで検索する。
335
+ #
336
+ # @note core/extension
337
+ #
338
+ def era(*args)
339
+ When::TM::CalendarEra._instance(*([self] + args))
340
+ end
341
+ alias :to_era :era
342
+
343
+ #
344
+ # self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成
345
+ #
346
+ # @param [Hash] options 暦法や時法などの指定
347
+ #
348
+ # @see When::TM::TemporalPosition._instance
349
+ #
350
+ # @return [When::TM::TemporalPosition]
351
+ #
352
+ # @note core/extension
353
+ #
354
+ def when?(options={})
355
+ When.when?(self, options)
356
+ end
357
+ alias :tm_pos :when?
358
+ alias :to_tm_pos :when?
359
+
360
+ #
361
+ # 曜日(剰余類)
362
+ #
363
+ # self の最初の3文字から決定した七曜(剰余類)を返します。
364
+ # 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
365
+ #
366
+ # @return [When::Coordinates::Residue]
367
+ # [ 月曜を 0 とする七曜(剰余類) ]
368
+ # [ 名前の一致するその他の剰余類 ]
369
+ #
370
+ # @note core/extension
371
+ #
372
+ def to_residue
373
+ When::Coordinates::Residue.to_residue(self)
374
+ end
375
+ alias :residue :to_residue
376
+ alias :day_of_week :to_residue
377
+
378
+ #
379
+ # 月名
380
+ #
381
+ # self の最初の3文字から決定した月名を返します。
382
+ # 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
383
+ # (self M17n なら name 自身をそのまま返します)
384
+ #
385
+ # @return [When::BasicTypes::M17n] 月名
386
+ #
387
+ # @note core/extension
388
+ #
389
+ def to_month_name
390
+ When::BasicTypes::M17n.month_name(self)
391
+ end
392
+ alias :month_name :to_month_name
393
+
394
+ #
395
+ # self When.exe Standard Expression とみなして When::TM::TemporalPosition を生成し“^”演算を実行
396
+ #
397
+ # @return [When::TM::TemporalPosition の “^”演算結果]
398
+ #
399
+ # @note core/extension
400
+ #
401
+ def ^(other)
402
+ When::TM::TemporalPosition._instance(self, {}) ^ other
403
+ end
404
+ end
405
+
406
+ #
407
+ # Extensions to Regexp class
408
+ #
409
+ class Regexp
410
+
411
+ include When::EncodingConversion
412
+
413
+ #
414
+ # self を検索する暦年代にマッチする正規表現とみなして登録された When::TM::CalendarEraを検索
415
+ #
416
+ # @overload calendar_era(options={}
417
+ # @param [Hash] options
418
+ # see also {When.era}
419
+ #
420
+ # @return [Array<When::TM::CalendarEra>]
421
+ #
422
+ # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
423
+ # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
424
+ # 生成しつつ読み込んで検索する。
425
+ #
426
+ # @note core/extension
427
+ #
428
+ def era(*args)
429
+ When::TM::CalendarEra._instance(*([self] + args))
430
+ end
431
+ alias :to_era :era
432
+
433
+ # 包摂リストに登録されている文字を包摂する
434
+ #
435
+ # @param [Hash] pattern 包摂ルール
436
+ #
437
+ # @return [Regexp] 包摂結果
438
+ #
439
+ def ideographic_unification(pattern=When::Locale._unification)
440
+ When::Locale.ideographic_unification(self, pattern)
441
+ end
442
+ end
443
+
444
+ #
445
+ # Extensions to Array class
446
+ #
447
+ class Array
448
+ #
449
+ # self を暦要素の Array とみなして [When::TM::TemporalPosition] を生成
450
+ #
451
+ # @param [Hash] options 暦法や時法などの指定
452
+ # @option options [Symbol] :invalid
453
+ # [:raise 日時が存在しない場合例外発生 ]
454
+ # [:check 日時が存在しない場合 nil を返す ]
455
+ # [その他/nil 日時が存在することを確認しない(デフォルト)]
456
+ # see also {When::TM::TemporalPosition._instance}
457
+ #
458
+ # @return [When::TM::TemporalPosition]
459
+ # @raise [ArgumentError]
460
+ # options[ :invalid ] が :raise で、日時が存在しない場合
461
+ #
462
+ # @note core/extension
463
+ #
464
+ def tm_pos(options={})
465
+ When.TemporalPosition(*(self.dup << options))
466
+ end
467
+ alias :to_tm_pos :tm_pos
468
+
469
+ # self を[幹,枝]と解釈してWhen::Coordinates::Pair を生成
470
+ #
471
+ # @see When::Coordinates::Pair._force_pair
472
+ #
473
+ # @return [When::Coordinates::Pair]
474
+ #
475
+ def to_pair
476
+ Coordinates::Pair._force_pair(*self)
477
+ end
478
+ alias :pair :to_pair
479
+ end
480
+
481
+ #
482
+ # Extensions to Module class
483
+ #
484
+ class Module
485
+ unless method_defined?(:_const_missing)
486
+ alias :_const_missing :const_missing
487
+
488
+ #
489
+ # When 直下に定数として定義する時法・暦法(暗黙的追加)
490
+ #
491
+ def const_missing(name)
492
+ if When.const_defined?(name)
493
+ _const_missing(name)
494
+ else
495
+ When.const_missing(name)
496
+ end
497
+ end
498
+ end
499
+ end