when_exe 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +171 -0
  3. data/lib/when_exe.rb +78 -47
  4. data/lib/when_exe/basictypes.rb +752 -747
  5. data/lib/when_exe/calendarnote.rb +805 -801
  6. data/lib/when_exe/calendartypes.rb +1583 -1531
  7. data/lib/when_exe/coordinates.rb +16 -15
  8. data/lib/when_exe/core/duration.rb +114 -110
  9. data/lib/when_exe/core/extension.rb +504 -504
  10. data/lib/when_exe/ephemeris.rb +1917 -1913
  11. data/lib/when_exe/ephemeris/moon.rb +333 -333
  12. data/lib/when_exe/ephemeris/notes.rb +389 -387
  13. data/lib/when_exe/ephemeris/planets.rb +585 -585
  14. data/lib/when_exe/ephemeris/sun.rb +214 -214
  15. data/lib/when_exe/googlecalendar.rb +144 -140
  16. data/lib/when_exe/icalendar.rb +1636 -1636
  17. data/lib/when_exe/inspect.rb +46 -22
  18. data/lib/when_exe/locales/akt.rb +176 -176
  19. data/lib/when_exe/locales/encoding_conversion.rb +134 -126
  20. data/lib/when_exe/locales/iast.rb +90 -90
  21. data/lib/when_exe/locales/locale.rb +750 -746
  22. data/lib/when_exe/locales/transliteration_table.rb +62 -62
  23. data/lib/when_exe/mini_application.rb +307 -305
  24. data/lib/when_exe/parts/enumerator.rb +2 -2
  25. data/lib/when_exe/parts/geometric_complex.rb +397 -397
  26. data/lib/when_exe/parts/method_cash.rb +224 -224
  27. data/lib/when_exe/parts/resource.rb +1069 -1071
  28. data/lib/when_exe/parts/timezone.rb +240 -230
  29. data/lib/when_exe/region/armenian.rb +56 -56
  30. data/lib/when_exe/region/babylonian.rb +405 -0
  31. data/lib/when_exe/region/bahai.rb +146 -146
  32. data/lib/when_exe/region/balinese.rb +622 -622
  33. data/lib/when_exe/region/chinese.rb +95 -25
  34. data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
  35. data/lib/when_exe/region/chinese/epochs.rb +1 -1
  36. data/lib/when_exe/region/chinese/twins.rb +803 -795
  37. data/lib/when_exe/region/christian.rb +824 -824
  38. data/lib/when_exe/region/coptic.rb +106 -87
  39. data/lib/when_exe/region/discordian.rb +225 -225
  40. data/lib/when_exe/region/far_east.rb +188 -188
  41. data/lib/when_exe/region/french.rb +56 -56
  42. data/lib/when_exe/region/geologicalage.rb +639 -639
  43. data/lib/when_exe/region/goddess.rb +58 -58
  44. data/lib/when_exe/region/indian.rb +1254 -1251
  45. data/lib/when_exe/region/iranian.rb +8 -8
  46. data/lib/when_exe/region/islamic.rb +3 -3
  47. data/lib/when_exe/region/japanese.rb +93 -99
  48. data/lib/when_exe/region/japanese/calendars.rb +396 -397
  49. data/lib/when_exe/region/japanese/epochs.rb +26 -26
  50. data/lib/when_exe/region/japanese/nihon_shoki.rb +71 -71
  51. data/lib/when_exe/region/japanese/notes.rb +1383 -1386
  52. data/lib/when_exe/region/japanese/residues.rb +1306 -1306
  53. data/lib/when_exe/region/japanese/twins.rb +225 -225
  54. data/lib/when_exe/region/japanese/weeks.rb +112 -0
  55. data/lib/when_exe/region/javanese.rb +230 -230
  56. data/lib/when_exe/region/jewish.rb +126 -126
  57. data/lib/when_exe/region/korean.rb +378 -378
  58. data/lib/when_exe/region/m17n.rb +114 -113
  59. data/lib/when_exe/region/martian.rb +258 -255
  60. data/lib/when_exe/region/mayan.rb +32 -32
  61. data/lib/when_exe/region/residue.rb +89 -89
  62. data/lib/when_exe/region/roman.rb +36 -24
  63. data/lib/when_exe/region/ryukyu.rb +97 -97
  64. data/lib/when_exe/region/shire.rb +240 -240
  65. data/lib/when_exe/region/soviet.rb +209 -0
  66. data/lib/when_exe/region/symmetry.rb +50 -50
  67. data/lib/when_exe/region/thai.rb +336 -335
  68. data/lib/when_exe/region/tibetan.rb +316 -315
  69. data/lib/when_exe/region/vietnamese.rb +440 -439
  70. data/lib/when_exe/region/weekdate.rb +80 -80
  71. data/lib/when_exe/region/world.rb +175 -175
  72. data/lib/when_exe/region/yerm.rb +14 -14
  73. data/lib/when_exe/region/zoroastrian.rb +203 -203
  74. data/lib/when_exe/timestandard.rb +707 -681
  75. data/lib/when_exe/tmduration.rb +338 -330
  76. data/lib/when_exe/tmobjects.rb +1346 -1325
  77. data/lib/when_exe/tmposition.rb +2115 -2072
  78. data/lib/when_exe/tmreference.rb +1693 -1669
  79. data/lib/when_exe/version.rb +1 -1
  80. data/link_to_online_documents +1 -1
  81. data/test/examples/JapanHolidaysRFC6350.ics +1 -1
  82. data/test/test.rb +67 -61
  83. data/test/test/basictypes.rb +409 -409
  84. data/test/test/calendarnote.rb +86 -69
  85. data/test/test/calendartypes.rb +97 -97
  86. data/test/test/coordinates.rb +396 -396
  87. data/test/test/ephemeris.rb +83 -74
  88. data/test/test/ephemeris/moon.rb +14 -14
  89. data/test/test/ephemeris/planets.rb +14 -14
  90. data/test/test/ephemeris/sun.rb +14 -14
  91. data/test/test/googlecalendar.rb +194 -176
  92. data/test/test/icalendar.rb +867 -858
  93. data/test/test/inspect.rb +117 -117
  94. data/test/test/parts.rb +487 -487
  95. data/test/test/region/balinese.rb +34 -0
  96. data/test/test/region/chinese.rb +218 -206
  97. data/test/test/region/christian.rb +245 -245
  98. data/test/test/region/coptic.rb +27 -27
  99. data/test/test/region/french.rb +33 -33
  100. data/test/test/region/geologicalage.rb +17 -17
  101. data/test/test/region/indian.rb +57 -57
  102. data/test/test/region/iran.rb +54 -54
  103. data/test/test/region/islamic.rb +18 -18
  104. data/test/test/region/japanese.rb +237 -219
  105. data/test/test/region/jewish.rb +61 -61
  106. data/test/test/region/m17n.rb +184 -184
  107. data/test/test/region/mayan.rb +195 -195
  108. data/test/test/region/residue.rb +147 -139
  109. data/test/test/region/thai.rb +116 -116
  110. data/test/test/region/tibetan.rb +30 -30
  111. data/test/test/region/vietnamese.rb +102 -102
  112. data/test/test/region/yerm.rb +146 -146
  113. data/test/test/timestandard.rb +81 -81
  114. data/test/test/tmobjects.rb +328 -328
  115. data/test/test/tmposition.rb +397 -284
  116. data/test/test/tmreference.rb +157 -157
  117. metadata +13 -10
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61d0b1c1a37dc54c8a87505b8ec22282052f56ee
4
+ data.tar.gz: 88aa53ad73c559c3d40f9992c4bd932f5292a48c
5
+ SHA512:
6
+ metadata.gz: c1d4d428fb2704611c027aae6f1d1301da50a69e76e386ed7ed56a2a9079c5f65d89b88b6084848cc9f04ebbfd2c4f5aa22e4bc26499c554179000f70d50cb20
7
+ data.tar.gz: cd39d0b62c40b1628c6ce1a06620064f095bcdd5115bafda9a1d297595c915d44c29b2fe0036ad3b7d582496fbb13e1b8d38d194b80b1bee57e06439a89b98f4
@@ -0,0 +1,171 @@
1
+ when_exe - A multicultural and multilingualized calendar library
2
+ ================================================================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/when_exe.svg)](http://badge.fury.io/rb/when_exe)
5
+
6
+ [when_exe](http://rubygems.org/gems/when_exe) is a multicultural and multilingualized calendar library based on ISO 8601, ISO 19108, RFC 5545 and RFC6350.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ The when_exe gem can be installed by running:
12
+
13
+ gem install when_exe
14
+
15
+
16
+ Documentation
17
+ -------------
18
+
19
+ API documentation for when_exe is available on [RubyDoc.info](http://rubydoc.info/gems/when_exe/frames).
20
+
21
+
22
+ License
23
+ -------
24
+
25
+ This beta version's license is limited. Please see [LICENSE.txt](https://github.com/suchowan/when_exe/blob/master/LICENSE.txt) for details.
26
+
27
+
28
+ Source Code
29
+ -----------
30
+
31
+ Source code for when_exe is available on [GitHub](https://github.com/suchowan/when_exe).
32
+
33
+
34
+ Example Usage
35
+ -------------
36
+
37
+ require 'when_exe'
38
+
39
+ # When::TM::CalDate
40
+
41
+ gregorian_date = When.tm_pos(2014, 8, 1)
42
+ p gregorian_date #=> 2014-08-01
43
+ p When.when?('2014-08-01') #=> 2014-08-01, the same date
44
+ p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
45
+ p gregorian_date.to_f #=> 2456871.0, at noon for UTC
46
+ p gregorian_date.class #=> When::TM::CalDate
47
+ p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
48
+ puts gregorian_date.name(When::MONTH) / 'en' #=> August
49
+ puts gregorian_date.name(When::MONTH) / 'fr' #=> août
50
+ puts gregorian_date.name(When::MONTH) / 'ar' #=> اغسطس
51
+ p gregorian_date.easter #=> 2014-04-20
52
+ p gregorian_date.is?('Easter') #=> false
53
+ p When.tm_pos(2014, 4, 20).is?('Easter') #=> true
54
+
55
+ islamic_date = When::TabularIslamic ^ gregorian_date
56
+ p islamic_date #=> 1435-10-04
57
+ p islamic_date.frame.iri #=> ""http://hosi.org/When/CalendarTypes/TabularIslamic"
58
+ puts islamic_date.name(When::MONTH) / 'en' #=> Shawwal
59
+ puts islamic_date.name(When::MONTH) / 'ar' #=> شوال
60
+
61
+ # When::TM::DateAndTime
62
+
63
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00')
64
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
65
+ p When.when?('2014-08-01T09:00:00+09:00') #=> 2014-08-01T09:00:00+09:00, the same date
66
+ p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
67
+ p gregorian_date.to_f #=> 2456870.5 at 09:00:00 of Timezone +09:00
68
+ p gregorian_date.class #=> When::TM::DateAndTime
69
+ p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
70
+ p gregorian_date.clk_time.class #=> When::TM::ClockTime
71
+ p gregorian_date.clk_time.frame.iri #=> "http://hosi.org/When/TM/Clock?label=+09:00"
72
+
73
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00',
74
+ :long=>'139.413012E', :lat=>'35.412222N')
75
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
76
+ p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.413012E&lat=35.412222N&alt=0"
77
+ p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
78
+ p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:46+09:00
79
+
80
+ darian_date = When::Darian ^ gregorian_date
81
+ p darian_date #=> 0216-13-23T15:12:11MTC
82
+ p darian_date.to_i #=> 49974, Serial Day Number(Integer)
83
+ p darian_date.to_f #=> 49974.13346485421
84
+ p darian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Darian"
85
+ p darian_date.clk_time.frame.iri #=> "http://hosi.org/When/CalendarTypes/MTC"
86
+ p darian_date.time_standard.iri #=> "http://hosi.org/When/TimeStandard/MartianTimeCoordinated?location=(_l:long=0&datum=Mars)"
87
+
88
+ # When::TM::CalendarEra
89
+
90
+ babylonian_date = When.tm_pos('NebuchadnezzarII', 1, 1, 1)
91
+ p babylonian_date #=> NebuchadnezzarII01(-603).01.01
92
+ p When.when?('NebuchadnezzarII1.1.1') #=> NebuchadnezzarII01(-603).01.01, the same date
93
+ p babylonian_date.to_i #=> 1500904, Julian Day Number(Integer)
94
+ p When.era('NebuchadnezzarII') #=> [_e:AncientOrient::Neo-Babylonian::NebuchadnezzarII]
95
+ p When.era('NebuchadnezzarII')[0] ^ 1500904 #=> NebuchadnezzarII01(-603).01.01, the same date
96
+ p babylonian_date.to_f #=> 1500904.0, at noon for UTC
97
+ p babylonian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/BabylonianPD"
98
+ p babylonian_date.calendar_era.iri #=> "http://hosi.org/When/TM/CalendarEra/AncientOrient::Neo-Babylonian::NebuchadnezzarII"
99
+
100
+ babylonian_date = When.when?('NebuchadnezzarII1.1.1T18:13:00',
101
+ :clock=>'+03:00?long=45&lat=32&border=Sunset')
102
+ 4.times do
103
+ p [babylonian_date , babylonian_date .to_i] #=>
104
+ # [NebuchadnezzarII01(-603).01.01T:18:13:00+03:00, 1500904]
105
+ # [NebuchadnezzarII01(-603).01.01T:18:14:00+03:00, 1500904]
106
+ # [NebuchadnezzarII01(-603).01.02T*18:15:00+03:00, 1500905]
107
+ # [NebuchadnezzarII01(-603).01.02T*18:16:00+03:00, 1500905]
108
+ babylonian_date += When::PT1M
109
+ end
110
+
111
+ # TZInfo
112
+ # https://rubygems.org/gems/tzinfo is required for this section's operations.
113
+ # Please install tzinfo before operation.
114
+
115
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :tz=>'Asia/Tokyo')
116
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
117
+ p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&label=Asia/Tokyo"
118
+ p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
119
+ p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:45+09:00
120
+
121
+ jst = When.tm_pos(1997, 4, 6, 15, 30, 00, :tz=>'Asia/Tokyo')
122
+ p jst #=> 1997-04-06T15:30:00+09:00
123
+ est = When.Clock('America/New_York') ^ jst
124
+ p est #=> 1997-04-06T01:30:00-05:00
125
+ jst = When.tm_pos(1997, 4, 6, 16, 30, 00, :tz=>'Asia/Tokyo')
126
+ p jst #=> 1997-04-06T16:30:00+09:00
127
+ edt = When.Clock('America/New_York') ^ jst
128
+ p edt #=> 1997-04-06T03:30:00-04:00
129
+
130
+ p When.when?('TZID=America/New_York:1997-10-26T01:30') #=> 1997-10-26T01:30-04:00
131
+ p When.when?('TZID=America/New_York:1997-10-26T01=30') #=> 1997-10-26T01:30-05:00
132
+ p When.when?('TZID=America/New_York:1997-10-26T02:30') #=> 1997-10-26T02:30-05:00
133
+ p When.when?('TZID=America/New_York:1997-10-26T03:30') #=> 1997-10-26T03:30-05:00
134
+
135
+ # Google Calendar
136
+ # https://github.com/suchowan/gcalapi is required for this section's operations.
137
+ # Please install gcalapi before operation.
138
+ # Please replace xxxxxxxx and ******** to valid pair of id and password.
139
+
140
+ service = GoogleCalendar::Service.new('xxxxxxxx@gmail.com', '********')
141
+ feed = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full" %
142
+ ['japanese', 'ja']
143
+ gcal = GoogleCalendar::Calendar::new(service, feed)
144
+ gcal.enum_for({'start-min'=>'2014-01-01', 'start-max'=>'2015-01-01',
145
+ 'orderby'=>'starttime', 'sortorder'=>'a'
146
+ }).each do |range|
147
+ puts '%s - %s' % [range, range.events[0].summary] #=>
148
+ # 2014-01-01T00:00:00.00+09:00...2014-01-02T00:00:00.00+09:00 - 元日
149
+ # 2014-01-02T00:00:00.00+09:00...2014-01-03T00:00:00.00+09:00 - 銀行休業日
150
+ # 2014-01-03T00:00:00.00+09:00...2014-01-04T00:00:00.00+09:00 - 銀行休業日
151
+ # 2014-01-13T00:00:00.00+09:00...2014-01-14T00:00:00.00+09:00 - 成人の日
152
+ # 2014-02-11T00:00:00.00+09:00...2014-02-12T00:00:00.00+09:00 - 建国記念の日
153
+ # 2014-03-21T00:00:00.00+09:00...2014-03-22T00:00:00.00+09:00 - 春分の日
154
+ # 2014-04-29T00:00:00.00+09:00...2014-04-30T00:00:00.00+09:00 - 昭和の日
155
+ # 2014-05-03T00:00:00.00+09:00...2014-05-04T00:00:00.00+09:00 - 憲法記念日
156
+ # 2014-05-04T00:00:00.00+09:00...2014-05-05T00:00:00.00+09:00 - みどりの日
157
+ # 2014-05-05T00:00:00.00+09:00...2014-05-06T00:00:00.00+09:00 - こどもの日
158
+ # 2014-05-06T00:00:00.00+09:00...2014-05-07T00:00:00.00+09:00 - みどりの日 振替休日
159
+ # 2014-07-21T00:00:00.00+09:00...2014-07-22T00:00:00.00+09:00 - 海の日
160
+ # 2014-09-15T00:00:00.00+09:00...2014-09-16T00:00:00.00+09:00 - 敬老の日
161
+ # 2014-09-23T00:00:00.00+09:00...2014-09-24T00:00:00.00+09:00 - 秋分の日
162
+ # 2014-10-13T00:00:00.00+09:00...2014-10-14T00:00:00.00+09:00 - 体育の日
163
+ # 2014-11-03T00:00:00.00+09:00...2014-11-04T00:00:00.00+09:00 - 文化の日
164
+ # 2014-11-23T00:00:00.00+09:00...2014-11-24T00:00:00.00+09:00 - 勤労感謝の日
165
+ # 2014-11-24T00:00:00.00+09:00...2014-11-25T00:00:00.00+09:00 - 勤労感謝の日 振替休日
166
+ # 2014-12-23T00:00:00.00+09:00...2014-12-24T00:00:00.00+09:00 - 天皇誕生日
167
+ # 2014-12-25T00:00:00.00+09:00...2014-12-26T00:00:00.00+09:00 - クリスマス
168
+ # 2014-12-31T00:00:00.00+09:00...2015-01-01T00:00:00.00+09:00 - 大晦日
169
+ end
170
+
171
+ For further detail, please refer to the [when_exe Wiki](http://www2u.biglobe.ne.jp/~suchowan/when_exe_wiki.html) pages.
@@ -48,25 +48,35 @@ module When
48
48
  #
49
49
  attr_reader :multi_thread
50
50
 
51
+ #
52
+ # Logger オブジェクト
53
+ #
54
+ # @return [Logger]
55
+ #
56
+ attr_accessor :logger
57
+ private :logger=
58
+
51
59
  # Initializations
52
60
  #
53
61
  # @param [Hash] options 以下の通り
54
- # @option options [When::Parts::Timezone::Base] :local デフォルトの地方時
55
- # @option options [When::Coordinates::Spatial] :location デフォルトの空間位置
56
- # @option options [When::TM::IntervalLength] :until V::Event::Enumerator の until
57
- # @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
58
- # @option options [String] :namespaces 名前空間定義の省略時に名前空間生成に用いる書式
59
- # @option options [Hash{String=>String}] :unification 漢字の包摂パターン ({ 包摂前の文字列=>包摂後の文字列 })
60
- # @option options [Array<String>] :order CalendarEra の検索順序 ([ IRI of When::TM::CalendarEra ])
61
- # @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
62
- # @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
63
- # @option options [String] :base_uri Base URI for When_exe Resources (Default When::SourceURI)
64
- # @option options [String] :root_dir Root Directory for When_exe Resources Cash data (Default When::RootDir)
65
- # @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
66
- # @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
67
- # @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
68
- # @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
69
- # @option options [true] :escape すべて毎回 method_missing を発生させる
62
+ # @option options [When::Parts::Timezone::Base] :local デフォルトの地方時
63
+ # @option options [When::Coordinates::Spatial] :location デフォルトの空間位置
64
+ # @option options [When::TM::IntervalLength] :until V::Event::Enumerator の until
65
+ # @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
66
+ # @option options [String] :namespace_format 名前空間定義の省略時に名前空間生成に用いる書式
67
+ # @option options [Hash{String=>String}] :unification 漢字の包摂パターン ({ 包摂前の文字列=>包摂後の文字列 })
68
+ # @option options [Array<String>] :order CalendarEra の検索順序 ([ IRI of When::TM::CalendarEra ])
69
+ # @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
70
+ # @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
71
+ # @option options [String] :base_uri Base URI for When_exe Resources (Default When::SourceURI)
72
+ # @option options [Hash<String=>String>] :additional_namespaces User defined namespaces (Default {})
73
+ # @option options [String] :root_dir Root Directory for When_exe Resources Cash data (Default When::RootDir)
74
+ # @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
75
+ # @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
76
+ # @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
77
+ # @option options [true] :escape すべて毎回 method_missing を発生させる
78
+ # @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
79
+ # @option options [Logger] :logger Logger オブジェクト
70
80
  #
71
81
  # @return [void]
72
82
  #
@@ -76,6 +86,7 @@ module When
76
86
  #
77
87
  def _setup_(options={})
78
88
  @multi_thread = options[:multi_thread]
89
+ @logger = options[:logger]
79
90
  Parts::MethodCash._setup_(options)
80
91
  Parts::Resource._setup_(options)
81
92
  Locale._setup_(options)
@@ -127,6 +138,8 @@ module When
127
138
  # When 直下に定数として定義する時法・暦法など(暗黙的追加)
128
139
  #
129
140
  def const_missing(constant)
141
+ sgn, *args = TM::PeriodDuration._to_array(constant.to_s)
142
+ return const_set(constant, TM::PeriodDuration.new(*args)) if sgn
130
143
  iri = Parts::Resource._abbreviation_to_iri(constant)
131
144
  return _const_missing(constant) unless iri
132
145
  resource = Parts::Resource._instance(iri)
@@ -146,7 +159,7 @@ module When
146
159
  #
147
160
  # ライブラリのあるディレクトリ
148
161
  #
149
- RootDir = File.dirname(__FILE__).sub(/\/[^\/]*$/,'')
162
+ RootDir = File.dirname(__FILE__).sub(/\/[^\/]*\z/,'')
150
163
 
151
164
  require 'when_exe/version'
152
165
  require 'when_exe/locales/locale'
@@ -202,7 +215,8 @@ module When
202
215
  autoload :Iranian, 'when_exe/region/iranian'
203
216
  autoload :Islamic, 'when_exe/region/islamic'
204
217
  autoload :Jewish, 'when_exe/region/jewish'
205
- autoload :Armenian, 'when_exe/region/Armenian'
218
+ autoload :AncientOrient, 'when_exe/region/babylonian'
219
+ autoload :Armenian, 'when_exe/region/armenian'
206
220
  autoload :Roman, 'when_exe/region/roman'
207
221
  autoload :Coptic, 'when_exe/region/coptic'
208
222
  autoload :French, 'when_exe/region/french'
@@ -255,6 +269,11 @@ module When
255
269
  autoload :EphemerisBasedIslamic, 'when_exe/region/islamic'
256
270
  autoload :Jewish, 'when_exe/region/jewish'
257
271
  autoload :Armenian, 'when_exe/region/armenian'
272
+ autoload :Babylonian, 'when_exe/region/babylonian'
273
+ autoload :BabylonianPD, 'when_exe/region/babylonian'
274
+ autoload :Seleucid, 'when_exe/region/babylonian'
275
+ autoload :SeleucidPD, 'when_exe/region/babylonian'
276
+ autoload :Ptolemaic, 'when_exe/region/coptic'
258
277
  autoload :Coptic, 'when_exe/region/coptic'
259
278
  autoload :JulianA, 'when_exe/region/roman'
260
279
  autoload :JulianB, 'when_exe/region/roman'
@@ -293,6 +312,8 @@ module When
293
312
  autoload :LunarPhases, 'when_exe/ephemeris/notes'
294
313
  autoload :Ephemeris, 'when_exe/ephemeris/notes'
295
314
  autoload :Japanese, 'when_exe/region/japanese/notes'
315
+ autoload :CommonWithRokuyo, 'when_exe/region/japanese/weeks'
316
+ autoload :RokuyoWeek, 'when_exe/region/japanese/weeks'
296
317
  autoload :Yis, 'when_exe/region/chinese'
297
318
  autoload :Balinese, 'when_exe/region/balinese'
298
319
  autoload :Javanese, 'when_exe/region/javanese'
@@ -301,6 +322,10 @@ module When
301
322
  autoload :Roman, 'when_exe/region/roman'
302
323
  autoload :Mayan, 'when_exe/region/mayan'
303
324
  autoload :Discordian, 'when_exe/region/discordian'
325
+ autoload :CommonWithSovietFiveDay, 'when_exe/region/soviet'
326
+ autoload :SovietFiveDayWeek, 'when_exe/region/soviet'
327
+ autoload :CommonWithSovietSixDay, 'when_exe/region/soviet'
328
+ autoload :SovietSixDayWeek, 'when_exe/region/soviet'
304
329
  # autoload :Yerm, 'when_exe/region/yerm'
305
330
  autoload :WorldWeek, 'when_exe/region/world'
306
331
  autoload :ShireWeek, 'when_exe/region/shire'
@@ -365,6 +390,7 @@ module When
365
390
  autoload :Iranian, 'when_exe/region/iranian'
366
391
  autoload :Hijra, 'when_exe/region/islamic'
367
392
  autoload :Jewish, 'when_exe/region/jewish'
393
+ autoload :AncientOrient, 'when_exe/region/babylonian'
368
394
  autoload :Roman, 'when_exe/region/roman'
369
395
  autoload :Julian, 'when_exe/region/roman'
370
396
  autoload :Pope, 'when_exe/region/pope'
@@ -373,8 +399,8 @@ module When
373
399
 
374
400
  # Defualt search path for Epochs and Eras
375
401
  DefaultEpochs = ['Common', 'ModernJapanese',
376
- 'Hijra', 'Jewish', 'Iranian',
377
- 'Roman', 'Byzantine', 'LongCount',
402
+ 'Hijra', 'Jewish', 'Iranian',
403
+ 'Roman', 'Byzantine', 'AncientOrient', 'LongCount',
378
404
  'BalineseLuniSolar', 'JavaneseLunar',
379
405
  'Japanese', 'JapanesePrimeMinister', 'NihonKoki', 'NihonShoki',
380
406
  'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
@@ -389,7 +415,8 @@ module When
389
415
  ['@ND', 'NaturalDisaster' ],
390
416
  ['@IY', 'InauspiciousYear'],
391
417
  ['@F', 'Foundation' ],
392
- ['@CR', 'CalendarReform' ]].map {|e|
418
+ ['@CR', 'CalendarReform' ],
419
+ ['@CE', 'CalendarEpoch' ]].map {|e|
393
420
  [e[0], When::Parts::Resource._instance('EpochEvents::'+e[1], '_m:')]
394
421
  }.flatten)]
395
422
 
@@ -397,17 +424,17 @@ module When
397
424
  Common = [{}, self, [
398
425
  'area:Common#{?Reform=Reform}',
399
426
  ['[BeforeCommonEra=en:BCE_(disambiguation),*alias:BCE]0.1.1'],
400
- ['[CommonEra=en:Common_Era,*alias:CE]1.1.1', 'Calendar Epoch', '01-01-01^Julian'],
401
- ['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', 'Calendar Reform', '#{Reform:1582.10.15}^Gregorian']
427
+ ['[CommonEra=en:Common_Era,*alias:CE]1.1.1', '@CE', '01-01-01^Julian'],
428
+ ['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', '@CR', '#{Reform:1582.10.15}^Gregorian']
402
429
  ]]
403
430
 
404
431
  # Modern Japanese Eras after the calendar reform to the Gregorian Calendar
405
432
  ModernJapanese = [self, [
406
433
  'area:[ModernJapanese]',
407
- ['[M=,alias:明=ja:明治]6.01.01', '@CR', '1873-01-01^Gregorian?note=Default'],
408
- ['[T=,alias:大=ja:大正]1.07.30', '@A', '1912-07-30'],
409
- ['[S=,alias:昭=ja:昭和]1.12.25', '@A', '1926-12-25'],
410
- ['[H=,alias:平=ja:平成]1.01.08', '@A', '1989-01-08']
434
+ ['[M=,alias:明=ja:%%<明治>]6.01.01', '@CR', '1873-01-01^Gregorian?note=Default'],
435
+ ['[T=,alias:大=ja:%%<大正>]1.07.30', '@A', '1912-07-30'],
436
+ ['[S=,alias:昭=ja:%%<昭和>]1.12.25', '@A', '1926-12-25'],
437
+ ['[H=,alias:平=ja:%%<平成>]1.01.08', '@A', '1989-01-08']
411
438
  ]]
412
439
  end
413
440
  end
@@ -419,7 +446,7 @@ module When
419
446
 
420
447
  # Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
421
448
  #
422
- # @param [String] specification When.exe Standard Representation として解釈して生成する
449
+ # @param [String] specification When.exe Standard Representation または ユリウス日JDN として解釈して生成する
423
450
  # @param [Numeric] specification ユリウス日として解釈して生成する
424
451
  # @param [Array] specification 要素を個別に解釈して生成したオブジェクトのArrayを返す
425
452
  # @param [When::TM::TemporalPosition, When::Parts::GeometricComplex] specification specificationをそのまま返す
@@ -434,14 +461,15 @@ module When
434
461
  # フォーマットごとの処理
435
462
  case specification
436
463
  when TM::TemporalPosition, Parts::GeometricComplex ; specification
437
- when TM::Position ; specification.any_other
438
- when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
439
- when /^today$/i ; today(options)
440
- when /^now$/i ; now(options)
441
- when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
442
- when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
443
- when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
444
- else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
464
+ when TM::Position ; specification.any_other
465
+ when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
466
+ when /\Atoday\z/i ; today(options)
467
+ when /\Anow\z/i ; now(options)
468
+ when /[JS]DN(\z|\^)/i; TM::JulianDate.parse(specification, options)
469
+ when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
470
+ when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
471
+ when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
472
+ else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
445
473
  end
446
474
  end
447
475
 
@@ -482,6 +510,7 @@ module When
482
510
  date = Array.new(options[:frame].indices.length+1) {args.shift}
483
511
  if (args.length > 0)
484
512
  options[:clock] ||= TM::Clock.local_time
513
+ options[:clock] = Clock(options[:clock])
485
514
  time = Array.new(options[:clock].indices.length) {args.shift}
486
515
  position = TM::DateAndTime.new(date, time.unshift(0), options)
487
516
  else
@@ -633,7 +662,9 @@ module When
633
662
  # @return [When::TM::CalendarEra] era に対応する When::TM::CalendarEra オブジェクト
634
663
  #
635
664
  def CalendarEra(era)
636
- Parts::Resource._instance(era, '_e:')
665
+ Parts::Resource._instance(era, '_e:') do |iri|
666
+ TM::CalendarEra.send(:_behalf_of, iri)
667
+ end
637
668
  end
638
669
 
639
670
  # When::TM::CalendarEra の検索
@@ -666,12 +697,12 @@ module When
666
697
  #
667
698
  def Clock(clock)
668
699
  case clock
669
- when Parts::Timezone::Base ; return clock
670
- when 'Z', 0 ; return UTC
671
- when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock))
672
- when /^#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock)
673
- when String ;
674
- else ; raise TypeError, "Invalid Type: #{clock.class}"
700
+ when Parts::Timezone::Base ; return clock
701
+ when 'Z', 0 ; return UTC
702
+ when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock))
703
+ when /\A#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock)
704
+ when String ;
705
+ else ; raise TypeError, "Invalid Type: #{clock.class}"
675
706
  end
