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
data/LICENSE.ja.txt CHANGED
@@ -1,25 +1,25 @@
1
- When.exe: A multicultural and multilingualized calendar library
2
-
3
- 本プログラムの著作権は須賀隆 <suchowan@box.email.ne.jp> にあります。
4
-
5
- 本プログラムは,下記の条件で使用できます.
6
-
7
- 1. 必ず、著作権表示や免責事項を含めて、制限なく自由に複製できます.
8
-
9
- 2. 以下の条件のいずれかを満たす時に本プログラムを自由に変更できます.
10
-
11
- (a) 変更した本プログラムを自分だけで使う.
12
-
13
- (b) その他の変更条件を作者と書面により合意する.
14
-
15
- 3. 本プログラム,変更した本プログラム及び本プログラムから生成した実行形式は,
16
- 作者との書面による合意がなければ配布できません.
17
-
18
- 4. 他のプログラムとの併合はいかなる目的であれ自由です.
19
-
20
- 5. 本プログラムへの入力となるデータおよび本プログラムからの出力の権利は
21
- 本プログラムの作者ではなく,それぞれの入出力を生成した人に属します.
22
-
23
- 6. 本プログラムは無保証です.作者は本プログラムをサポートする意志はありますが,
24
- プログラム自身のバグあるいは本プログラムの実行などから発生するいかなる損害に
25
- 対しても責任を持ちません.
1
+ When.exe: A multicultural and multilingualized calendar library
2
+
3
+ 本プログラムの著作権は須賀隆 <suchowan@box.email.ne.jp> にあります。
4
+
5
+ 本プログラムは,下記の条件で使用できます.
6
+
7
+ 1. 必ず、著作権表示や免責事項を含めて、制限なく自由に複製できます.
8
+
9
+ 2. 以下の条件のいずれかを満たす時に本プログラムを自由に変更できます.
10
+
11
+ (a) 変更した本プログラムを自分だけで使う.
12
+
13
+ (b) その他の変更条件を作者と書面により合意する.
14
+
15
+ 3. 本プログラム,変更した本プログラム及び本プログラムから生成した実行形式は,
16
+ 作者との書面による合意がなければ配布できません.
17
+
18
+ 4. 他のプログラムとの併合はいかなる目的であれ自由です.
19
+
20
+ 5. 本プログラムへの入力となるデータおよび本プログラムからの出力の権利は
21
+ 本プログラムの作者ではなく,それぞれの入出力を生成した人に属します.
22
+
23
+ 6. 本プログラムは無保証です.作者は本プログラムをサポートする意志はありますが,
24
+ プログラム自身のバグあるいは本プログラムの実行などから発生するいかなる損害に
25
+ 対しても責任を持ちません.
data/LICENSE.txt CHANGED
@@ -1,31 +1,31 @@
1
- When.exe: A multicultural and multilingualized calendar library
2
-
3
- This library is copyrighted free software by Takashi SUGA <suchowan@box.email.ne.jp>.
4
-
5
- You can use and/or modify the software under the conditions below:
6
-
7
- 1. You may make verbatim copies of the software without restriction, provided
8
- that you duplicate all of the original copyright notices and associated
9
- disclaimers.
10
-
11
- 2. You may modify your copy of the software in any way, provided that
12
- you do at least ONE of the following:
13
-
14
- a) place your modifications in your private domain.
15
-
16
- b) make other written arrangements with the author.
17
-
18
- 3. You cannot distribute the software with/without modification or
19
- derived executable binary form without written arrangements with the author.
20
-
21
- 4. You may modify and include the part of the software into any other
22
- software.
23
-
24
- 5. The data supplied as input to or produced as output from the software
25
- do not automatically fall under the copyright of the software,
26
- but belong to whomever generated them.
27
-
28
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
29
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
30
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
- PURPOSE.
1
+ When.exe: A multicultural and multilingualized calendar library
2
+
3
+ This library is copyrighted free software by Takashi SUGA <suchowan@box.email.ne.jp>.
4
+
5
+ You can use and/or modify the software under the conditions below:
6
+
7
+ 1. You may make verbatim copies of the software without restriction, provided
8
+ that you duplicate all of the original copyright notices and associated
9
+ disclaimers.
10
+
11
+ 2. You may modify your copy of the software in any way, provided that
12
+ you do at least ONE of the following:
13
+
14
+ a) place your modifications in your private domain.
15
+
16
+ b) make other written arrangements with the author.
17
+
18
+ 3. You cannot distribute the software with/without modification or
19
+ derived executable binary form without written arrangements with the author.
20
+
21
+ 4. You may modify and include the part of the software into any other
22
+ software.
23
+
24
+ 5. The data supplied as input to or produced as output from the software
25
+ do not automatically fall under the copyright of the software,
26
+ but belong to whomever generated them.
27
+
28
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
29
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
30
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
+ PURPOSE.
data/bin/irb.rc ADDED
@@ -0,0 +1,5 @@
1
+ require 'pp'
2
+ require 'when_exe'
3
+ require 'when_exe/core/extension'
4
+ require 'when_exe/mini_application'
5
+ include When
data/bin/locales.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  =begin
4
4
  Copyright (C) 2011-2012 Takashi SUGA
