when_exe 0.2.100 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/LICENSE.ja.txt +25 -25
  2. data/LICENSE.txt +31 -31
  3. data/bin/irb.rc +5 -0
  4. data/bin/locales.rb +2 -2
  5. data/bin/when.rb +16 -0
  6. data/bin/when.rb.config +7 -0
  7. data/lib/when_exe.rb +616 -14
  8. data/lib/when_exe/basictypes.rb +615 -0
  9. data/lib/when_exe/calendartypes.rb +1700 -0
  10. data/lib/when_exe/coordinates.rb +1936 -0
  11. data/lib/when_exe/core/compatibility.rb +54 -0
  12. data/lib/when_exe/core/duration.rb +72 -72
  13. data/lib/when_exe/core/extension.rb +382 -0
  14. data/lib/when_exe/ephemeris.rb +1845 -0
  15. data/lib/when_exe/googlecalendar.rb +140 -0
  16. data/lib/when_exe/icalendar.rb +1587 -0
  17. data/lib/when_exe/inspect.rb +1237 -0
  18. data/lib/when_exe/locales/af.rb +90 -0
  19. data/lib/when_exe/locales/ar.rb +145 -0
  20. data/lib/when_exe/locales/az.rb +90 -0
  21. data/lib/when_exe/locales/bg.rb +90 -0
  22. data/lib/when_exe/locales/bn.rb +94 -0
  23. data/lib/when_exe/locales/bs.rb +121 -0
  24. data/lib/when_exe/locales/ca.rb +92 -0
  25. data/lib/when_exe/locales/cs.rb +107 -0
  26. data/lib/when_exe/locales/cy.rb +150 -0
  27. data/lib/when_exe/locales/da.rb +84 -0
  28. data/lib/when_exe/locales/de.rb +92 -0
  29. data/lib/when_exe/locales/de_AT.rb +92 -0
  30. data/lib/when_exe/locales/de_CH.rb +92 -0
  31. data/lib/when_exe/locales/el.rb +93 -0
  32. data/lib/when_exe/locales/en.rb +88 -0
  33. data/lib/when_exe/locales/en_AU.rb +88 -0
  34. data/lib/when_exe/locales/en_CA.rb +88 -0
  35. data/lib/when_exe/locales/en_GB.rb +88 -0
  36. data/lib/when_exe/locales/en_IN.rb +88 -0
  37. data/lib/when_exe/locales/en_NZ.rb +88 -0
  38. data/lib/when_exe/locales/eo.rb +89 -0
  39. data/lib/when_exe/locales/es.rb +84 -0
  40. data/lib/when_exe/locales/es_419.rb +84 -0
  41. data/lib/when_exe/locales/es_AR.rb +84 -0
  42. data/lib/when_exe/locales/es_CL.rb +84 -0
  43. data/lib/when_exe/locales/es_CO.rb +84 -0
  44. data/lib/when_exe/locales/es_MX.rb +84 -0
  45. data/lib/when_exe/locales/es_PE.rb +85 -0
  46. data/lib/when_exe/locales/es_VE.rb +84 -0
  47. data/lib/when_exe/locales/et.rb +94 -0
  48. data/lib/when_exe/locales/eu.rb +95 -0
  49. data/lib/when_exe/locales/fa.rb +80 -0
  50. data/lib/when_exe/locales/fi.rb +89 -0
  51. data/lib/when_exe/locales/fr.rb +88 -0
  52. data/lib/when_exe/locales/fr_CA.rb +88 -0
  53. data/lib/when_exe/locales/fr_CH.rb +88 -0
  54. data/lib/when_exe/locales/gl.rb +81 -0
  55. data/lib/when_exe/locales/he.rb +84 -0
  56. data/lib/when_exe/locales/hi.rb +80 -0
  57. data/lib/when_exe/locales/hi_IN.rb +84 -0
  58. data/lib/when_exe/locales/hr.rb +128 -0
  59. data/lib/when_exe/locales/hu.rb +84 -0
  60. data/lib/when_exe/locales/id.rb +89 -0
  61. data/lib/when_exe/locales/is.rb +89 -0
  62. data/lib/when_exe/locales/it.rb +87 -0
  63. data/lib/when_exe/locales/it_CH.rb +87 -0
  64. data/lib/when_exe/locales/ja.rb +78 -0
  65. data/lib/when_exe/locales/kn.rb +86 -0
  66. data/lib/when_exe/locales/ko.rb +78 -0
  67. data/lib/when_exe/locales/links.rb +2342 -0
  68. data/lib/when_exe/locales/lo.rb +123 -0
  69. data/lib/when_exe/locales/locales.rb +91 -0
  70. data/lib/when_exe/locales/lt.rb +111 -0
  71. data/lib/when_exe/locales/lv.rb +118 -0
  72. data/lib/when_exe/locales/mk.rb +93 -0
  73. data/lib/when_exe/locales/mn.rb +80 -0
  74. data/lib/when_exe/locales/nb.rb +81 -0
  75. data/lib/when_exe/locales/ne.rb +81 -0
  76. data/lib/when_exe/locales/nl.rb +92 -0
  77. data/lib/when_exe/locales/nn.rb +73 -0
  78. data/lib/when_exe/locales/or.rb +84 -0
  79. data/lib/when_exe/locales/pl.rb +128 -0
  80. data/lib/when_exe/locales/pt.rb +88 -0
  81. data/lib/when_exe/locales/pt_BR.rb +88 -0
  82. data/lib/when_exe/locales/rm.rb +143 -0
  83. data/lib/when_exe/locales/ro.rb +105 -0
  84. data/lib/when_exe/locales/ru.rb +128 -0
  85. data/lib/when_exe/locales/sk.rb +109 -0
  86. data/lib/when_exe/locales/sl.rb +122 -0
  87. data/lib/when_exe/locales/sr.rb +122 -0
  88. data/lib/when_exe/locales/sv.rb +83 -0
  89. data/lib/when_exe/locales/sw.rb +89 -0
  90. data/lib/when_exe/locales/th.rb +78 -0
  91. data/lib/when_exe/locales/tl.rb +99 -0
  92. data/lib/when_exe/locales/tr.rb +96 -0
  93. data/lib/when_exe/locales/uk.rb +128 -0
  94. data/lib/when_exe/locales/uz.rb +128 -0
  95. data/lib/when_exe/locales/vi.rb +94 -0
  96. data/lib/when_exe/locales/wo.rb +82 -0
  97. data/lib/when_exe/locales/zh_CN.rb +77 -0
  98. data/lib/when_exe/locales/zh_HK.rb +77 -0
  99. data/lib/when_exe/locales/zh_TW.rb +77 -0
  100. data/lib/when_exe/mini_application.rb +252 -0
  101. data/lib/when_exe/parts/enumerator.rb +472 -0
  102. data/lib/when_exe/parts/geometric_complex.rb +379 -0
  103. data/lib/when_exe/parts/locale.rb +513 -0
  104. data/lib/when_exe/parts/method_cash.rb +207 -0
  105. data/lib/when_exe/parts/resource.rb +806 -0
  106. data/lib/when_exe/parts/timezone.rb +182 -0
  107. data/lib/when_exe/region/bahai.rb +145 -0
  108. data/lib/when_exe/region/balinese.rb +627 -0
  109. data/lib/when_exe/region/chinese.rb +896 -0
  110. data/lib/when_exe/region/chinese_calendar.rb +919 -0
  111. data/lib/when_exe/region/chinese_epoch.rb +1245 -0
  112. data/lib/when_exe/region/christian.rb +644 -0
  113. data/lib/when_exe/region/far_east.rb +192 -0
  114. data/lib/when_exe/region/french.rb +66 -0
  115. data/lib/when_exe/region/geologicalage.rb +639 -0
  116. data/lib/when_exe/region/indian.rb +1066 -0
  117. data/lib/when_exe/region/iranian.rb +66 -0
  118. data/lib/when_exe/region/islamic.rb +105 -0
  119. data/lib/when_exe/region/japanese.rb +851 -0
  120. data/lib/when_exe/region/japanese_notes.rb +964 -0
  121. data/lib/when_exe/region/japanese_residues.rb +1149 -0
  122. data/lib/when_exe/region/javanese.rb +228 -0
  123. data/lib/when_exe/region/jewish.rb +127 -0
  124. data/lib/when_exe/region/korean.rb +267 -0
  125. data/lib/when_exe/region/m17n.rb +115 -0
  126. data/lib/when_exe/region/martian.rb +215 -0
  127. data/lib/when_exe/region/mayan.rb +122 -0
  128. data/lib/when_exe/region/moon.rb +333 -0
  129. data/lib/when_exe/region/nihon_shoki.rb +73 -0
  130. data/lib/when_exe/region/planets.rb +585 -0
  131. data/lib/when_exe/region/pope.rb +298 -0
  132. data/lib/when_exe/region/residue.rb +229 -0
  133. data/lib/when_exe/region/roman.rb +325 -0
  134. data/lib/when_exe/region/ryukyu.rb +98 -0
  135. data/lib/when_exe/region/shire.rb +254 -0
  136. data/lib/when_exe/region/sun.rb +210 -0
  137. data/lib/when_exe/region/thai.rb +227 -0
  138. data/lib/when_exe/region/tibetan.rb +233 -0
  139. data/lib/when_exe/region/v50.rb +111 -0
  140. data/lib/when_exe/region/vietnamese.rb +173 -0
  141. data/lib/when_exe/region/world.rb +197 -0
  142. data/lib/when_exe/timestandard.rb +547 -0
  143. data/lib/when_exe/tmduration.rb +330 -330
  144. data/lib/when_exe/tmobjects.rb +1295 -0
  145. data/lib/when_exe/tmposition.rb +1955 -0
  146. data/lib/when_exe/tmreference.rb +1547 -0
  147. data/lib/when_exe/version.rb +10 -3
  148. data/link_to_online_documents +4 -0
  149. data/test/examples/JapanHolidays.ics +456 -0
  150. data/test/examples/Millennium.ics +17 -0
  151. data/test/examples/NewYork.ics +61 -0
  152. data/test/examples/Residue.m17n +135 -0
  153. data/test/examples/Spatial.m17n +179 -0
  154. data/test/examples/Terms.m17n +39 -0
  155. data/test/examples/Test.ics +53 -0
  156. data/test/examples/USA-DST.ics +61 -0
  157. data/test/examples/geometric_complex.rb +41 -0
  158. data/test/examples/sample.xml +14 -0
  159. data/test/examples/today.rb +61 -0
  160. data/test/test.rb +54 -19
  161. data/test/test.rb.config +1 -0
  162. data/test/test/basictypes.rb +368 -0
  163. data/test/test/calendartypes.rb +57 -0
  164. data/test/test/coordinates.rb +380 -0
  165. data/test/test/ephemeris.rb +127 -0
  166. data/test/test/googlecalendar.rb +167 -0
  167. data/test/test/icalendar.rb +848 -0
  168. data/test/test/inspect.rb +115 -0
  169. data/test/test/parts.rb +480 -0
  170. data/test/test/region/chinese.rb +161 -0
  171. data/test/test/region/french.rb +33 -0
  172. data/test/test/region/geologicalage.rb +14 -0
  173. data/test/test/region/indian.rb +55 -0
  174. data/test/test/region/iran.rb +54 -0
  175. data/test/test/region/islamic.rb +18 -0
  176. data/test/test/region/japanese.rb +62 -0
  177. data/test/test/region/jewish.rb +61 -0
  178. data/test/test/region/m17n.rb +181 -0
  179. data/test/test/region/mayan.rb +78 -0
  180. data/test/test/region/moon.rb +14 -0
  181. data/test/test/region/planets.rb +14 -0
  182. data/test/test/region/residue.rb +123 -0
  183. data/test/test/region/sun.rb +14 -0
  184. data/test/test/region/thai.rb +94 -0
  185. data/test/test/region/tibetan.rb +30 -0
  186. data/test/test/tmobjects.rb +356 -57
  187. data/test/test/tmposition.rb +237 -0
  188. data/test/test/tmreference.rb +95 -0
  189. data/when_exe.gemspec +2 -2
  190. metadata +187 -7
  191. data/doc/COPYING +0 -31
  192. data/doc/COPYING.ja +0 -25
  193. data/doc/document_url +0 -1