676
707
  c = TM::Clock[clock] || V::Timezone[clock]
677
708
  return c if c
@@ -714,8 +745,8 @@ module When
714
745
  longitude = latitude = nil
715
746
  args.each do |arg|
716
747
  case arg
717
- when /^#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}$/; longitude = arg
718
- when /^#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}$/; latitude = arg
748
+ when /\A#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}\z/; longitude = arg
749
+ when /\A#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}\z/; latitude = arg
719
750
  else ; rest << arg
720
751
  end
721
752
  end
@@ -784,8 +815,8 @@ module When
784
815
  when BasicTypes::M17n ; source
785
816
  when String
786
817
  source = EncodingConversion.to_internal_encoding(source)
787
- return self[$1] if source =~ /^\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource)
788
- return Parts::Resource[$1] if source =~ /^\s*\[::([^\]]+)\]/
818
+ return self[$1] if source =~ /\A\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource)
819
+ return Parts::Resource[$1] if source =~ /\A\s*\[::([^\]]+)\]/
789
820
  BasicTypes::M17n.new(source, namespace, locale, options)
790
821
  else ; raise TypeError, "Invalid Type: #{source.class}"
791
822
  end
@@ -1,747 +1,752 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-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
- 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
- # @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
30
- # @option options [Integer] :ordinal_date_digits ISO8601拡大表記の年内通日の桁数(省略時 3桁)
31
- #
32
- # @return [Array] format, date, time, clock, era
33
- #
34
- # format (Symbol, nil)
35
- # nil 通常形式
36
- # :century 世紀指定形式 ('CC', '+CCCC', '-CCCC')
37
- # :day 年間通算日形式 ('YYDDD'など)
38
- # :week 暦週形式 ('YYWNN'など)
39
- #
40
- # date (Array<Numeric>) 日付部分
41
- #
42
- # time (Array<Numeric>) 時刻部分
43
- #
44
- # clock (String) 時間帯
45
- #
46
- # era (String, Array<String, Integer>) 年号(Integerは0年に対応する通年)
47
- #
48
- def _to_array(date_time, options={})
49
- raise TypeError, "Argument is not ISO 8601 String" unless date_time.kind_of?(String)
50
- if options[:abbr].kind_of?(When::TimeValue)
51
- options[:abbr] = ((options[:frame]||When::Gregorian) ^ options[:abbr]).cal_date
52
- end
53
- date_time = date_time.gsub(/_([\d])/, '\1')
54
- begin
55
- return _to_array_basic(date_time, options)
56
- rescue ArgumentError
57
- return _to_array_extended(date_time, options)
58
- end
59
- end
60
-
61
- private
62
-
63
- # ISO 8601 基本形式の表現を分解して配列化する
64
- def _to_array_basic(date_time, options={})
65
-
66
- case date_time
67
- # basic date & time format (ISO 8601)
68
- when /^([-+W\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?$/
69
- d, t, time, clock = $~[1..4]
70
- format, date = Date._to_array_basic_ISO8601(d, options)
71
-
72
- # basic date & time format (JIS X0301)
73
- when /^([.\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?$/
74
- raise ArgumentError, "Wrong date format" unless options[:era_name]
75
- d, t, time, clock = $~[1..4]
76
- format, date = Date._to_array_basic_X0301(d, options)
77
- era = options[:era_name]
78
-
79
- # basic time format (ISO 8601)
80
- when /^(T(-{0,2}[.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?$/
81
- t, time, clock = $~[1..3]
82
-
83
- # not supported
84
- else
85
- raise ArgumentError, "Wrong date format: #{date_time}"
86
- end
87
-
88
- return [format, date, Time._to_array_basic(time, t, options),
89
- Time._to_string_clock(clock), era]
90
- end
91
-
92
- # ISO 8601 拡張形式の表現を分解して配列化する
93
- def _to_array_extended(date_time, options={})
94
-
95
- case date_time
96
- # extended date & time format (ISO 8601)
97
- when /^([-+*&%@!>=<?\dW.\(\)]+)(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?$/
98
- d, t, time, clock = $~[1..4]
99
- if d =~ /[\(\)]/
100
- d = When::CalendarTypes::Yerm.parse(d, options[:abbr])
101
- options[:frame] ||= 'Yerm'
102
- end
103
- format, date = Date._to_array_extended_ISO8601(d, options)
104
-
105
- # extended date & time format (JIS X0301)
106
- when /^((.+::)?(\[[^\]]+\]|[^-+\d]+))([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?$/
107
- era, parent, child, d, t, time, clock = $~[1..7]
108
- format, date, era = Date._to_array_extended_X0301(d, era, options)
109
- era ||= options[:era_name] if (d =~ /\./)
110
-
111
- # extended time format (ISO 8601)
112
- when /^(T(-{0,2}[:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?$/
113
- t, time, clock = $~[1..3]
114
-
115
- # not supported
116
- else
117
- raise ArgumentError, "Wrong date format: #{date_time}"
118
- end
119
-
120
- return [format, date, Time._to_array_extended(time, t, options),
121
- Time._to_string_clock(clock), era]
122
- end
123
- end
124
- end
125
-
126
- #
127
- # ISO 8601 Date Representation
128
- #
129
- # see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date]
130
- #
131
- class Date < DateTime
132
-
133
- # @private
134
- Extra_Year_Digits = Hash.new {|hash, key|
135
- ex = (key || 1).to_i
136
- hash[key] =
137
- if ex > 0
138
- [
139
- /^(\d{2})$/,
140
- /^([-+]\d{#{4+ex}})(\d{2})(\d{2})$/,
141
- /^([-+]\d{#{4+ex}})-(\d{2})$/,
142
- /^([-+]\d{#{4+ex}})$/,
143
- /^([-+]\d{#{4+ex}})W(\d{2})(\d{1})?$/,
144
- /^([+]\d{#{2+ex}})$/,
145
- /^([-]\d{#{2+ex}})$/,
146
- /^([-+]\d{#{4+ex}})(\d{3})$/
147
- ]
148
- elsif ex == 0
149
- [/^(\d{2})$/] + [/^(\d{4})$/] * 6
150
- else
151
- [/^(\d{4})$/] * 7
152
- end
153
- }
154
-
155
- # @private
156
- Ordinal_Date_Digits = Hash.new {|hash, key|
157
- hash[key] = /^(\d{#{(key || 3).to_i}})$/
158
- }
159
-
160
- class << self
161
- # ISO 8601 基本形式の表現を分解して配列化する
162
- def _to_array_basic_ISO8601(date, options={})
163
- by, bm, bd = options[:abbr]
164
- extra_reg = Extra_Year_Digits[options[:extra_year_digits]]
165
- case date
166
- when nil ; return nil
167
- when /^(\d{4})(\d{2})(\d{2})$/ ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.1
168
- when /^(\d{4})-(\d{2})$/ ; return nil, [$1.to_i, $2.to_i] # 5.2.1.2
169
- when /^(\d{4})$/ ; return nil, [$1.to_i] # 5.2.1.2
170
- when extra_reg[0] ; return :century,[$1.to_i * 100] # 5.2.1.2
171
- when /^(\d{4})(\d{3})$/ ; return :day, [$1.to_i, $2.to_i] # 5.2.2.1
172
- when /^(\d{4})W(\d{2})(\d{1})?$/ ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.1-2
173
- when extra_reg[1] ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.4 a)
174
- when extra_reg[2] ; return nil, [$1.to_i, $2.to_i] # 5.2.1.4 b)
175
- when extra_reg[3] ; return nil, [$1.to_i] # 5.2.1.4 c)
176
- when extra_reg[4] ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.4 a-b)
177
- when extra_reg[5] ; return :century,[$1.to_i * 100] # 5.2.1.4 d)
178
- when extra_reg[6] ; return :century,[$1.to_i * 100] unless by # 5.2.1.4 d)
179
- when extra_reg[7] ; return :day, [$1.to_i, $2.to_i] # 5.2.2.3 a)
180
- else ; raise ArgumentError, "Wrong date format" unless by
181
- end
182
-
183
- by = by.to_i
184
- case date
185
- when /^(\d{2})(\d{2})(\d{2})$/ ; return nil, [_century($1,by), $2.to_i, $3.to_i] # 5.2.1.3 a)
186
- when /^-(\d{2})(\d{2})?$/ ; return nil, [_century($1,by), _int($2)] # 5.2.1.3 b-c)
187
- when /^--(\d{2})(\d{2})?$/ ; return nil, [by, $1.to_i, _int($2)] # 5.2.1.3 d-e)
188
- when /^(\d{2})(\d{3})$/ ; return :day, [_century($1,by), $2.to_i] # 5.2.2.2 a)
189
- when /^-(\d{3})$/ ; return :day, [by, $1.to_i] # 5.2.2.2 b)
190
- when /^(\d{2})W(\d{2})(\d{1})?$/ ; return :week, [_century($1,by), $2.to_i, _int($3)] # 5.2.3.3 a-b)
191
- when /^-(\d{1})W(\d{2})(\d{1})?$/ ; return :week, [_decade($1,by), $2.to_i, _int($3)] # 5.2.3.3 c-d)
192
- when /^-W(\d{2})(\d{1})?$/ ; return :week, [by, $1.to_i, _int($2)] # 5.2.3.3 e-f)
193
- else ; raise ArgumentError, "Wrong date format" unless bm
194
- end
195
-
196
- bm = bm.to_i
197
- case date
198
- when /^---(\d{2})$/ ; return nil, [by, bm, $1.to_i] # 5.2.1.3 f)
199
- when /^-W-(\d{1})$/ ; return :week, [by, bm, $1.to_i] # 5.2.3.3 g)
200
- when /^----$/ ; return nil, [by, bm, bd.to_i] if bd # extension
201
- end
202
-
203
- raise ArgumentError, "Wrong date format: #{date}"
204
- end
205
-
206
- # JIS X0301 基本形式の表現を分解して配列化する
207
- def _to_array_basic_X0301(date, options={})
208
- raise ArgumentError, "Wrong date format" unless date =~ /\./
209
- date.scan(/\d+\./) do |part|
210
- raise ArgumentError, "Wrong date format" unless part.length == 3
211
- end
212
- _to_array_basic_ISO8601(date.gsub(/\./, ''), {:abbr=>options[:abbr]||1})
213
- end
214
-
215
- # ISO 8601 拡張形式の表現を分解して配列化する
216
- def _to_array_extended_ISO8601(date, options={})
217
- return nil unless date
218
- abbr = Array(options[:abbr]).dup
219
- unless date =~ /^([-+]?\d+#{abbr[0] ? '|-' : ''})([-*=.])?(.*)/
220
- raise ArgumentError, "Wrong date format: #{date}"
221
- end
222
- date = $3
223
- dd = [Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)]
224
- while date =~ /^(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])(.+)/
225
- date = $3
226
- dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
227
- end
228
- case date
229
- when /^W(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?(\d+)?([-*=?%@])?$/
230
- dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
231
- dd << Coordinates::Pair._en_pair($3, $4)
232
- return :week, dd
233
- when Ordinal_Date_Digits[options[:ordinal_date_digits]]
234
- dd << $1.to_i
235
- return :day, dd
236
- when /^(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?$/
237
- dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
238
- return nil, dd
239
- when ''
240
- return nil, dd
241
- else
242
- raise ArgumentError, "Wrong date format: #{date}"
243
- end
244
- end
245
-
246
- # JIS X0301 拡張形式の表現を分解して配列化する
247
- def _to_array_extended_X0301(date, era, options={})
248
- if (date =~ /^([-+\d]+)\(([-+\d]+)\)(.*)$/)
249
- year = $2
250
- date = $1 + $3
251
- end
252
- format, date = _to_array_extended_ISO8601(date, options)
253
- if (year)
254
- yy = year.to_i
255
- ee = date[0] * 1
256
- era = [era, yy-ee, yy+ee]
257
- end
258
- return format, date, era
259
- end
260
-
261
- private
262
-
263
- def _completion(digits, base)
264
- case digits
265
- when nil ; return nil
266
- when /^\d{5}/ ; raise ArgumentError, "Wrong date format: #{digits}"
267
- else ; return digits.to_i unless base
268
- end
269
-
270
- base = base.to_i
271
- case digits
272
- when '-' ; return base
273
- when /^-?(\d{1})$/ ; return _decade( $1, base)
274
- when /^-?(\d{2})$/ ; return _century($1, base)
275
- else ; return digits.to_i
276
- end
277
- end
278
-
279
- def _century(year, base)
280
- quotient, remainder = base.divmod(100)
281
- year = year.to_i
282
- quotient += 1 if year < remainder
283
- return quotient * 100 + year
284
- end
285
-
286
- def _decade(year, base)
287
- quotient, remainder = base.divmod(10)
288
- year = year.to_i
289
- quotient += 1 if year < remainder
290
- return quotient * 10 + year
291
- end
292
-
293
- def _int(digits)
294
- return digits ? digits.to_i : nil
295
- end
296
- end
297
- end
298
-
299
- #
300
- # ISO 8601 Time Representation
301
- #
302
- # see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#time]
303
- #
304
- class Time < DateTime
305
-
306
- class << self
307
- # 基本形式の表現を分解して配列化する
308
- def _to_array_basic(time, t, options={})
309
- return nil unless t
310
- return [0] unless time
311
- time.sub!(/,/, '.')
312
- unless (time =~ /^(\d{2}(?:\.\d+)?|-)(\d{2}(?:\.\d+)?|-)?(\d{2}(\.\d+)?)?$/)
313
- raise ArgumentError, "Wrong time format: #{time}"
314
- end
315
- indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
316
- abbr = Array(options[:abbr]).dup
317
- abbr[0..indices.length] = []
318
- return [0, Coordinates::Pair._en_number($1=='-' ? abbr[0] : $1, nil),
319
- Coordinates::Pair._en_number($2=='-' ? abbr[1] : $2, nil),
320
- Coordinates::Pair._en_number($3, nil)]
321
- end
322
-
323
- # 拡張形式の表現を分解して配列化する
324
- def _to_array_extended(time, t, options={})
325
- return nil unless t
326
- return [0] unless time
327
- indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
328
- abbr = Array(options[:abbr]).dup
329
- abbr[0..indices.length] = []
330
- time.sub!(/,/, '.')
331
- tt = [0]
332
- while time =~ /^(\d{2}(?:\.\d+)?|-)([:*=])(.+)/
333
- time = $3
334
- tt << Coordinates::Pair._en_pair($1=='-' ? abbr.shift : $1, $2)
335
- end
336
- case time
337
- when /^(\d{2}(\.\d+)?)$/
338
- tt << Coordinates::Pair._en_number($1, nil)
339
- when ''
340
- else
341
- raise ArgumentError, "Wrong time format: #{time}"
342
- end
343
- return tt
344
- end
345
-
346
- # 時間帯の表現を正規化する
347
- def _to_string_clock(clock)
348
- return nil unless clock
349
- return clock if (clock =~ /^[A-Z]+(\?.+)?$/)
350
- raise ArgumentError, "Wrong clock format: #{clock}" unless clock =~ /^([-+])(\d{2})(?::?(\d{2}))?(?::?(\d{2}))?$/
351
- sgn, h, m, s = $~[1..4]
352
- zone = sgn + h + ':' + (m||'00')
353
- zone += s if s
354
- return zone
355
- end
356
- end
357
- end
358
-
359
- # コード
360
- #
361
- # 当該コードを定義している辞書, シソーラスまたは機関への参照を
362
- # オプショナルな codeSpace 属性に保持することができる文字列
363
- #
364
- # see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#CodeType gml schema}
365
- #
366
- class Code < String
367
-
368
- # an optional codeSpace
369
- #
370
- # @return [String] anyURI (Optional)
371
- attr_accessor :code_space
372
- alias :codeSpace :code_space
373
- private :code_space=
374
-
375
- # オブジェクトの生成
376
- #
377
- # @param [String] code Text token
378
- # @param [String] namespace code を定義している authority の URI
379
- #
380
- def initialize(code, namespace=nil)
381
- @code_space = namespace
382
- self[0..-1] = code
383
- end
384
- end
385
-
386
- #
387
- # == 多言語対応文字列
388
- #
389
- # 本ライブラリで用いる諸々の用語を多言語対応で曖昧性なく管理するため
390
- # Code の subclass として定義する
391
- #
392
- # == 内部変数
393
- # === self[ 0..-1 ] : String
394
- # インスタンスを代表する文字列
395
- # 通常の String として振舞う場合は、この文字列として振舞う
396
- #
397
- # === @locale : Hash
398
- # インスタンスがさす言葉の諸言語での表現を文字列として保持する
399
- # locale指定('lang_country.encoding') => その locale での文字列
400
- # locale指定の要素に省略がある場合、残った共通の要素によって文字列を特定する
401
- # Ex. @locale = {'en'=>'March', 'ja'=>'三月'} ならば、locale が
402
- # 'en_US', 'en_GB' のいずれでもlocale での文字列は 'March'
403
- #
404
- # === @namespace : Hash
405
- # インスタンスがさす言葉の意味を特定するための authority の URI を保持する
406
- # locale指定('lang_country.encoding') => その locale での authority の URI
407
- # locale指定の要素に省略がある場合、残った共通の要素によってURIを特定する
408
- # Ex. @locale = {'en'=>'en:March', 'ja'=>'ja:3%E6%9C%88'} ならば、locale が
409
- # 'en_US', 'en_GB' のいずれでもlocale での authority の URIは 'en:March'
410
- # 当該用語が標準管理機関で管理されていない場合、wikipedia の当該項目の URI を用いる
411
- #
412
- # === @code_space : String
413
- # 代表的な authority URI
414
- # @namespace[''] である
415
- #
416
- # see {When::Locale}, {When::Parts::Resource}
417
- #
418
- class M17n < Code
419
- include When::Locale
420
- include Parts::Resource
421
-
422
- # @private
423
- HashProperty = [:label, :names, :link, :access_key, :code_space]
424
-
425
- # @private
426
- LabelTypes = {
427
- 'Residue' => ['Coordinates', '%s', '_co:%s%s' ],
428
- 'Week' => ['CalendarNote', '%sWeek', '_n:%sWeek%s' ],
429
- 'Notes' => ['CalendarNote', '%s', '_n:%s/Notes%s'],
430
- nil => ['BasicTypes::M17n', '%s', '_m:%s%s' ]
431
- }
432
-
433
- class << self
434
-
435
- #
436
- # resource の取得
437
- #
438
- # @param [When::Parts::Resource, String] source
439
- #
440
- # @return [When::Parts::Resource]
441
- #
442
- # @private
443
- def _label(source)
444
- case source
445
- when Parts::Resource, nil ; return source
446
- when Parts::Resource::IRIHeader ; return Parts::Resource._instance(source)
447
- end
448
- iri = Parts::Resource._abbreviation_to_iri(source, LabelTypes)
449
- iri ? Parts::Resource._instance(iri) : nil
450
- end
451
-
452
- #
453
- # label の取得
454
- #
455
- # @param [When::Parts::Resource, String] source
456
- #
457
- # @return [When::BasicTypes::M17n, String]
458
- #
459
- def label(source)
460
- resource = _label(source)
461
- case resource
462
- when nil ; return source
463
- when M17n ; return resource
464
- when Parts::Resource ; return resource.label
465
- else ; return resource
466
- end
467
- end
468
-
469
- #
470
- # label の Array の取得
471
- #
472
- # @param [When::Parts::Resource, Array] source
473
- #
474
- # @return [Array]
475
- #
476
- def labels(source)
477
- array =
478
- if source.kind_of?(Array)
479
- source
480
- else
481
- resource = _label(source)
482
- return nil unless resource
483
- resource.child
484
- end
485
- case array[0]
486
- when M17n ; return array
487
- when Parts::Resource ; return array.map {|v| v.label}
488
- else ; return array
489
- end
490
- end
491
- end
492
-
493
- #
494
- # 代表名
495
- #
496
- # @return [String]
497
- #
498
- attr_reader :label
499
-
500
- #
501
- # 名前が意味するもの自体のオブジェクト
502
- #
503
- # @return [When::BasicTypes::Object]
504
- #
505
- alias :what :parent
506
-
507
- #
508
- # When::BasicTypes::M17n に変換する - 何もしないで自身を返す
509
- #
510
- # @return [When::BasicTypes::M17n]
511
- #
512
- def to_m17n
513
- self
514
- end
515
-
516
- #
517
- # 内部エンコーディング文字列化
518
- #
519
- def to_internal_encoding
520
- _copy({:label => When::EncodingConversion.to_internal_encoding(to_s),
521
- :names => Hash[*(names.keys.map {|name| [name, When::EncodingConversion.to_internal_encoding(names[name])]}).flatten],
522
- :link => link,
523
- :access_key => access_key,
524
- :code_space => code_space
525
- })
526
- end
527
-
528
- #
529
- # 外部エンコーディング文字列化
530
- #
531
- def to_external_encoding
532
- _copy({:label => When::EncodingConversion.to_external_encoding(to_s),
533
- :names => Hash[*(names.keys.map {|name| [name, When::EncodingConversion.to_external_encoding(names[name])]}).flatten],
534
- :link => link,
535
- :access_key => access_key,
536
- :code_space => code_space
537
- })
538
- end
539
-
540
- # オブジェクトの生成
541
- #
542
- # @overload initialize(names, namespace={}, locale=[])
543
- # @param [Array<String>] names
544
- #
545
- # [String] '*locale:label=prefix:link'
546
- # * - 存在すれば、label をインスタンスを代表する文字列とする
547
- # locale - label に対応する locale指定(なければ、locale 引数の指定を用いる)
548
- # label - locale 指定に対応する label
549
- # prefix:link - その locale での authority の URI
550
- # prefix: - namespace 引数の指定により URI に展開する
551
- # link - なければ labelをURI encodeして用いる
552
- #
553
- # @param [Hash] namespace { prefix=>uri }
554
- #
555
- # lables, locale 引数の prefix の展開に用いる
556
- #
557
- # @param [Array<String>] locale
558
- #
559
- # [String] '*locale=prefix:link'
560
- # * - 存在すれば、label をインスタンスを代表する文字列とする
561
- # locale - locale指定
562
- # prefix:link - authority の URI
563
- # prefix: - namespace 引数の指定により URI に展開する
564
- #
565
- # @example
566
- # M17n.new(['3月', 'fr:Mars=http://fr.wikipedia.org/wiki/Mars_(mois)', 'March'],
567
- # {'en_wikipedia'=>'http://en.wikipedia.org/wiki/',
568
- # 'ja_wikipedia'=>'http://ja.wikipedia.org/wiki/'},
569
- # ['=ja_wikipedia:', '*en=en_wikipedia:']) を行うと、生成された M17n では、
570
- # @names = {'' =>'3月', 'fr'=>'Mars', 'en'=>'March'}
571
- # @namespace = {'' =>'http://ja.wikipedia.org/wiki/3%E6%9C%88',
572
- # 'fr'=>'http://fr.wikipedia.org/wiki/Mars_(mois)',
573
- # 'en'=>'http://en.wikipedia.org/wiki/March'}
574
- # となり、通常の String として振舞う場合は 'March' として振舞う
575
- #
576
- def initialize(*args)
577
- rest, options = _attributes(args)
578
- _sequence
579
-
580
- return _pool[@label.to_s] ?
581
- _copy_all(_pool[@label.to_s]) : # 階層になった Resource の代表ラベルのための生成
582
- _copy(options) if @label # M17n#to_h の出力と書式互換の入力による生成
583
-
584
- case rest[0]
585
- when When::Parts::Resource::ContentLine
586
- content, namespace = rest
587
- namespace ||= {}
588
- names = []
589
- locale = []
590
- begin
591
- loc = content.attribute['language'].object
592
- locale << [nil, loc, namespace[loc]]
593
- name = content.object
594
- ref = content.attribute['reference'] || content.attribute['url']
595
- name += '=' + (/^NUL$/i =~ ref.object ? '' : ref.object) if ref
596
- names << name
597
- end while (content = content.same_altid)
598
- @names ||= names.reverse
599
- @namespace ||= namespace if namespace.kind_of?(Hash)
600
- @locale ||= locale.reverse
601
- when nil ;
602
- else
603
- names, namespace, locale = rest
604
- @names = names if names
605
- @namespace ||= When::Locale._namespace(namespace) if namespace
606
- @locale ||= When::Locale._locale(locale) if locale
607
- end
608
- @namespace ||= {}
609
- @locale ||= []
610
-
611
- @code_space = @namespace['']
612
- self[0..-1] = @label = _names(@names, @namespace, @locale)
613
- end
614
- end
615
-
616
- #
617
- # Abstract class for instance having permanent life with IRI
618
- #
619
- # see {When::Parts::Resource}
620
- # see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#ObjectType gml schema}
621
- #
622
- class Object
623
-
624
- include Parts::Resource
625
-
626
- # 名前
627
- #
628
- # @return [String, When::BasicTypes::M17n]
629
- #
630
- attr_reader :label
631
-
632
- private
633
-
634
- # オブジェクトの初期化
635
- def initialize(*args)
636
- @_lock_ = Mutex.new if When.multi_thread
637
- _normalize(*_attributes(args))
638
- _sequence
639
- end
640
- end
641
- end
642
-
643
- #
644
- # RS::Identifier を提供する
645
- #
646
- module RS
647
-
648
- # 参照系の識別子
649
- #
650
- # see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#IdentifierType gml schema}
651
- #
652
- class Identifier
653
-
654
- # The code or name for this Identifier
655
- #
656
- # @return [When::BasicTypes::Code]
657
- #
658
- attr_reader :name
659
-
660
- # Identifier of the version of the associated codeSpace or code
661
- #
662
- # @return [Array<String>]
663
- #
664
- attr_reader :version
665
-
666
- # Remarks about this code or alias
667
- #
668
- # @return [Array<String>] String は URI/IRI文字列の場合あり
669
- #
670
- attr_reader :remarks
671
-
672
- # オブジェクトの生成
673
- #
674
- # @param [When::BasicTypes::Code] name
675
- # @param [Array<String>] version
676
- # @param [Array<String>] remarks String は URI/IRI文字列の場合あり
677
- #
678
- def initialize(name, version=nil, remarks=nil)
679
- @name = name
680
- @version = version
681
- @remarks = remarks
682
- end
683
-
684
- # その他のメソッド
685
- #
686
- # @note When::RS::Identifier で定義されていないメソッドは
687
- # 処理を @name (type: When::BasicTypes::Code) に委譲する
688
- #
689
- def method_missing(name, *args, &block)
690
- self.class.module_eval %Q{
691
- def #{name}(*args, &block)
692
- @name.send("#{name}", *args, &block)
693
- end
694
- } unless When::Parts::MethodCash.escape(name)
695
- @name.send(name, *args, &block)
696
- end
697
- end
698
- end
699
-
700
- #
701
- # EX::Extent を提供する
702
- #
703
- module EX
704
-
705
- # 参照系の時間的および空間的な使用範囲を記述する
706
- #
707
- # 本ライブラリでは、時間的使用範囲を記述ためにのみ使用している
708
- #
709
- # see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#ExtentType gml schema}
710
- #
711
- class Extent
712
-
713
- # time periods
714
- #
715
- # 時間的使用範囲の上限と下限を示す
716
- #
717
- # @return [When::TM::Period]
718
- #
719
- attr_reader :temporal_extent
720
- alias :temporalExtent :temporal_extent
721
-
722
- # オブジェクトの生成
723
- #
724
- # @param [When::TM::Period] extent
725
- #
726
- def initialize(extent)
727
- @temporal_extent = extent
728
- end
729
-
730
- # その他のメソッド
731
- #
732
- # @note When::EX::Extent で定義されていないメソッドは
733
- # 処理を @temporal_extent (type: When::TM::Period) に委譲する
734
- #
735
- def method_missing(name, *args, &block)
736
- self.class.module_eval %Q{
737
- def #{name}(*args, &block)
738
- list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
739
- @temporal_extent.send("#{name}", *list, &block)
740
- end
741
- } unless When::Parts::MethodCash.escape(name)
742
- list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
743
- @temporal_extent.send(name, *list, &block)
744
- end
745
- end
746
- end
747
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-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
+ 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
+ # @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
30
+ # @option options [Integer] :ordinal_date_digits ISO8601拡大表記の年内通日の桁数(省略時 3桁)
31
+ #
32
+ # @return [Array] format, date, time, clock, era
33
+ #
34
+ # format (Symbol, nil)
35
+ # nil 通常形式
36
+ # :century 世紀指定形式 ('CC', '+CCCC', '-CCCC')
37
+ # :day 年間通算日形式 ('YYDDD'など)
38
+ # :week 暦週形式 ('YYWNN'など)
39
+ #
40
+ # date (Array<Numeric>) 日付部分
41
+ #
42
+ # time (Array<Numeric>) 時刻部分
43
+ #
44
+ # clock (String) 時間帯
45
+ #
46
+ # era (String, Array<String, Integer>) 年号(Integerは0年に対応する通年)
47
+ #
48
+ def _to_array(date_time, options={})
49
+ raise TypeError, "Argument is not ISO 8601 String" unless date_time.kind_of?(String)
50
+ if options[:abbr].kind_of?(When::TimeValue)
51
+ options[:abbr] = ((options[:frame]||When::Gregorian) ^ options[:abbr]).cal_date
52
+ end
53
+ date_time = date_time.gsub(/_([\d])/, '\1')
54
+ begin
55
+ return _to_array_basic(date_time, options)
56
+ rescue ArgumentError
57
+ return _to_array_extended(date_time, options)
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ # ISO 8601 基本形式の表現を分解して配列化する
64
+ def _to_array_basic(date_time, options={})
65
+
66
+ case date_time
67
+ # basic date & time format (ISO 8601)
68
+ when /\A([-+W\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?\z/
69
+ d, t, time, clock = $~[1..4]
70
+ format, date = Date._to_array_basic_ISO8601(d, options)
71
+
72
+ # basic date & time format (JIS X0301)
73
+ when /\A([.\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?\z/
74
+ raise ArgumentError, "Wrong date format" unless options[:era_name]
75
+ d, t, time, clock = $~[1..4]
76
+ format, date = Date._to_array_basic_X0301(d, options)
77
+ era = options[:era_name]
78
+
79
+ # basic time format (ISO 8601)
80
+ when /\A(T(-{0,2}[.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?\z/
81
+ t, time, clock = $~[1..3]
82
+
83
+ # not supported
84
+ else
85
+ raise ArgumentError, "Wrong date format: #{date_time}"
86
+ end
87
+
88
+ return [format, date, Time._to_array_basic(time, t, options),
89
+ Time._to_string_clock(clock), era]
90
+ end
91
+
92
+ # ISO 8601 拡張形式の表現を分解して配列化する
93
+ def _to_array_extended(date_time, options={})
94
+
95
+ case date_time
96
+ # extended date & time format (ISO 8601)
97
+ when /\A([-+*&%@!>=<?\dW.\(\)]+)(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?\z/
98
+ d, t, time, clock = $~[1..4]
99
+ if d =~ /[\(\)]/
100
+ d = When::CalendarTypes::Yerm.parse(d, options[:abbr])
101
+ options[:frame] ||= 'Yerm'
102
+ end
103
+ format, date = Date._to_array_extended_ISO8601(d, options)
104
+
105
+ # extended date & time format (JIS X0301)
106
+ when /\A((.+::)?(\[[^\]]+\]|[^-+\d]+))([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?\z/
107
+ era, parent, child, d, t, time, clock = $~[1..7]
108
+ format, date, era = Date._to_array_extended_X0301(d, era, options)
109
+ era ||= options[:era_name] if (d =~ /\./)
110
+
111
+ # extended time format (ISO 8601)
112
+ when /\A(T(-{0,2}[:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?\z/
113
+ t, time, clock = $~[1..3]
114
+
115
+ # not supported
116
+ else
117
+ raise ArgumentError, "Wrong date format: #{date_time}"
118
+ end
119
+
120
+ return [format, date, Time._to_array_extended(time, t, options),
121
+ Time._to_string_clock(clock), era]
122
+ end
123
+ end
124
+ end
125
+
126
+ #
127
+ # ISO 8601 Date Representation
128
+ #
129
+ # see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date]
130
+ #
131
+ class Date < DateTime
132
+
133
+ # @private
134
+ Extra_Year_Digits = Hash.new {|hash, key|
135
+ ex = (key || 1).to_i
136
+ hash[key] =
137
+ if ex > 0
138
+ [
139
+ /\A(\d{2})\z/,
140
+ /\A([-+]\d{#{4+ex}})(\d{2})(\d{2})\z/,
141
+ /\A([-+]\d{#{4+ex}})-(\d{2})\z/,
142
+ /\A([-+]\d{#{4+ex}})\z/,
143
+ /\A([-+]\d{#{4+ex}})W(\d{2})(\d{1})?\z/,
144
+ /\A([+]\d{#{2+ex}})\z/,
145
+ /\A([-]\d{#{2+ex}})\z/,
146
+ /\A([-+]\d{#{4+ex}})(\d{3})\z/
147
+ ]
148
+ elsif ex == 0
149
+ [/\A(\d{2})\z/] + [/\A(\d{4})\z/] * 6
150
+ else
151
+ [/\A(\d{4})\z/] * 7
152
+ end
153
+ }
154
+
155
+ # @private
156
+ Ordinal_Date_Digits = Hash.new {|hash, key|
157
+ hash[key] = /\A(\d{#{(key || 3).to_i}})\z/
158
+ }
159
+
160
+ class << self
161
+ # ISO 8601 基本形式の表現を分解して配列化する
162
+ def _to_array_basic_ISO8601(date, options={})
163
+ by, bm, bd = options[:abbr]
164
+ extra_reg = Extra_Year_Digits[options[:extra_year_digits]]
165
+ case date
166
+ when nil ; return nil
167
+ when /\A(\d{4})(\d{2})(\d{2})\z/ ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.1
168
+ when /\A(\d{4})-(\d{2})\z/ ; return nil, [$1.to_i, $2.to_i] # 5.2.1.2
169
+ when /\A(\d{4})\z/ ; return nil, [$1.to_i] # 5.2.1.2
170
+ when extra_reg[0] ; return :century,[$1.to_i * 100] # 5.2.1.2
171
+ when /\A(\d{4})(\d{3})\z/ ; return :day, [$1.to_i, $2.to_i] # 5.2.2.1
172
+ when /\A(\d{4})W(\d{2})(\d{1})?\z/ ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.1-2
173
+ when extra_reg[1] ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.4 a)
174
+ when extra_reg[2] ; return nil, [$1.to_i, $2.to_i] # 5.2.1.4 b)
175
+ when extra_reg[3] ; return nil, [$1.to_i] # 5.2.1.4 c)
176
+ when extra_reg[4] ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.4 a-b)
177
+ when extra_reg[5] ; return :century,[$1.to_i * 100] # 5.2.1.4 d)
178
+ when extra_reg[6] ; return :century,[$1.to_i * 100] unless by # 5.2.1.4 d)
179
+ when extra_reg[7] ; return :day, [$1.to_i, $2.to_i] # 5.2.2.3 a)
180
+ else ; raise ArgumentError, "Wrong date format" unless by
181
+ end
182
+
183
+ by = by.to_i
184
+ case date
185
+ when /\A(\d{2})(\d{2})(\d{2})\z/ ; return nil, [_century($1,by), $2.to_i, $3.to_i] # 5.2.1.3 a)
186
+ when /\A-(\d{2})(\d{2})?\z/ ; return nil, [_century($1,by), _int($2)] # 5.2.1.3 b-c)
187
+ when /\A--(\d{2})(\d{2})?\z/ ; return nil, [by, $1.to_i, _int($2)] # 5.2.1.3 d-e)
188
+ when /\A(\d{2})(\d{3})\z/ ; return :day, [_century($1,by), $2.to_i] # 5.2.2.2 a)
189
+ when /\A-(\d{3})\z/ ; return :day, [by, $1.to_i] # 5.2.2.2 b)
190
+ when /\A(\d{2})W(\d{2})(\d{1})?\z/ ; return :week, [_century($1,by), $2.to_i, _int($3)] # 5.2.3.3 a-b)
191
+ when /\A-(\d{1})W(\d{2})(\d{1})?\z/ ; return :week, [_decade($1,by), $2.to_i, _int($3)] # 5.2.3.3 c-d)
192
+ when /\A-W(\d{2})(\d{1})?\z/ ; return :week, [by, $1.to_i, _int($2)] # 5.2.3.3 e-f)
193
+ else ; raise ArgumentError, "Wrong date format" unless bm
194
+ end
195
+
196
+ bm = bm.to_i
197
+ case date
198
+ when /\A---(\d{2})\z/ ; return nil, [by, bm, $1.to_i] # 5.2.1.3 f)
199
+ when /\A-W-(\d{1})\z/ ; return :week, [by, bm, $1.to_i] # 5.2.3.3 g)
200
+ when /\A----\z/ ; return nil, [by, bm, bd.to_i] if bd # extension
201
+ end
202
+
203
+ raise ArgumentError, "Wrong date format: #{date}"
204
+ end
205
+
206
+ # JIS X0301 基本形式の表現を分解して配列化する
207
+ def _to_array_basic_X0301(date, options={})
208
+ raise ArgumentError, "Wrong date format" unless date =~ /\./
209
+ date.scan(/\d+\./) do |part|
210
+ raise ArgumentError, "Wrong date format" unless part.length == 3
211
+ end
212
+ _to_array_basic_ISO8601(date.gsub(/\./, ''), {:abbr=>options[:abbr]||1})
213
+ end
214
+
215
+ # ISO 8601 拡張形式の表現を分解して配列化する
216
+ def _to_array_extended_ISO8601(date, options={})
217
+ return nil unless date
218
+ abbr = Array(options[:abbr]).dup
219
+ unless date =~ /\A([-+]?\d+#{abbr[0] ? '|-' : ''})([-*=.])?(.*)/
220
+ raise ArgumentError, "Wrong date format: #{date}"
221
+ end
222
+ date = $3
223
+ dd = [Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)]
224
+ while date =~ /\A(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])(.+)/
225
+ date = $3
226
+ dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
227
+ end
228
+ case date
229
+ when /\AW(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?(\d+)?([-*=?%@])?\z/
230
+ dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
231
+ dd << Coordinates::Pair._en_pair($3, $4)
232
+ return :week, dd
233
+ when Ordinal_Date_Digits[options[:ordinal_date_digits]]
234
+ dd << $1.to_i
235
+ return :day, dd
236
+ when /\A(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?\z/
237
+ dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
238
+ return nil, dd
239
+ when ''
240
+ return nil, dd
241
+ else
242
+ raise ArgumentError, "Wrong date format: #{date}"
243
+ end
244
+ end
245
+
246
+ # JIS X0301 拡張形式の表現を分解して配列化する
247
+ def _to_array_extended_X0301(date, era, options={})
248
+ if (date =~ /\A([-+\d]+)\(([-+\d]+)\)(.*)\z/)
249
+ year = $2
250
+ date = $1 + $3
251
+ end
252
+ format, date = _to_array_extended_ISO8601(date, options)
253
+ if (year)
254
+ yy = year.to_i
255
+ ee = date[0] * 1
256
+ era = [era, yy-ee, yy+ee]
257
+ end
258
+ return format, date, era
259
+ end
260
+
261
+ private
262
+
263
+ def _completion(digits, base)
264
+ case digits
265
+ when nil ; return nil
266
+ when /\A\d{5}/ ; raise ArgumentError, "Wrong date format: #{digits}"
267
+ else ; return digits.to_i unless base
268
+ end
269
+
270
+ base = base.to_i
271
+ case digits
272
+ when '-' ; return base
273
+ when /\A-?(\d{1})\z/ ; return _decade( $1, base)
274
+ when /\A-?(\d{2})\z/ ; return _century($1, base)
275
+ else ; return digits.to_i
276
+ end
277
+ end
278
+
279
+ def _century(year, base)
280
+ quotient, remainder = base.divmod(100)
281
+ year = year.to_i
282
+ quotient += 1 if year < remainder
283
+ return quotient * 100 + year
284
+ end
285
+
286
+ def _decade(year, base)
287
+ quotient, remainder = base.divmod(10)
288
+ year = year.to_i
289
+ quotient += 1 if year < remainder
290
+ return quotient * 10 + year
291
+ end
292
+
293
+ def _int(digits)
294
+ return digits ? digits.to_i : nil
295
+ end
296
+ end
297
+ end
298
+
299
+ #
300
+ # ISO 8601 Time Representation
301
+ #
302
+ # see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#time]
303
+ #
304
+ class Time < DateTime
305
+
306
+ class << self
307
+ # 基本形式の表現を分解して配列化する
308
+ def _to_array_basic(time, t, options={})
309
+ return nil unless t
310
+ return [0] unless time
311
+ time.sub!(/,/, '.')
312
+ unless (time =~ /\A(\d{2}(?:\.\d+)?|-)(\d{2}(?:\.\d+)?|-)?(\d{2}(\.\d+)?)?\z/)
313
+ raise ArgumentError, "Wrong time format: #{time}"
314
+ end
315
+ indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
316
+ abbr = Array(options[:abbr]).dup
317
+ abbr[0..indices.length] = []
318
+ return [0, Coordinates::Pair._en_number($1=='-' ? abbr[0] : $1, nil),
319
+ Coordinates::Pair._en_number($2=='-' ? abbr[1] : $2, nil),
320
+ Coordinates::Pair._en_number($3, nil)]
321
+ end
322
+
323
+ # 拡張形式の表現を分解して配列化する
324
+ def _to_array_extended(time, t, options={})
325
+ return nil unless t
326
+ return [0] unless time
327
+ indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
328
+ abbr = Array(options[:abbr]).dup
329
+ abbr[0..indices.length] = []
330
+ time.sub!(/,/, '.')
331
+ if time =~ /\A([:*=])(.+)/
332
+ time = $2
333
+ tt = [Coordinates::Pair._en_pair(0, $1)]
334
+ else
335
+ tt = [0]
336
+ end
337
+ while time =~ /\A(\d{2}(?:\.\d+)?|-)([:*=])(.+)/
338
+ time = $3
339
+ tt << Coordinates::Pair._en_pair($1=='-' ? abbr.shift : $1, $2)
340
+ end
341
+ case time
342
+ when /\A(\d{2}(\.\d+)?)\z/
343
+ tt << Coordinates::Pair._en_number($1, nil)
344
+ when ''
345
+ else
346
+ raise ArgumentError, "Wrong time format: #{time}"
347
+ end
348
+ return tt
349
+ end
350
+
351
+ # 時間帯の表現を正規化する
352
+ def _to_string_clock(clock)
353
+ return nil unless clock
354
+ return clock if (clock =~ /\A[A-Z]+(\?.+)?\z/)
355
+ raise ArgumentError, "Wrong clock format: #{clock}" unless clock =~ /\A([-+])(\d{2})(?::?(\d{2}))?(?::?(\d{2}))?\z/
356
+ sgn, h, m, s = $~[1..4]
357
+ zone = sgn + h + ':' + (m||'00')
358
+ zone += s if s
359
+ return zone
360
+ end
361
+ end
362
+ end
363
+
364
+ # コード
365
+ #
366
+ # 当該コードを定義している辞書, シソーラスまたは機関への参照を
367
+ # オプショナルな codeSpace 属性に保持することができる文字列
368
+ #
369
+ # see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#CodeType gml schema}
370
+ #
371
+ class Code < String
372
+
373
+ # an optional codeSpace
374
+ #
375
+ # @return [String] anyURI (Optional)
376
+ attr_accessor :code_space
377
+ alias :codeSpace :code_space
378
+ private :code_space=
379
+
380
+ # オブジェクトの生成
381
+ #
382
+ # @param [String] code Text token
383
+ # @param [String] namespace code を定義している authority の URI
384
+ #
385
+ def initialize(code, namespace=nil)
386
+ @code_space = namespace
387
+ self[0..-1] = code
388
+ end
389
+ end
390
+
391
+ #
392
+ # == 多言語対応文字列
393
+ #
394
+ # 本ライブラリで用いる諸々の用語を多言語対応で曖昧性なく管理するため
395
+ # Code subclass として定義する
396
+ #
397
+ # == 内部変数
398
+ # === self[ 0..-1 ] : String
399
+ # インスタンスを代表する文字列
400
+ # 通常の String として振舞う場合は、この文字列として振舞う
401
+ #
402
+ # === @locale : Hash
403
+ # インスタンスがさす言葉の諸言語での表現を文字列として保持する
404
+ # locale指定('lang_country.encoding') => その locale での文字列
405
+ # locale指定の要素に省略がある場合、残った共通の要素によって文字列を特定する
406
+ # Ex. @locale = {'en'=>'March', 'ja'=>'三月'} ならば、locale
407
+ # 'en_US', 'en_GB' のいずれでもlocale での文字列は 'March'
408
+ #
409
+ # === @namespace : Hash
410
+ # インスタンスがさす言葉の意味を特定するための authority URI を保持する
411
+ # locale指定('lang_country.encoding') => その locale での authority の URI
412
+ # locale指定の要素に省略がある場合、残った共通の要素によってURIを特定する
413
+ # Ex. @locale = {'en'=>'en:March', 'ja'=>'ja:3%E6%9C%88'} ならば、locale が
414
+ # 'en_US', 'en_GB' のいずれでもlocale での authority の URIは 'en:March'
415
+ # 当該用語が標準管理機関で管理されていない場合、wikipedia の当該項目の URI を用いる
416
+ #
417
+ # === @code_space : String
418
+ # 代表的な authority URI
419
+ # @namespace[''] である
420
+ #
421
+ # see {When::Locale}, {When::Parts::Resource}
422
+ #
423
+ class M17n < Code
424
+ include When::Locale
425
+ include Parts::Resource
426
+
427
+ # @private
428
+ HashProperty = [:label, :names, :link, :access_key, :code_space]
429
+
430
+ # @private
431
+ LabelTypes = {
432
+ 'Residue' => ['Coordinates', '%s', '_co:%s%s' ],
433
+ 'Week' => ['CalendarNote', '%sWeek', '_n:%sWeek%s' ],
434
+ 'Notes' => ['CalendarNote', '%s', '_n:%s/Notes%s'],
435
+ nil => ['BasicTypes::M17n', '%s', '_m:%s%s' ]
436
+ }
437
+
438
+ class << self
439
+
440
+ #
441
+ # resource の取得
442
+ #
443
+ # @param [When::Parts::Resource, String] source
444
+ #
445
+ # @return [When::Parts::Resource]
446
+ #
447
+ # @private
448
+ def _label(source)
449
+ case source
450
+ when Parts::Resource, nil ; return source
451
+ when Parts::Resource::IRIHeader ; return Parts::Resource._instance(source)
452
+ end
453
+ iri = Parts::Resource._abbreviation_to_iri(source, LabelTypes)
454
+ iri ? Parts::Resource._instance(iri) : nil
455
+ end
456
+
457
+ #
458
+ # label の取得
459
+ #
460
+ # @param [When::Parts::Resource, String] source
461
+ #
462
+ # @return [When::BasicTypes::M17n, String]
463
+ #
464
+ def label(source)
465
+ resource = _label(source)
466
+ case resource
467
+ when nil ; return source
468
+ when M17n ; return resource
469
+ when Parts::Resource ; return resource.label
470
+ else ; return resource
471
+ end
472
+ end
473
+
474
+ #
475
+ # label の Array の取得
476
+ #
477
+ # @param [When::Parts::Resource, Array] source
478
+ #
479
+ # @return [Array]
480
+ #
481
+ def labels(source)
482
+ array =
483
+ if source.kind_of?(Array)
484
+ source
485
+ else
486
+ resource = _label(source)
487
+ return nil unless resource
488
+ resource.child
489
+ end
490
+ case array[0]
491
+ when M17n ; return array
492
+ when Parts::Resource ; return array.map {|v| v.label}
493
+ else ; return array
494
+ end
495
+ end
496
+ end
497
+
498
+ #
499
+ # 代表名
500
+ #
501
+ # @return [String]
502
+ #
503
+ attr_reader :label
504
+
505
+ #
506
+ # 名前が意味するもの自体のオブジェクト
507
+ #
508
+ # @return [When::BasicTypes::Object]
509
+ #
510
+ alias :what :parent
511
+
512
+ #
513
+ # When::BasicTypes::M17n に変換する - 何もしないで自身を返す
514
+ #
515
+ # @return [When::BasicTypes::M17n]
516
+ #
517
+ def to_m17n
518
+ self
519
+ end
520
+
521
+ #
522
+ # 内部エンコーディング文字列化
523
+ #
524
+ def to_internal_encoding
525
+ _copy({:label => When::EncodingConversion.to_internal_encoding(to_s),
526
+ :names => Hash[*(names.keys.map {|name| [name, When::EncodingConversion.to_internal_encoding(names[name])]}).flatten],
527
+ :link => link,
528
+ :access_key => access_key,
529
+ :code_space => code_space
530
+ })
531
+ end
532
+
533
+ #
534
+ # 外部エンコーディング文字列化
535
+ #
536
+ def to_external_encoding
537
+ _copy({:label => When::EncodingConversion.to_external_encoding(to_s),
538
+ :names => Hash[*(names.keys.map {|name| [name, When::EncodingConversion.to_external_encoding(names[name])]}).flatten],
539
+ :link => link,
540
+ :access_key => access_key,
541
+ :code_space => code_space
542
+ })
543
+ end
544
+
545
+ # オブジェクトの生成
546
+ #
547
+ # @overload initialize(names, namespace={}, locale=[])
548
+ # @param [Array<String>] names
549
+ #
550
+ # [String] '*locale:label=prefix:link'
551
+ # * - 存在すれば、label をインスタンスを代表する文字列とする
552
+ # locale - label に対応する locale指定(なければ、locale 引数の指定を用いる)
553
+ # label - locale 指定に対応する label
554
+ # prefix:link - その locale での authority の URI
555
+ # prefix: - namespace 引数の指定により URI に展開する
556
+ # link - なければ labelをURI encodeして用いる
557
+ #
558
+ # @param [Hash] namespace { prefix=>uri }
559
+ #
560
+ # lables, locale 引数の prefix の展開に用いる
561
+ #
562
+ # @param [Array<String>] locale
563
+ #
564
+ # [String] '*locale=prefix:link'
565
+ # * - 存在すれば、label をインスタンスを代表する文字列とする
566
+ # locale - locale指定
567
+ # prefix:link - authority の URI
568
+ # prefix: - namespace 引数の指定により URI に展開する
569
+ #
570
+ # @example
571
+ # M17n.new(['3月', 'fr:Mars=http://fr.wikipedia.org/wiki/Mars_(mois)', 'March'],
572
+ # {'en_wikipedia'=>'http://en.wikipedia.org/wiki/',
573
+ # 'ja_wikipedia'=>'http://ja.wikipedia.org/wiki/'},
574
+ # ['=ja_wikipedia:', '*en=en_wikipedia:']) を行うと、生成された M17n では、
575
+ # @names = {'' =>'3月', 'fr'=>'Mars', 'en'=>'March'}
576
+ # @namespace = {'' =>'http://ja.wikipedia.org/wiki/3%E6%9C%88',
577
+ # 'fr'=>'http://fr.wikipedia.org/wiki/Mars_(mois)',
578
+ # 'en'=>'http://en.wikipedia.org/wiki/March'}
579
+ # となり、通常の String として振舞う場合は 'March' として振舞う
580
+ #
581
+ def initialize(*args)
582
+ rest, options = _attributes(args)
583
+ _sequence
584
+
585
+ return _pool[@label.to_s] ?
586
+ _copy_all(_pool[@label.to_s]) : # 階層になった Resource の代表ラベルのための生成
587
+ _copy(options) if @label # M17n#to_h の出力と書式互換の入力による生成
588
+
589
+ case rest[0]
590
+ when When::Parts::Resource::ContentLine
591
+ content, namespace = rest
592
+ namespace ||= {}
593
+ names = []
594
+ locale = []
595
+ begin
596
+ loc = content.attribute['language'].object
597
+ locale << [nil, loc, namespace[loc]]
598
+ name = content.object
599
+ ref = content.attribute['reference'] || content.attribute['url']
600
+ name += '=' + (/\ANUL\z/i =~ ref.object ? '' : ref.object) if ref
601
+ names << name
602
+ end while (content = content.same_altid)
603
+ @names ||= names.reverse
604
+ @namespace ||= namespace if namespace.kind_of?(Hash)
605
+ @locale ||= locale.reverse
606
+ when nil ;
607
+ else
608
+ names, namespace, locale = rest
609
+ @names = names if names
610
+ @namespace ||= When::Locale._namespace(namespace) if namespace
611
+ @locale ||= When::Locale._locale(locale) if locale
612
+ end
613
+ @namespace ||= {}
614
+ @locale ||= []
615
+
616
+ @code_space = @namespace['']
617
+ self[0..-1] = @label = _names(@names, @namespace, @locale)
618
+ end
619
+ end
620
+
621
+ #
622
+ # Abstract class for instance having permanent life with IRI
623
+ #
624
+ # see {When::Parts::Resource}
625
+ # see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#ObjectType gml schema}
626
+ #
627
+ class Object
628
+
629
+ include Parts::Resource
630
+
631
+ # 名前
632
+ #
633
+ # @return [String, When::BasicTypes::M17n]
634
+ #
635
+ attr_reader :label
636
+
637
+ private
638
+
639
+ # オブジェクトの初期化
640
+ def initialize(*args)
641
+ @_lock_ = Mutex.new if When.multi_thread
642
+ _normalize(*_attributes(args))
643
+ _sequence
644
+ end
645
+ end
646
+ end
647
+
648
+ #
649
+ # RS::Identifier を提供する
650
+ #
651
+ module RS
652
+
653
+ # 参照系の識別子
654
+ #
655
+ # see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#IdentifierType gml schema}
656
+ #
657
+ class Identifier
658
+
659
+ # The code or name for this Identifier
660
+ #
661
+ # @return [When::BasicTypes::Code]
662
+ #
663
+ attr_reader :name
664
+
665
+ # Identifier of the version of the associated codeSpace or code
666
+ #
667
+ # @return [Array<String>]
668
+ #
669
+ attr_reader :version
670
+
671
+ # Remarks about this code or alias
672
+ #
673
+ # @return [Array<String>] String は URI/IRI文字列の場合あり
674
+ #
675
+ attr_reader :remarks
676
+
677
+ # オブジェクトの生成
678
+ #
679
+ # @param [When::BasicTypes::Code] name
680
+ # @param [Array<String>] version
681
+ # @param [Array<String>] remarks String は URI/IRI文字列の場合あり
682
+ #
683
+ def initialize(name, version=nil, remarks=nil)
684
+ @name = name
685
+ @version = version
686
+ @remarks = remarks
687
+ end
688
+
689
+ # その他のメソッド
690
+ #
691
+ # @note When::RS::Identifier で定義されていないメソッドは
692
+ # 処理を @name (type: When::BasicTypes::Code) に委譲する
693
+ #
694
+ def method_missing(name, *args, &block)
695
+ self.class.module_eval %Q{
696
+ def #{name}(*args, &block)
697
+ @name.send("#{name}", *args, &block)
698
+ end
699
+ } unless When::Parts::MethodCash.escape(name)
700
+ @name.send(name, *args, &block)
701
+ end
702
+ end
703
+ end
704
+
705
+ #
706
+ # EX::Extent を提供する
707
+ #
708
+ module EX
709
+
710
+ # 参照系の時間的および空間的な使用範囲を記述する
711
+ #
712
+ # 本ライブラリでは、時間的使用範囲を記述ためにのみ使用している
713
+ #
714
+ # see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#ExtentType gml schema}
715
+ #
716
+ class Extent
717
+
718
+ # time periods
719
+ #
720
+ # 時間的使用範囲の上限と下限を示す
721
+ #
722
+ # @return [When::TM::Period]
723
+ #
724
+ attr_reader :temporal_extent
725
+ alias :temporalExtent :temporal_extent
726
+
727
+ # オブジェクトの生成
728
+ #
729
+ # @param [When::TM::Period] extent
730
+ #
731
+ def initialize(extent)
732
+ @temporal_extent = extent
733
+ end
734
+
735
+ # その他のメソッド
736
+ #
737
+ # @note When::EX::Extent で定義されていないメソッドは
738
+ # 処理を @temporal_extent (type: When::TM::Period) に委譲する
739
+ #
740
+ def method_missing(name, *args, &block)
741
+ self.class.module_eval %Q{
742
+ def #{name}(*args, &block)
743
+ list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
744
+ @temporal_extent.send("#{name}", *list, &block)
745
+ end
746
+ } unless When::Parts::MethodCash.escape(name)
747
+ list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
748
+ @temporal_extent.send(name, *list, &block)
749
+ end
750
+ end
751
+ end
752
+ end