5
5
 
6
- You may use and/or modify this file according to the license described in the COPYING file included in this archive.
6
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
7
7
  =end
8
8
 
9
9
  require 'pp'
@@ -16,7 +16,7 @@ HEADER = <<HEADER
16
16
  =begin
17
17
  Copyright (C) 2012-2013 Takashi SUGA
18
18
 
19
- You may use and/or modify this file according to the license described in the COPYING file included in this archive.
19
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
20
20
  =end
21
21
 
22
22
  module When::BasicTypes
data/bin/when.rb ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ =begin
4
+ Copyright (C) 2011-2013 Takashi SUGA
5
+
6
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ require 'pp'
10
+ require 'when_exe'
11
+ require 'when_exe/mini_application'
12
+ args = ARGV.map {|arg| arg.encode('UTF-8')}
13
+ config = When.config
14
+ server, port = config['?']
15
+ result = !port ? When.free_conv(*args) : args == [] ? When.server(port) : When.client(server, port, args.join(' '))
16
+ pp When::Parts::Locale.translate(result, config['!']) if result
@@ -0,0 +1,7 @@
1
+ #?:localhost:10001
2
+ !:ja.Windows-31J
3
+ G:Gregorian
4
+ J:Julian
5
+ W:_e:Japanese
6
+ K:_e:Chinese
7
+ E:ChineseLuniSolar?timezone=9&intercalary_span=3
data/lib/when_exe.rb CHANGED
@@ -1,14 +1,616 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
-
4
- Copyright (C) 2011-2013 Takashi SUGA
5
-
6
- You may use and/or modify this file according to the license described in the COPYING file included in this archive.
7
- =end
8
-
9
- $:.unshift(File.dirname(__FILE__)) unless
10
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
11
-
12
- require 'when_exe/version'
13
- require 'when_exe/tmduration'
14
-
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
+ begin
9
+ require 'rubygems'
10
+ rescue LoadError
11
+ end
12
+ begin
13
+ gem 'tzinfo'
14
+ autoload :TZInfo, 'tzinfo'
15
+ rescue LoadError, NoMethodError
16
+ end
17
+ begin
18
+ gem 'gcalapi'
19
+ autoload :GoogleCalendar, 'when_exe/googlecalendar'
20
+ rescue LoadError, NoMethodError
21
+ end
22
+
23
+ autoload :URI, 'uri'
24
+ autoload :OpenURI, 'open-uri'
25
+ autoload :JSON, 'json'
26
+ autoload :REXML, 'rexml/document'
27
+ autoload :Mutex, 'thread' unless Object.const_defined?(:Mutex)
28
+
29
+ $:.unshift(File.dirname(__FILE__)) unless
30
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
31
+
32
+ #
33
+ # A multicultural and multilingualized calendar library based on ISO 8601, ISO 19108 and RFC 5545
34
+ #
35
+ module When
36
+
37
+ class << self
38
+
39
+ #
40
+ # マルチスレッド対応の場合 true
41
+ #
42
+ # @return [Boolean]
43
+ #
44
+ attr_reader :multi_thread
45
+
46
+ # Initializations
47
+ #
48
+ # @param [Hash] options
49
+ # @option options [When::TM::Clock, When::V::Timezone, When::Parts::Timezone] :local デフォルトの地方時
50
+ # @option options [When::TM::IntervalLength] :until V::Event::Enumerator の until
51
+ # @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
52
+ # @option options [Array<String>] :order CalendarEra の検索順序 ([ IRI of When::TM::CalendarEra ])
53
+ # @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
54
+ # @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
55
+ # @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
56
+ #
57
+ # @return [void]
58
+ #
59
+ def _setup_(options={})
60
+ @multi_thread = options[:multi_thread]
61
+ Parts::Resource._setup_
62
+ Parts::Locale._setup_(options[:alias])
63
+ TM::CalendarEra._setup_(options[:order])
64
+ TM::Calendar._setup_
65
+ TM::Clock._setup_(options[:local])
66
+ TM::TemporalPosition._setup_(options[:format])
67
+ V::Event._setup_(options[:until])
68
+ V::Timezone._setup_
69
+ Parts::Timezone._setup_
70
+ TimeStandard._setup_(options[:leap_seconds])
71
+ end
72
+ end
73
+
74
+ SourceURI = "http://hosi.org/When/"
75
+
76
+ require 'when_exe/version'
77
+ require 'when_exe/parts/enumerator'
78
+ require 'when_exe/parts/locale'
79
+ require 'when_exe/parts/resource'
80
+ require 'when_exe/parts/geometric_complex'
81
+ require 'when_exe/parts/timezone'
82
+ require 'when_exe/parts/method_cash'
83
+ require 'when_exe/core/compatibility'
84
+ require 'when_exe/basictypes'
85
+ require 'when_exe/ephemeris'
86
+ require 'when_exe/tmduration'
87
+ require 'when_exe/coordinates'
88
+ require 'when_exe/icalendar'
89
+ require 'when_exe/tmobjects'
90
+ require 'when_exe/timestandard'
91
+ require 'when_exe/tmposition'
92
+ require 'when_exe/tmreference'
93
+ require 'when_exe/calendartypes'
94
+ require 'when_exe/locales/locales'
95
+ require 'when_exe/region/m17n'
96
+ require 'when_exe/region/residue'
97
+ require 'when_exe/region/christian'
98
+ require 'when_exe/inspect'
99
+
100
+ #
101
+ # Module Constants
102
+ #
103
+
104
+ DurationP1D = TM::PeriodDuration.new([0,0,1])
105
+ DurationP1W = TM::PeriodDuration.new([0,0,7])
106
+ DurationP1M = TM::PeriodDuration.new([0,1,0])
107
+ DurationP1Y = TM::PeriodDuration.new([1,0,0])
108
+ TimeValue = TM::IndeterminateValue
109
+
110
+ UTF8 = '.UTF-8'
111
+ W31J = '.Windows-31J'
112
+ EUCJP = '.eucJP'
113
+
114
+ class BasicTypes::M17n
115
+ autoload :JapaneseTerms, 'when_exe/region/japanese'
116
+ autoload :ChineseTerms, 'when_exe/region/chinese'
117
+ autoload :YiTerms, 'when_exe/region/chinese'
118
+ autoload :TibetanTerms, 'when_exe/region/tibetan'
119
+ autoload :ThaiTerms, 'when_exe/region/thai'
120
+ autoload :BalineseTerms, 'when_exe/region/balinese'
121
+ autoload :JavaneseTerms, 'when_exe/region/javanese'
122
+ autoload :IndianTerms, 'when_exe/region/indian'
123
+ autoload :IranianTerms, 'when_exe/region/iranian'
124
+ autoload :IslamicTerms, 'when_exe/region/islamic'
125
+ autoload :JewishTerms, 'when_exe/region/jewish'
126
+ autoload :RomanTerms, 'when_exe/region/roman'
127
+ autoload :ChristianTerms, 'when_exe/region/christian'
128
+ autoload :FrenchTerms, 'when_exe/region/french'
129
+ autoload :WorldTerms, 'when_exe/region/world'
130
+ autoload :ShireTerms, 'when_exe/region/shire'
131
+ autoload :MartianTerms, 'when_exe/region/martian'
132
+ autoload :WikipediaLinks, 'when_exe/locales/links'
133
+ end
134
+
135
+ module CalendarTypes
136
+ autoload :Japanese, 'when_exe/region/japanese'
137
+ autoload :ChineseSolar, 'when_exe/region/chinese'
138
+ autoload :ChineseLuniSolar, 'when_exe/region/chinese'
139
+ autoload :Chinese, 'when_exe/region/chinese'
140
+ autoload :Yi, 'when_exe/region/chinese'
141
+ autoload :Tibetan, 'when_exe/region/tibetan'
142
+ autoload :ThaiB, 'when_exe/region/thai'
143
+ autoload :ThaiC, 'when_exe/region/thai'
144
+ autoload :Tenganan, 'when_exe/region/balinese'
145
+ autoload :Pranatamangsa, 'when_exe/region/javanese'
146
+ autoload :IndianNationalSolar, 'when_exe/region/indian'
147
+ autoload :HinduSolar, 'when_exe/region/indian'
148
+ autoload :HinduLuniSolar, 'when_exe/region/indian'
149
+ autoload :SolarHejri, 'when_exe/region/iranian'
150
+ autoload :Bahai, 'when_exe/region/bahai'
151
+ autoload :TabularIslamic, 'when_exe/region/islamic'
152
+ autoload :EphemerisBasedIslamic, 'when_exe/region/islamic'
153
+ autoload :Jewish, 'when_exe/region/jewish'
154
+ autoload :JulianA, 'when_exe/region/roman'
155
+ autoload :JulianB, 'when_exe/region/roman'
156
+ autoload :JulianC, 'when_exe/region/roman'
157
+ autoload :Roman, 'when_exe/region/roman'
158
+ autoload :FrenchRepublican, 'when_exe/region/french'
159
+ autoload :World, 'when_exe/region/world'
160
+ autoload :LongCount, 'when_exe/region/mayan'
161
+ autoload :Shire, 'when_exe/region/shire'
162
+ autoload :ShireG, 'when_exe/region/shire'
163
+ autoload :Darian, 'when_exe/region/martian'
164
+ autoload :MTC, 'when_exe/region/martian'
165
+
166
+ class CalendarNote
167
+ autoload :JapaneseNote, 'when_exe/region/japanese_notes'
168
+ autoload :BalineseNote, 'when_exe/region/balinese'
169
+ autoload :RomanNote, 'when_exe/region/roman'
170
+ autoload :WorldWeek, 'when_exe/region/world'
171
+ autoload :ShireWeek, 'when_exe/region/shire'
172
+
173
+ DefaultNotes = [['_m:CalendarTerms::Month'], []]
174
+ JulianDayNotes = [['CommonResidue::Week', 'CommonResidue::干支']]
175
+ BahaiNotes = [['Bahai::YearName'], ['_m:BahaiTerms::Month'], []]
176
+ JavaneseNotes = [['Javanese::Windu'], ['_m:CalendarTerms::Month'],
177
+ ['Javanese::Pasaran', 'Javanese::Paringkelan', 'Javanese::Week', 'Javanese::Wuku']]
178
+ ChineseNotes = [['CommonResidue::干支'], ['_m:CalendarTerms::Month'], ['CommonResidue::干支']]
179
+ YiNotes = [['Yi::YearName'], ['_m:CalendarTerms::Month'], []]
180
+ MayanNotes = [["Mayan::Trecena", "Mayan::Tzolk'in", "Mayan::Lords_of_the_Night", "Mayan::Haab'"]]
181
+ end
182
+ end
183
+
184
+ module Coordinates
185
+ autoload :Yi, 'when_exe/region/chinese'
186
+ autoload :Javanese, 'when_exe/region/javanese'
187
+ autoload :IndianCities, 'when_exe/region/indian'
188
+ autoload :Bahai, 'when_exe/region/bahai'
189
+ autoload :Roman, 'when_exe/region/roman'
190
+ autoload :Mayan, 'when_exe/region/mayan'
191
+
192
+ # default index for date coordinates
193
+ DefaultDateIndex = [
194
+ Coordinates::Index.new({:unit=>12}),
195
+ Coordinates::Index.new
196
+ ]
197
+
198
+ # default index for time coordinates
199
+ DefaultTimeIndex = [
200
+ Coordinates::Index.new({:base=>0, :unit=>24}),
201
+ Coordinates::Index.new({:base=>0, :unit=>60}),
202
+ Coordinates::Index.new({:base=>0, :unit=>60})
203
+ ]
204
+ end
205
+
206
+ class TM::CalendarEra
207
+ autoload :GeologicalAge, 'when_exe/region/geologicalage'
208
+ autoload :Japanese, 'when_exe/region/japanese'
209
+ autoload :JapanesePrimeMinister, 'when_exe/region/japanese'
210
+ autoload :NihonKoki, 'when_exe/region/nihon_shoki'
211
+ autoload :NihonShoki, 'when_exe/region/nihon_shoki'
212
+ autoload :Chinese, 'when_exe/region/chinese_epoch'
213
+ autoload :Ryukyu, 'when_exe/region/ryukyu'
214
+ autoload :Korean, 'when_exe/region/korean'
215
+ autoload :Vietnamese, 'when_exe/region/vietnamese'
216
+ autoload :Manchurian, 'when_exe/region/far_east'
217
+ autoload :Rouran, 'when_exe/region/far_east'
218
+ autoload :Gaochang, 'when_exe/region/far_east'
219
+ autoload :Yunnan, 'when_exe/region/far_east'
220
+ # autoload :Tibetan, 'when_exe/region/tibetan'
221
+ autoload :Balinese, 'when_exe/region/balinese'
222
+ autoload :Javanese, 'when_exe/region/javanese'
223
+ autoload :Indian , 'when_exe/region/indian'
224
+ autoload :Iranian, 'when_exe/region/iranian'
225
+ autoload :Hijra, 'when_exe/region/islamic'
226
+ autoload :Jewish, 'when_exe/region/jewish'
227
+ autoload :Roman, 'when_exe/region/roman'
228
+ autoload :Julian, 'when_exe/region/roman'
229
+ autoload :Pope, 'when_exe/region/pope'
230
+ autoload :Byzantine, 'when_exe/region/christian'
231
+ autoload :French, 'when_exe/region/french'
232
+ autoload :World, 'when_exe/region/world'
233
+ autoload :Mayan, 'when_exe/region/mayan'
234
+
235
+ # Defualt search path for Epochs and Eras
236
+ DefaultEpochs = ['Common', 'ModernJapanese',
237
+ 'Iranian', 'Hijra', 'Jewish', 'Roman', 'Byzantine',
238
+ 'French', 'World', 'Mayan',
239
+ 'Balinese', 'Javanese',
240
+ 'Japanese', 'JapanesePrimeMinister', 'NihonKoki', 'NihonShoki',
241
+ 'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
242
+ 'Manchurian', 'Rouran', 'Gaochang', 'Yunnan', # 'Tibetan',
243
+ 'Pope' ]
244
+
245
+ # Common Era
246
+ Common = [self, [
247
+ "namespace:[en=http://en.wikipedia.org/wiki/]",
248
+ "area:[Common]",
249
+ ["[BeforeCommonEra=en:BCE_(disambiguation),*alias:BCE]0.1.1"],
250
+ ["[CommonEra=en:Common_Era,*alias:CE]1.1.1", "Calendar Epoch", "01-01-01^Julian"],
251
+ ["[CommonEra=en:Common_Era,*alias:CE]1582.10.15", "Calendar Reform", "1582-10-15^Gregorian"]
252
+ ]]
253
+
254
+ # Modern Japanese Eras after the calendar reform to the Gregorian Calendar
255
+ ModernJapanese = [self, [
256
+ "area:[Japan]",
257
+ ["M6.01.01", "Calendar Reform", "1873-01-01^Gregorian?note=DefaultNotes"],
258
+ ["T1.07.30", "Accession", "1912-07-30"],
259
+ ["S1.12.25", "Accession", "1926-12-25"],
260
+ ["H1.01.08", "Accession", "1989-01-08"]
261
+ ]]
262
+ end
263
+
264
+ #
265
+ # Module Functions
266
+ #
267
+ module_function
268
+
269
+ # Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
270
+ #
271
+ # @param [String] specification When.exe Standard Representation として解釈して生成する
272
+ # @param [Numeric] specification ユリウス日として解釈して生成する
273
+ # @param [Array] specification 要素を個別に解釈して生成したオブジェクトのArrayを返す
274
+ # @param [When::TM::TemporalPosition, When::Parts::GeometricComplex] specification specificationをそのまま返す
275
+ # @param [When::TM::TemporalPosition] specification specification.any_otherを返す
276
+ #
277
+ # @param [Hash] options 暦法や時法などの指定 (see {When::TM::TemporalPosition._instance})
278
+ #
279
+ # @return [When::TM::TemporalPosition, When::TM::Duration, When::Parts::GeometricComplex or Array<them>]
280
+ #
281
+ def when?(specification, options={})
282
+
283
+ # フォーマットごとの処理
284
+ case specification
285
+ when TM::TemporalPosition, Parts::GeometricComplex ; specification
286
+ when TM::Position ; specification.any_other
287
+ when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
288
+ when /^today$/i ; today(options)
289
+ when /^now$/i ; now(options)
290
+ when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
291
+ when String ; TM::TemporalPosition._instance(specification, options)
292
+ when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
293
+ else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
294
+ end
295
+ end
296
+
297
+ # When::TM::TemporalPosition の生成
298
+ #
299
+ # @overload TemporalPosition(*args, options={})
300
+ # @param [String or [String, Integer], Numeric, ...] args
301
+ # [String] 年号
302
+ # [Array<String, Integer>] 年号と 0 年の通年
303
+ # [Numeric] 年月日時分秒(途中で打ち切り可)
304
+ # @param [Hash] options 暦法や時法などの指定
305
+ # @option options [Symbol] :invalid
306
+ # [:raise 日時が存在しない場合例外発生 ]
307
+ # [:check 日時が存在しない場合 nil を返す ]
308
+ # [その他/nil 日時が存在することを確認しない(デフォルト)]
309
+ # @see When::TM::TemporalPosition._instance
310
+ #
311
+ # @return [When::TM::TemporalPosition]
312
+ # @raise [ArgumentError]
313
+ # options[ :invalid ] が :raise で、日時が存在しない場合
314
+ #
315
+ def TemporalPosition(*args)
316
+ # 引数の解釈
317
+ options = args[-1].kind_of?(Hash) ? args.pop.dup : {}
318
+ validate = options.delete(:invalid)
319
+ options = TM::TemporalPosition._options(options)
320
+ options[:frame] ||= 'Gregorian'
321
+ options[:frame] = Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
322
+ options[:era_name] = args.shift if args[0].kind_of?(String) || args[0].kind_of?(Array)
323
+
324
+ # 時間位置の生成
325
+ date = Array.new(options[:frame].indices.length+1) {args.shift}
326
+ if (args.length > 0)
327
+ options[:clock] ||= TM::Clock.local_time || utc
328
+ time = Array.new(options[:clock].indices.length) {args.shift}
329
+ position = TM::DateAndTime.new(date, time.unshift(0), options)
330
+ else
331
+ position = TM::CalDate.new(date, options)
332
+ end
333
+ return position unless [:raise, :check].include?(validate)
334
+
335
+ # 時間位置の存在確認
336
+ date[0] = -date[0] if position.calendar_era_name && position.calendar_era_name[2] # 紀元前
337
+ date.each_index do |i|
338
+ break unless date[i]
339
+ next if Coordinates::Pair._force_pair(date[i]) == Coordinates::Pair._force_pair(position.cal_date[i])
340
+ return nil if validate == :check
341
+ raise ArgumentError, "Specified date not found: #{date}"
342
+ end
343
+ return position unless time
344
+ time.each_index do |i|
345
+ break unless time[i]
346
+ next if Coordinates::Pair._force_pair(time[i]) == Coordinates::Pair._force_pair(position.clk_time.clk_time[i])
347
+ return nil if validate == :check
348
+ raise ArgumentError, "Specified time not found: #{time}"
349
+ end
350
+ return position
351
+ end
352
+
353
+ # 指定日時に対応する When::TM::TemporalPosition の生成
354
+ # (When::TM::DateAndTime of specified Time)
355
+ #
356
+ # @param [::Time] time 変換元の日時のTimeオブジェクト
357
+ # @param [Float] time 1970-01-01T00:00:00Z からの経過秒数
358
+ # @param [Hash] options 暦法や時法などの指定
359
+ # @see When::TM::TemporalPosition._instance
360
+ #
361
+ # @return [When::TM::DateAndTime]
362
+ #
363
+ def at(time, options={})
364
+ options = options._attr if options.kind_of?(TM::TemporalPosition)
365
+ options[:frame] ||= 'Gregorian'
366
+ options[:frame] = Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
367
+ clock = TM::Clock.get_clock(options)
368
+ jdt = TM::JulianDate.universal_time(time.to_f * TM::IntervalLength::SECOND, {:frame=>clock})
369
+ options[:clock] = jdt.frame
370
+ date = options[:frame].jul_trans(jdt, options)
371
+ date = TM::CalDate.new(date.cal_date, options) if options[:precision] &&
372
+ options[:precision] <= DAY
373
+ return date
374
+ end
375
+
376
+ # 現在日時に対応する When::TM::TemporalPosition の生成
377
+ # (When::TM::DateAndTime of now)
378
+ # @note メソッド実行時の「現在日時」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
379
+ #
380
+ # @param [Hash] options 暦法や時法などの指定
381
+ # @see When::TM::TemporalPosition._instance
382
+ #
383
+ # @return [When::TM::DateAndTime]
384
+ #
385
+ def now(options={})
386
+ When.at(Time.now, options)
387
+ end
388
+
389
+ # 本日に対応する When::TM::CalDate の生成
390
+ # (When::TM::CalDate of today)
391
+ # @note メソッド実行時の「本日」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
392
+ # @note options で時間帯を指定しても「本日」の決定に使用するのみで、戻り値には反映されない
393
+ #
394
+ # @param [Hash] options 暦法や時法などの指定
395
+ # @see When::TM::TemporalPosition._instance
396
+ #
397
+ # @return [When::TM::CalDate]
398
+ #
399
+ def today(options={})
400
+ now(options.merge({:precision=>DAY}))
401
+ end
402
+
403
+ # When::TM::Duration の生成
404
+ #
405
+ # @param [String] period When.exe Standard Representation として解釈して生成する
406
+ # @param [Numeric] period When::TM::IntervalLength::SYSTEM 単位の値として解釈して生成する
407
+ # @param [Array] period 要素を個別に解釈して生成したオブジェクトのArrayを返す
408
+ # @param [When::TM::Duration] period 処理を行わず、そのまま返す
409
+ # @param [Hash] options 現時点では未使用
410
+ #
411
+ # @return [When::TM::Duration or Array<them>]
412
+ #
413
+ def Duration(period, options={})
414
+ case period
415
+ when Array
416
+ period.map {|e| Duration(e, options)}
417
+
418
+ when TM::Duration
419
+ period
420
+
421
+ when 0
422
+ TM::IntervalLength.new(0, 'day')
423
+
424
+ when Numeric
425
+ [TM::Duration::YEAR, TM::Duration::MONTH, TM::Duration::WEEK, TM::Duration::DAY,
426
+ TM::Duration::HOUR, TM::Duration::MINUTE, TM::Duration::SECOND].each do |unit|
427
+ div, mod = period.divmod(unit)
428
+ return TM::IntervalLength.new(div, TM::Duration::Unit.invert[unit]) if mod == 0
429
+ end
430
+ TM::IntervalLength.new(period, 'system')
431
+
432
+ when String
433
+ # IntervalLength
434
+ args = TM::IntervalLength._to_array(period)
435
+ return TM::IntervalLength.new(*args) if args
436
+
437
+ # PeriodDuration
438
+ sign, *args = TM::PeriodDuration._to_array(period)
439
+ raise TypeError, "Argument 'period' is not a Duration" unless (sign)
440
+ args << options
441
+ duration = TM::PeriodDuration.new(*args)
442
+ return (sign >= 0) ? duration : -duration
443
+
444
+ else
445
+ nil
446
+ end
447
+ end
448
+
449
+ # When::TM::Calendar の生成/参照
450
+ #
451
+ # @param [String] calendar 暦法を表す文字列
452
+ #
453
+ # @return [When::TM::Calendar] calendar に対応する When::TM::Calendar オブジェクト
454
+ #
455
+ def Calendar(calendar)
456
+ Parts::Resource._instance(calendar, '_c:')
457
+ end
458
+
459
+ # When::CalendarTypes::CalendarNote の生成/参照
460
+ #
461
+ # @param [String] notes 暦注リストを表す文字列
462
+ #
463
+ # @return [When::CalendarTypes::CalendarNote] notes に対応する When::CalendarTypes::CalendarNote オブジェクト
464
+ #
465
+ def CalendarNote(notes)
466
+ Parts::Resource._instance(notes, '_n:')
467
+ end
468
+
469
+ # When::TM::CalendarEra の生成/参照
470
+ #
471
+ # @param [String] era 暦年代を表す文字列
472
+ #
473
+ # @return [When::TM::CalendarEra] era に対応する When::TM::CalendarEra オブジェクト
474
+ #
475
+ def CalendarEra(era)
476
+ Parts::Resource._instance(era, '_e:')
477
+ end
478
+
479
+ # When::TM::CalendarEra の検索
480
+ #
481
+ # @overload era(key, epoch=nil, reverse=nil, options={})
482
+ # @param [String, Regexp] key 検索する暦年代または、暦年代にマッチする正規表現
483
+ # @param [Integer] epoch 年数を昇順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
484
+ # @param [Integer] reverse 年数を降順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
485
+ # @param [Hash] options
486
+ # @option options [String] :area 暦年代の使用地域の指定(デフォルトは nil - 指定なし)
487
+ # @option options [String] :period 暦年代の使用時代の指定(デフォルトは nil - 指定なし)
488
+ # @option options [Integer] :count 何件ヒットするまで検索するかを指定(デフォルトは 1件)
489
+ # @option options [String] the_others 例えば When::TM::CalendarEra オブジェクトの epoch_of_use に 'name' などの
490
+ # 指定がある場合、:name に指定しておけば、検索での絞り込みに使用できる。
491
+ #
492
+ # @return [Array<When::TM::CalendarEra>] 検索結果を When::TM::CalendarEra オブジェクトの Array で返す
493
+ # @note ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを生成しつつ読み込んで検索する。
494
+ #
495
+ def era(*args)
496
+ TM::CalendarEra._instance(*args)
497
+ end
498
+
499
+ # When::TM::Clock の生成/参照
500
+ #
501
+ # @param [String] clock 時法を表す文字列
502
+ # @param [Numeric] clock 秒を単位として表した時差(東経側を + とする)
503
+ # @param [When::TM::Clock] clock なにもせず clock をそのまま返す
504
+ #
505
+ # @return [When::TM::Clock] clock に対応する When::TM::Clock オブジェクト
506
+ #
507
+ def Clock(clock)
508
+ case clock
509
+ when TM::Clock ; return clock
510
+ when 'Z' ; return utc
511
+ when /^LMT|LAT|THS|MTC/ ; return Parts::Resource._instance('_c:' + clock)
512
+ when Numeric ; return utc if clock==0
513
+ when String
514
+ c = TM::Clock[clock] || V::Timezone[clock]
515
+ return c if c
516
+ clock, options = clock.split('?')
517
+ else ; raise TypeError, "Invalid Type: #{clock.class}"
518
+ end
519
+ iri = "_tm:Clock?label=" + TM::Clock.to_hms(clock)
520
+ iri += "&" + options if options
521
+ Parts::Resource._instance(iri)
522
+ end
523
+
524
+ # When::CalendarTypes::UTC の生成/参照
525
+ #
526
+ # @return [When::CalendarTypes::UTC]
527
+ #
528
+ def utc
529
+ Parts::Resource._instance("_c:UTC")
530
+ end
531
+
532
+ #
533
+ # 曜日(剰余類)
534
+ #
535
+ # @param [Numeric] day 月曜を 0 とする七曜(剰余類)を返します
536
+ # @param [String] day 最初の3文字から決定した七曜(剰余類)を返します。
537
+ # 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
538
+ #
539
+ # @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類) または 名前の一致するその他の剰余類
540
+ #
541
+ def Residue(day)
542
+ When::Coordinates::Residue.to_residue(day)
543
+ end
544
+ alias :day_of_week :Residue
545
+
546
+ #
547
+ # 月名
548
+ #
549
+ # @param [Numeric] name 指定の月番号の月名を返します
550
+ # @param [String] name 最初の3文字から決定した月名を返します。
551
+ # 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
552
+ # (name が M17n なら name 自身をそのまま返します)
553
+ #
554
+ # @return [When::BasicTypes::M17n] 月名
555
+ #
556
+ def MonthName(name)
557
+ When::BasicTypes::M17n.month_name(name)
558
+ end
559
+
560
+ # When::BasicTypes::M17n の生成/参照
561
+ #
562
+ # @param [String] source 多言語対応文字列のIRI
563
+ #
564
+ # @return [When::BasicTypes::M17n] source に対応する When::BasicTypes::M17n オブジェクト
565
+ #
566
+ def M17n(source)
567
+ Parts::Resource._instance(source, '_m:')
568
+ end
569
+
570
+ # When::BasicTypes::M17n の生成/参照
571
+ #
572
+ # @param [When::BasicTypes::M17n] source 処理を行わず、そのままsourceを返す
573
+ # @param [String] source locale と 文字列の対応
574
+ # @param [Array] source 要素を個別に解釈して生成したオブジェクトのArrayを返す
575
+ # @param [Hash] namespace prefix の指定
576
+ # @param [Array] locale locale の定義順序の指定
577
+ # @param [Hash] options (see {When::BasicTypes::M17n.new}[link:When/BasicTypes/M17n.html#method-c-new])
578
+ #
579
+ # @return [When::BasicTypes::M17n or Array<them>]
580
+ #
581
+ def m17n(source, namespace=nil, locale=nil, options={})
582
+ case source
583
+ when Array ; BasicTypes::M17n.new(source, namespace, locale, options)
584
+ when BasicTypes::M17n ; source
585
+ when String
586
+ return self[$1] if source =~ /^\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource)
587
+ return Parts::Resource[$1] if source =~ /^\s*\[::([^\]]+)\]/
588
+ BasicTypes::M17n.new(source, namespace, locale, options)
589
+ else ; raise TypeError, "Invalid Type: #{source.class}"
590
+ end
591
+ end
592
+
593
+ # When::Parts::Resource の生成/参照
594
+ #
595
+ # @param [String] iri IRI を表す文字列
596
+ # @param [String] namespace デフォルトの namespace
597
+ #
598
+ # @return [When::Parts::Resourc] iri (または namespace:iri) に対応する When::Parts::Resource オブジェクト
599
+ #
600
+ def Resource(iri, namespace=nil)
601
+ Parts::Resource._instance(iri, namespace)
602
+ end
603
+ alias :IRI :Resource
604
+
605
+ # When::Coordinates::Pair の生成
606
+ #
607
+ # @param [Numeric, String] trunk 幹の要素
608
+ # @param [Numeric, String] branch 枝の要素
609
+ # @see When::Coordinates::Pair._force_pair
610
+ #
611
+ # @return [When::Coordinates::Pair]
612
+ #
613
+ def Pair(trunk, branch=nil)
614
+ Coordinates::Pair._force_pair(trunk, branch)
615
+ end
616
+ end