@@ -0,0 +1,615 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-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
+ module When
9
+
10
+ # ISO 19108 以外の ISO に規定のある基本的なデータ型
11
+ # およびその subclass
12
+ module BasicTypes
13
+
14
+ #
15
+ # ISO 8601 Date and Time Representation
16
+ #
17
+ # see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date_time]
18
+ #
19
+ class DateTime < String
20
+
21
+ class << self
22
+
23
+ # When.exe Standard Representation 形式の表現を分解してArray化する
24
+ #
25
+ # @param [String] date_time 日時を表現する When.exe Standard Representation 形式の文字列
26
+ # @param [Hash] options
27
+ # @option options [String, Array<String, Integer>] :era_name デフォルトの年号(Integerは0年に対応する通年)
28
+ # @option options [Array<Numeric>] :abbr 上位省略形式で使用する上位部分
29
+ #
30
+ # @return [Array] format, date, time, clock, era
31
+ #
32
+ # format (Symbol, nil)
33
+ # nil 通常形式
34
+ # :century 世紀指定形式 ('CC', '+CCCC', '-CCCC')
35
+ # :day 年間通算日形式 ('YYDDD'など)
36
+ # :week 暦週形式 ('YYWNN'など)
37
+ #
38
+ # date (Array<Numeric>) 日付部分
39
+ #
40
+ # time (Array<Numeric>) 時刻部分
41
+ #
42
+ # clock (String) 時間帯
43
+ #
44
+ # era (String, Array<String, Integer>) 年号(Integerは0年に対応する通年)
45
+ #
46
+ def _to_array(date_time, options={})
47
+ raise TypeError, "Argument is not ISO 8601 String" unless date_time.kind_of?(String)
48
+ if options[:abbr].kind_of?(When::TimeValue)
49
+ options[:abbr] = ((options[:frame]||When.Calendar('Gregorian')) ^ options[:abbr]).cal_date
50
+ end
51
+ date_time = date_time.gsub(/_+/, '')
52
+ begin
53
+ return _to_array_basic(date_time, options)
54
+ rescue ArgumentError
55
+ return _to_array_extended(date_time, options)
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ # ISO 8601 基本形式の表現を分解して配列化する
62
+ def _to_array_basic(date_time, options={})
63
+
64
+ case date_time
65
+ # basic date & time format (ISO 8601)
66
+ when /^([-+W\d]+)(?:(T([.,\d]+)?)([A-Z]+|[-+]\d+)?)?$/
67
+ d, t, time, clock = $~[1..4]
68
+ format, date = Date._to_array_basic_ISO8601(d, options)
69
+
70
+ # basic date & time format (JIS X0301)
71
+ when /^([.\d]+)(?:(T([.,\d]+)?)([A-Z]+|[-+]\d+)?)?$/
72
+ raise ArgumentError, "Wrong date format" unless options[:era_name]
73
+ d, t, time, clock = $~[1..4]
74
+ format, date = Date._to_array_basic_X0301(d, options)
75
+ era = options[:era_name]
76
+
77
+ # basic time format (ISO 8601)
78
+ when /^(T(-{0,2}[.,\d]+)?)([A-Z]+|[-+]\d+)?$/
79
+ t, time, clock = $~[1..3]
80
+
81
+ # not supported
82
+ else
83
+ raise ArgumentError, "Wrong date format: #{date_time}"
84
+ end
85
+
86
+ return [format, date, Time._to_array_basic(time, t, options),
87
+ Time._to_string_clock(clock), era]
88
+ end
89
+
90
+ # ISO 8601 拡張形式の表現を分解して配列化する
91
+ def _to_array_extended(date_time, options={})
92
+
93
+ case date_time
94
+ # extended date & time format (ISO 8601)
95
+ when /^([-+*&%@!>=<?\dW.]+)(?:(T([:*=.,\d]+)?)([A-Z]+|[-+][:\d]+)?)?$/
96
+ d, t, time, clock = $~[1..4]
97
+ format, date = Date._to_array_extended_ISO8601(d, options)
98
+
99
+ # extended date & time format (JIS X0301)
100
+ when /^(\[[^\]]+\]|[^-+\d]+)([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]+|[-+][:\d]+)?)?$/
101
+ era, d, t, time, clock = $~[1..5]
102
+ format, date, era = Date._to_array_extended_X0301(d, era, options)
103
+ era ||= options[:era_name] if (d =~ /\./)
104
+
105
+ # extended time format (ISO 8601)
106
+ when /^(T(-{0,2}[:*=.,\d]+)?)([A-Z]+|[-+][:\d]+)?$/
107
+ t, time, clock = $~[1..3]
108
+
109
+ # not supported
110
+ else
111
+ raise ArgumentError, "Wrong date format: #{date_time}"
112
+ end
113
+
114
+ return [format, date, Time._to_array_extended(time, t, options),
115
+ Time._to_string_clock(clock), era]
116
+ end
117
+ end
118
+ end
119
+
120
+ #
121
+ # ISO 8601 Date Representation
122
+ #
123
+ # see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date]
124
+ #
125
+ class Date < DateTime
126
+
127
+ class << self
128
+ # ISO 8601 基本形式の表現を分解して配列化する
129
+ def _to_array_basic_ISO8601(date, options={})
130
+ by, bm, bd = options[:abbr]
131
+ case date
132
+ when nil ; return nil
133
+ when /^(\d{4})(\d{2})(\d{2})$/ ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.1
134
+ when /^(\d{4})-(\d{2})$/ ; return nil, [$1.to_i, $2.to_i] # 5.2.1.2
135
+ when /^(\d{4})$/ ; return nil, [$1.to_i] # 5.2.1.2
136
+ when /^(\d{2})$/ ; return :century,[$1.to_i * 100] # 5.2.1.2
137
+ when /^(\d{4})(\d{3})$/ ; return :day, [$1.to_i, $2.to_i] # 5.2.2.1
138
+ when /^(\d{4})W(\d{2})(\d{1})?$/ ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.1-2
139
+ when /^([-+]\d{6})(\d{2})(\d{2})$/ ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.4 a)
140
+ when /^([-+]\d{6})-(\d{2})$/ ; return nil, [$1.to_i, $2.to_i] # 5.2.1.4 b)
141
+ when /^([-+]\d{6})$/ ; return nil, [$1.to_i] # 5.2.1.4 c)
142
+ when /^([-+]\d{6})W(\d{2})(\d{1})?$/; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.4 a-b)
143
+ when /^([+]\d{4})$/ ; return :century,[$1.to_i * 100] # 5.2.1.4 d)
144
+ when /^([-]\d{4})$/ ; return :century,[$1.to_i * 100] unless by # 5.2.1.4 d)
145
+ when /^([-+]\d{6})(\d{3})$/ ; return :day, [$1.to_i, $2.to_i] # 5.2.2.3 a)
146
+ else ; raise ArgumentError, "Wrong date format" unless by
147
+ end
148
+
149
+ by = by.to_i
150
+ case date
151
+ when /^(\d{2})(\d{2})(\d{2})$/ ; return nil, [_century($1,by), $2.to_i, $3.to_i] # 5.2.1.3 a)
152
+ when /^-(\d{2})(\d{2})?$/ ; return nil, [_century($1,by), _int($2)] # 5.2.1.3 b-c)
153
+ when /^--(\d{2})(\d{2})?$/ ; return nil, [by, $1.to_i, _int($2)] # 5.2.1.3 d-e)
154
+ when /^(\d{2})(\d{3})$/ ; return :day, [_century($1,by), $2.to_i] # 5.2.2.2 a)
155
+ when /^-(\d{3})$/ ; return :day, [by, $1.to_i] # 5.2.2.2 b)
156
+ when /^(\d{2})W(\d{2})(\d{1})?$/ ; return :week, [_century($1,by), $2.to_i, _int($3)] # 5.2.3.3 a-b)
157
+ when /^-(\d{1})W(\d{2})(\d{1})?$/ ; return :week, [_decade($1,by), $2.to_i, _int($3)] # 5.2.3.3 c-d)
158
+ when /^-W(\d{2})(\d{1})?$/ ; return :week, [by, $1.to_i, _int($2)] # 5.2.3.3 e-f)
159
+ else ; raise ArgumentError, "Wrong date format" unless bm
160
+ end
161
+
162
+ bm = bm.to_i
163
+ case date
164
+ when /^---(\d{2})$/ ; return nil, [by, bm, $1.to_i] # 5.2.1.3 f)
165
+ when /^-W-(\d{1})$/ ; return :week, [by, bm, $1.to_i] # 5.2.3.3 g)
166
+ when /^----$/ ; return nil, [by, bm, bd.to_i] if bd # extension
167
+ end
168
+
169
+ raise ArgumentError, "Wrong date format: #{date}"
170
+ end
171
+
172
+ # JIS X0301 基本形式の表現を分解して配列化する
173
+ def _to_array_basic_X0301(date, options={})
174
+ raise ArgumentError, "Wrong date format" unless date =~ /\./
175
+ date.scan(/\d+\./) do |part|
176
+ raise ArgumentError, "Wrong date format" unless part.length == 3
177
+ end
178
+ _to_array_basic_ISO8601(date.gsub(/\./, ''), {:abbr=>options[:abbr]||1})
179
+ end
180
+
181
+ # ISO 8601 拡張形式の表現を分解して配列化する
182
+ def _to_array_extended_ISO8601(date, options={})
183
+ return nil unless date
184
+ abbr = Array(options[:abbr]).dup
185
+ unless date =~ /^([-+]?\d+#{abbr[0] ? '|-' : ''})([-*=.])?(.*)/
186
+ raise ArgumentError, "Wrong date format: #{date}"
187
+ end
188
+ date = $3
189
+ dd = [Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)]
190
+ while date =~ /^(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])(.+)/
191
+ date = $3
192
+ dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
193
+ end
194
+ case date
195
+ when /^W(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?(\d+)?([-*=?%@])?$/
196
+ dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
197
+ dd << Coordinates::Pair._en_pair($3, $4)
198
+ return :week, dd
199
+ when /^(\d{3})$/
200
+ dd << $1.to_i
201
+ return :day, dd
202
+ when /^(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?$/
203
+ dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
204
+ return nil, dd
205
+ when ''
206
+ return nil, dd
207
+ else
208
+ raise ArgumentError, "Wrong date format: #{date}"
209
+ end
210
+ end
211
+
212
+ # JIS X0301 拡張形式の表現を分解して配列化する
213
+ def _to_array_extended_X0301(date, era, options={})
214
+ if (date =~ /^([-+\d]+)\(([-+\d]+)\)(.*)$/)
215
+ year = $2
216
+ date = $1 + $3
217
+ end
218
+ format, date = _to_array_extended_ISO8601(date, options)
219
+ if (year)
220
+ yy = year.to_i
221
+ ee = date[0] * 1
222
+ era = [era, yy-ee, yy+ee]
223
+ end
224
+ return format, date, era
225
+ end
226
+
227
+ private
228
+
229
+ def _completion(digits, base)
230
+ case digits
231
+ when nil ; return nil
232
+ when /^\d{5}/ ; raise ArgumentError, "Wrong date format: #{digits}"
233
+ else ; return digits.to_i unless base
234
+ end
235
+
236
+ base = base.to_i
237
+ case digits
238
+ when '-' ; return base
239
+ when /^-?(\d{1})$/ ; return _decade( $1, base)
240
+ when /^-?(\d{2})$/ ; return _century($1, base)
241
+ else ; return digits.to_i
242
+ end
243
+ end
244
+
245
+ def _century(year, base)
246
+ quotient, remainder = base.divmod(100)
247
+ year = year.to_i
248
+ quotient += 1 if year < remainder
249
+ return quotient * 100 + year
250
+ end
251
+
252
+ def _decade(year, base)
253
+ quotient, remainder = base.divmod(10)
254
+ year = year.to_i
255
+ quotient += 1 if year < remainder
256
+ return quotient * 10 + year
257
+ end
258
+
259
+ def _int(digits)
260
+ return digits ? digits.to_i : nil
261
+ end
262
+ end
263
+ end
264
+
265
+ #
266
+ # ISO 8601 Time Representation
267
+ #
268
+ # see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#time]
269
+ #
270
+ class Time < DateTime
271
+
272
+ class << self
273
+ # 基本形式の表現を分解して配列化する
274
+ def _to_array_basic(time, t, options={})
275
+ return nil unless t
276
+ return [0] unless time
277
+ time.sub!(/,/, '.')
278
+ unless (time =~ /^(\d{2}(?:\.\d+)?|-)(\d{2}(?:\.\d+)?|-)?(\d{2}(\.\d+)?)?$/)
279
+ raise ArgumentError, "Wrong time format: #{time}"
280
+ end
281
+ indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndex
282
+ abbr = Array(options[:abbr]).dup
283
+ abbr[0..indices.length] = []
284
+ return [0, Coordinates::Pair._en_number($1=='-' ? abbr[0] : $1, nil),
285
+ Coordinates::Pair._en_number($2=='-' ? abbr[1] : $2, nil),
286
+ Coordinates::Pair._en_number($3, nil)]
287
+ end
288
+
289
+ # 拡張形式の表現を分解して配列化する
290
+ def _to_array_extended(time, t, options={})
291
+ return nil unless t
292
+ return [0] unless time
293
+ indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndex
294
+ abbr = Array(options[:abbr]).dup
295
+ abbr[0..indices.length] = []
296
+ time.sub!(/,/, '.')
297
+ tt = [0]
298
+ while time =~ /^(\d{2}(?:\.\d+)?|-)([:*=])(.+)/
299
+ time = $3
300
+ tt << Coordinates::Pair._en_pair($1=='-' ? abbr.shift : $1, $2)
301
+ end
302
+ case time
303
+ when /^(\d{2}(\.\d+)?)$/
304
+ tt << Coordinates::Pair._en_number($1, nil)
305
+ when ''
306
+ else
307
+ raise ArgumentError, "Wrong time format: #{time}"
308
+ end
309
+ return tt
310
+ end
311
+
312
+ # 時間帯の表現を正規化する
313
+ def _to_string_clock(clock)
314
+ return nil unless clock
315
+ return clock if (clock =~ /^[A-Z]+$/)
316
+ raise ArgumentError, "Wrong clock format: #{clock}" unless (clock =~ /^([-+])(\d{2})(?::?(\d{2}))?$/)
317
+ s, h, m = $~[1..3]
318
+ return s + h + ':' + (m||'00')
319
+ end
320
+ end
321
+ end
322
+
323
+ # コード
324
+ #
325
+ # 当該コードを定義している辞書, シソーラスまたは機関への参照を
326
+ # オプショナルな codeSpace 属性に保持することができる文字列
327
+ #
328
+ # see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#CodeType gml schema}
329
+ #
330
+ class Code < String
331
+
332
+ # an optional codeSpace
333
+ #
334
+ # @return [String] anyURI (Optional)
335
+ attr_reader :code_space
336
+ alias :codeSpace :code_space
337
+
338
+ # オブジェクトの生成
339
+ #
340
+ # @param [String] code Text token
341
+ # @param [String] namespace code を定義している authority の URI
342
+ #
343
+ def initialize(code, namespace=nil)
344
+ @code_space = namespace
345
+ self[0..-1] = code
346
+ end
347
+ end
348
+
349
+ #
350
+ # == 多言語対応文字列
351
+ #
352
+ # 本ライブラリで用いる諸々の用語を多言語対応で曖昧性なく管理するため
353
+ # Code の subclass として定義する
354
+ #
355
+ # == 内部変数
356
+ # === self[ 0..-1 ] : String
357
+ # インスタンスを代表する文字列
358
+ # 通常の String として振舞う場合は、この文字列として振舞う
359
+ #
360
+ # === @locale : Hash
361
+ # インスタンスがさす言葉の諸言語での表現を文字列として保持する
362
+ # locale指定('lang_country.encoding') => その locale での文字列
363
+ # locale指定の要素に省略がある場合、残った共通の要素によって文字列を特定する
364
+ # Ex. @locale = {'en'=>'March', 'ja'=>'三月'} ならば、locale が
365
+ # 'en_US', 'en_GB' のいずれでもlocale での文字列は 'March'
366
+ #
367
+ # === @namespace : Hash
368
+ # インスタンスがさす言葉の意味を特定するための authority の URI を保持する
369
+ # locale指定('lang_country.encoding') => その locale での authority の URI
370
+ # locale指定の要素に省略がある場合、残った共通の要素によってURIを特定する
371
+ # Ex. @locale = {'en'=>'en:March', 'ja'=>'ja:3%E6%9C%88'} ならば、locale が
372
+ # 'en_US', 'en_GB' のいずれでもlocale での authority の URIは 'en:March'
373
+ # 当該用語が標準管理機関で管理されていない場合、wikipedia の当該項目の URI を用いる
374
+ #
375
+ # === @code_space : String
376
+ # 代表的な authority の URI
377
+ # @namespace[''] である
378
+ #
379
+ # see {When::Parts::Locale}, {When::Parts::Resource}
380
+ #
381
+ class M17n < Code
382
+ include Parts::Locale
383
+ include Parts::Resource
384
+
385
+ # @private
386
+ def self._get_locale(locale, access_key)
387
+ return nil unless access_key
388
+ access_key = access_key.split(/\//).map {|key| key =~ /^[0-9]+$/ ? key.to_i : key}
389
+ locale = locale.sub(/\..*/, '').sub(/-/,'_')
390
+ [locale, locale.sub(/_.*/, '')].each do |loc|
391
+ symbol = ('Locale_' + loc).to_sym
392
+ return {loc=>access_key.inject(const_get(symbol)) {|hash, key| hash = hash[key]}} if (const_defined?(symbol))
393
+ end
394
+ return nil
395
+ end
396
+
397
+ #
398
+ # When::BasicTypes::M17n に変換する - 何もしないで自身を返す
399
+ #
400
+ # @return [When::BasicTypes::M17n]
401
+ #
402
+ def to_m17n
403
+ self
404
+ end
405
+
406
+ #
407
+ # 識別文字列
408
+ #
409
+ # @return [String]
410
+ #
411
+ def label
412
+ @label || to_s
413
+ end
414
+
415
+ #
416
+ # _m17n_form のための要素生成 - 何もしないで自身を返す
417
+ #
418
+ # @param [Hash] options 未使用
419
+ #
420
+ # @return [When::BasicTypes::M17n]
421
+ #
422
+ def _to_hash_value(options={})
423
+ self
424
+ end
425
+
426
+ # オブジェクトの生成
427
+ #
428
+ # @overload initialize(names, namespace={}, locale=[])
429
+ # @param [Array<String>] names
430
+ #
431
+ # [String] '*locale:label=prefix:link'
432
+ # * - 存在すれば、label をインスタンスを代表する文字列とする
433
+ # locale - label に対応する locale指定(なければ、locale 引数の指定を用いる)
434
+ # label - locale 指定に対応する label
435
+ # prefix:link - その locale での authority の URI
436
+ # prefix: - namespace 引数の指定により URI に展開する
437
+ # link - なければ labelをURI encodeして用いる
438
+ #
439
+ # @param [Hash] namespace { prefix=>uri }
440
+ #
441
+ # lables, locale 引数の prefix の展開に用いる
442
+ #
443
+ # @param [Array<String>] locale
444
+ #
445
+ # [String] '*locale=prefix:link'
446
+ # * - 存在すれば、label をインスタンスを代表する文字列とする
447
+ # locale - locale指定
448
+ # prefix:link - authority の URI
449
+ # prefix: - namespace 引数の指定により URI に展開する
450
+ #
451
+ # @example
452
+ # M17n.new(['3月', 'fr:Mars=http://fr.wikipedia.org/wiki/Mars_(mois)', 'March'],
453
+ # {'en_wikipedia'=>'http://en.wikipedia.org/wiki/',
454
+ # 'ja_wikipedia'=>'http://ja.wikipedia.org/wiki/'},
455
+ # ['=ja_wikipedia:', '*en=en_wikipedia:']) を行うと、生成された M17n では、
456
+ # @names = {'' =>'3月', 'fr'=>'Mars', 'en'=>'March'}
457
+ # @namespace = {'' =>'http://ja.wikipedia.org/wiki/3%E6%9C%88',
458
+ # 'fr'=>'http://fr.wikipedia.org/wiki/Mars_(mois)',
459
+ # 'en'=>'http://en.wikipedia.org/wiki/March'}
460
+ # となり、通常の String として振舞う場合は 'March' として振舞う
461
+ #
462
+ def initialize(*args)
463
+ rest, options = _attributes(args)
464
+ _sequence
465
+
466
+ if (_pool[@label])
467
+ _copy_all(_pool[@label])
468
+
469
+ else
470
+ if (rest)
471
+ names, namespace, locale = args
472
+ @names = names if names
473
+ @namespace ||= Parts::Locale._namespace(namespace) if namespace
474
+ @locale ||= Parts::Locale._locale(locale) if locale
475
+ end
476
+ @namespace ||= {}
477
+ @locale ||= []
478
+
479
+ @code_space = @namespace['']
480
+ self[0..-1] = _names(@names, @namespace, @locale)
481
+ end
482
+ end
483
+ end
484
+
485
+ #
486
+ # Abstract class for instance having permanent life with IRI
487
+ #
488
+ # see {When::Parts::Resource}
489
+ # see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#ObjectType gml schema}
490
+ #
491
+ class Object
492
+
493
+ include Parts::Resource
494
+
495
+ # 名前
496
+ #
497
+ # @return [String, When::BasicTypes::M17n]
498
+ #
499
+ attr_reader :label
500
+
501
+ # オブジェクトのtap
502
+ unless method_defined?(:tap)
503
+ #
504
+ # tap - yield による処理のチェーン化
505
+ #
506
+ def tap
507
+ yield(self)
508
+ self
509
+ end
510
+ end
511
+
512
+ private
513
+
514
+ # オブジェクトの初期化
515
+ def initialize(*args)
516
+ @_lock_ = Mutex.new if When.multi_thread
517
+ _normalize(*_attributes(args))
518
+ _sequence
519
+ end
520
+ end
521
+ end
522
+
523
+ #
524
+ # RS::Identifier を提供する
525
+ #
526
+ module RS
527
+
528
+ # 参照系の識別子
529
+ #
530
+ # see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#IdentifierType gml schema}
531
+ #
532
+ class Identifier
533
+
534
+ # The code or name for this Identifier
535
+ #
536
+ # @return [When::BasicTypes::Code]
537
+ #
538
+ attr_reader :name
539
+
540
+ # Identifier of the version of the associated codeSpace or code
541
+ #
542
+ # @return [Array<String>]
543
+ #
544
+ attr_reader :version
545
+
546
+ # Remarks about this code or alias
547
+ #
548
+ # @return [Array<String>] String は URI/IRI文字列の場合あり
549
+ #
550
+ attr_reader :remarks
551
+
552
+ # オブジェクトの生成
553
+ #
554
+ # @param [When::BasicTypes::Code] name
555
+ # @param [Array<String>] version
556
+ # @param [Array<String>] remarks String は URI/IRI文字列の場合あり
557
+ #
558
+ def initialize(name, version=nil, remarks=nil)
559
+ @name = name
560
+ @version = version
561
+ @remarks = remarks
562
+ end
563
+
564
+ # その他のメソッド
565
+ #
566
+ # @note When::RS::Identifier で定義されていないメソッドは
567
+ # 処理を @name (type: When::BasicTypes::Code) に委譲する
568
+ #
569
+ def method_missing(name, *args, &block)
570
+ @name.send(name.to_sym, *args, &block)
571
+ end
572
+ end
573
+ end
574
+
575
+ #
576
+ # EX::Extent を提供する
577
+ #
578
+ module EX
579
+
580
+ # 参照系の時間的および空間的な使用範囲を記述する
581
+ #
582
+ # 本ライブラリでは、時間的使用範囲を記述ためにのみ使用している
583
+ #
584
+ # see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#ExtentType gml schema}
585
+ #
586
+ class Extent
587
+
588
+ # time periods
589
+ #
590
+ # 時間的使用範囲の上限と下限を示す
591
+ #
592
+ # @return [When::TM::Period]
593
+ #
594
+ attr_reader :temporal_extent
595
+ alias :temporalExtent :temporal_extent
596
+
597
+ # オブジェクトの生成
598
+ #
599
+ # @param [When::TM::Period] extent
600
+ #
601
+ def initialize(extent)
602
+ @temporal_extent = extent
603
+ end
604
+
605
+ # その他のメソッド
606
+ #
607
+ # @note When::EX::Extent で定義されていないメソッドは
608
+ # 処理を @temporal_extent (type: When::TM::Period) に委譲する
609
+ #
610
+ def method_missing(name, *args, &block)
611
+ @temporal_extent.send(name.to_sym, *args, &block)
612
+ end
613
+ end
614
+ end
615
+ end