when_exe 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -36,7 +36,7 @@ module When::Coordinates
36
36
  return src.to_r * Spatial::DEGREE if (src =~ /E[-+]/ || src !~ MATCH[dir])
37
37
  sign = ($1 == dir[1..1]) ? -1 : +1
38
38
  value = src.gsub(MATCH[dir], '').strip
39
- if ((value + "00000") =~ /^(\d+)\.(\d{2})(\d{2})(\d+)$/)
39
+ if ((value + "00000") =~ /\A(\d+)\.(\d{2})(\d{2})(\d+)\z/)
40
40
  deg, min, sec, frac = $~[1..4]
41
41
  sec += "." + frac
42
42
  else
@@ -119,15 +119,15 @@ module When::Coordinates
119
119
  else ; return nil
120
120
  end
121
121
 
122
- match = day[/^...|^.{1,2}$/]
122
+ match = day[/\A...|^.{1,2}\z/]
123
123
  if match
124
124
  week.size.times do |i|
125
- return week[i] if week[i].label.=~(/^#{match}/i)
125
+ return week[i] if week[i].label.=~(/\A#{match}/i)
126
126
  end
127
127
  end
128
128
 
129
129
  ObjectSpace.each_object(self) do |object|
130
- return object if object.registered? && object.label.=~(/^#{day}$/)
130
+ return object if object.registered? && object.label.=~(/\A#{day}\z/)
131
131
  end
132
132
 
133
133
  return nil
@@ -849,9 +849,9 @@ module When::Coordinates
849
849
  # @return [Array<When::Coordinates::Pair>]
850
850
  #
851
851
  def _en_pair_array(source)
852
- source = $1 if (source=~/^\s*\[?(.+?)\]?\s*$/)
852
+ source = $1 if source=~/\A\s*\[?(.+?)\]?\s*\z/
853
853
  source.split(/,/).map {|v|
854
- v =~ /^\s*(.+?)([^\d\s])?\s*$/
854
+ v =~ /\A\s*(.+?)([^\d\s])?\s*\z/
855
855
  _en_pair($1, $2)
856
856
  }
857
857
  end
@@ -864,7 +864,7 @@ module When::Coordinates
864
864
  # @return [Array<When::Coordinates::Pair>]
865
865
  #
866
866
  def _en_pair_date_time(source)
867
- source = $1 if source =~ /^\s*\[(.+)\]\s*$/
867
+ source = $1 if source =~ /\A\s*\[(.+)\]\s*\z/
868
868
  trunk, branch, *rest = source.strip.split(/([^\d])/)
869
869
  if trunk == ''
870
870
  sign = branch
@@ -954,7 +954,7 @@ module When::Coordinates
954
954
  #
955
955
  # branch の更新
956
956
  #
957
- # @param [Numeric] branch新しい branch
957
+ # @param [Numeric] branch 新しい branch
958
958
  #
959
959
  # @return [When::Coordinates::Pair] 更新結果
960
960
  #
@@ -1252,7 +1252,7 @@ module When::Coordinates
1252
1252
 
1253
1253
  # デフォルトの空間位置
1254
1254
  #
1255
- # @param [When::Coordinates::Spatial, String] default_location デフォルトの空間位置
1255
+ # @param [When::Coordinates::Spatial, String] local デフォルトの空間位置
1256
1256
  #
1257
1257
  # @return [When::Coordinates::Spatial, String]
1258
1258
  #
@@ -1460,7 +1460,7 @@ module When::Coordinates
1460
1460
  # 時間帯による指定
1461
1461
  @tz = When::Parts::Timezone.tz_info[@tz] if @tz.kind_of?(String)
1462
1462
  if @tz
1463
- @label ||= @tz.label
1463
+ @label ||= When.m17n(@tz.identifier)
1464
1464
  @long ||= @tz.longitude
1465
1465
  @lat ||= @tz.latitude
1466
1466
  end
@@ -1563,17 +1563,18 @@ module When::Coordinates
1563
1563
  def _normalize_spatial
1564
1564
 
1565
1565
  # Location
1566
- if ((@location||@long||@lat||@alt).kind_of?(String))
1566
+ if (@location||@long||@lat||@alt).kind_of?(String)
1567
1567
  @location ||= "_l:long=#{@long||0}&lat=#{@lat||0}&alt=#{@alt||0}"
1568
1568
  @location = When.Resource(@location)
1569
1569
  end
1570
+ @location ||= @tz_prop.location if @tz_prop
1570
1571
 
1571
1572
  # Border
1572
- if (@border.kind_of?(String))
1573
+ if @border.kind_of?(String)
1573
1574
  @border = When.Calendar(
1574
1575
  case @border
1575
1576
  when /\([-\d]+?\)/ ; "_c:MultiBorder?borders=#{@border}"
1576
- when /^[^A-Z_]/i ; "_c:Border?border=#{@border}"
1577
+ when /\A[^A-Z_]/i ; "_c:Border?border=#{@border}"
1577
1578
  else ; @border
1578
1579
  end)
1579
1580
  end
@@ -1786,7 +1787,7 @@ module When::Coordinates
1786
1787
 
1787
1788
  # 下の位の既定値
1788
1789
  unless date[1] || !@border
1789
- date[0...@base.length] = @border.border([date[0]], self)
1790
+ date[0...@base.length] = @border.border([@border._date_adjust(date[0])], self)
1790
1791
  end
1791
1792
 
1792
1793
  # 要素数固定部分の正規化(上 -> 下) - ISO8601 の 小数要素(ex. "T23:20.8")の処理
@@ -1947,7 +1948,7 @@ module When::Coordinates
1947
1948
  @label = When::BasicTypes::M17n.label(@label)
1948
1949
 
1949
1950
  # Origin and Upper Digits
1950
- @origin_of_MSC ||= - +@border.behavior if @border
1951
+ @origin_of_MSC ||= - @border.behavior * 1 if @border
1951
1952
  @origin_of_MSC = Pair._en_number(@origin_of_MSC)
1952
1953
  @origin_of_LSC = Pair._en_number(@origin_of_LSC)
1953
1954
  @index_of_MSC = Pair._en_number(@index_of_MSC)
@@ -1,110 +1,114 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2013 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
- =end
7
-
8
- #
9
- # When::TM::Duration のための標準クラスの拡張
10
- #
11
-
12
- #
13
- # When::TM::Duration
14
- #
15
- # @private
16
- class When::TM::Duration
17
- def rational_duration
18
- unless @rational_duration
19
- sec = duration / When::TM::Duration::SECOND
20
- mod = sec % When::TM::Duration::DAY.to_i
21
- if mod == 0 || mod != mod.to_i
22
- @rational_duration = @duration / When::TM::Duration::DAY
23
- else
24
- @rational_duration = Rational(sec.to_i, 86400)
25
- end
26
- end
27
-
28
- @rational_duration
29
- end
30
- end
31
-
32
- #
33
- # Extensions to Date class
34
- #
35
- # @private
36
- class Date
37
-
38
- alias :_plus_ :+
39
- def +(other)
40
- other.kind_of?(When::TM::Duration) ? self + other.rational_duration : self._plus_(other)
41
- end
42
-
43
-
44
- alias :_minus_ :-
45
- def -(other)
46
- other.kind_of?(When::TM::Duration) ? self - other.rational_duration : self._minus_(other)
47
- end
48
- end
49
-
50
- #
51
- # Extensions to Time class
52
- #
53
- # @private
54
- class Time
55
-
56
- alias :_plus_ :+
57
- def +(other)
58
- other.kind_of?(When::TM::Duration) ? self + other.to_f : self._plus_(other)
59
- end
60
-
61
-
62
- alias :_minus_ :-
63
- def -(other)
64
- other.kind_of?(When::TM::Duration) ? self - other.to_f : self._minus_(other)
65
- end
66
- end
67
-
68
- #
69
- # Extensions to Numeric class
70
- #
71
- class Numeric
72
-
73
- #
74
- # メソッド名に相当する単位で表した When::TM::Duration
75
- # @method unit_duration
76
- # @return [When::TM::Duration]
77
- # @note unit は second, minute, hour, day, week または
78
- # seconds, minutes, hours, days, weeks に読み替える
79
- # @note core/duration
80
-
81
- # @private
82
- When::TM::Duration::Unit.keys.each do |key|
83
-
84
- module_eval %Q{
85
- # for When::TM::Duration
86
- def #{key}_duration
87
- When::TM::Duration.new(self * When::TM::Duration::Unit['#{key}'])
88
- end
89
- alias :#{key}s_duration :#{key}_duration
90
- }
91
- end
92
- end
93
-
94
- #
95
- # Extensions to Array class
96
- #
97
- class Array
98
-
99
- #
100
- # self を Array<日, 時, 分, 秒> とみなして When::TM::Duration を生成
101
- #
102
- # @return [When::TM::Duration]
103
- #
104
- # @note core/duration
105
- #
106
- def duration
107
- When::TM::Duration.dhms(*self)
108
- end
109
- alias :to_duration :duration
110
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2013 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
+ =end
7
+
8
+ #
9
+ # When::TM::Duration のための標準クラスの拡張
10
+ #
11
+
12
+ #
13
+ # When::TM::Duration
14
+ #
15
+ # @private
16
+ class When::TM::Duration
17
+ def rational_duration
18
+ unless @rational_duration
19
+ sec = duration / When::TM::Duration::SECOND
20
+ mod = sec % When::TM::Duration::DAY.to_i
21
+ if mod == 0 || mod != mod.to_i
22
+ @rational_duration = @duration / When::TM::Duration::DAY
23
+ else
24
+ @rational_duration = Rational(sec.to_i, 86400)
25
+ end
26
+ end
27
+
28
+ @rational_duration
29
+ end
30
+ end
31
+
32
+ #
33
+ # Extensions to Date class
34
+ #
35
+ # @private
36
+ class Date
37
+
38
+ alias :_plus_ :+
39
+ def +(other)
40
+ other.kind_of?(When::TM::Duration) ? self + other.rational_duration : self._plus_(other)
41
+ end
42
+
43
+
44
+ alias :_minus_ :-
45
+ def -(other)
46
+ case other
47
+ when When::TM::Duration ; self - other.rational_duration
48
+ when When::TimeValue ; self._minus_(kind_of?(DateTime) ? other.to_date_time : other.to_date)
49
+ else ; self._minus_(other)
50
+ end
51
+ end
52
+ end
53
+
54
+ #
55
+ # Extensions to Time class
56
+ #
57
+ # @private
58
+ class Time
59
+
60
+ alias :_plus_ :+
61
+ def +(other)
62
+ other.kind_of?(When::TM::Duration) ? self + other.to_f : self._plus_(other)
63
+ end
64
+
65
+
66
+ alias :_minus_ :-
67
+ def -(other)
68
+ other.kind_of?(When::TM::Duration) ? self - other.to_f : self._minus_(other)
69
+ end
70
+ end
71
+
72
+ #
73
+ # Extensions to Numeric class
74
+ #
75
+ class Numeric
76
+
77
+ #
78
+ # メソッド名に相当する単位で表した When::TM::Duration
79
+ # @method unit_duration
80
+ # @return [When::TM::Duration]
81
+ # @note unit は second, minute, hour, day, week または
82
+ # seconds, minutes, hours, days, weeks に読み替える
83
+ # @note core/duration
84
+
85
+ # @private
86
+ When::TM::Duration::Unit.keys.each do |key|
87
+
88
+ module_eval %Q{
89
+ # for When::TM::Duration
90
+ def #{key}_duration
91
+ When::TM::Duration.new(self * When::TM::Duration::Unit['#{key}'])
92
+ end
93
+ alias :#{key}s_duration :#{key}_duration
94
+ }
95
+ end
96
+ end
97
+
98
+ #
99
+ # Extensions to Array class
100
+ #
101
+ class Array
102
+
103
+ #
104
+ # self を Array<日, 時, 分, 秒> とみなして When::TM::Duration を生成
105
+ #
106
+ # @return [When::TM::Duration]
107
+ #
108
+ # @note core/duration
109
+ #
110
+ def duration
111
+ When::TM::Duration.dhms(*self)
112
+ end
113
+ alias :to_duration :duration
114
+ end
@@ -1,504 +1,504 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2013-2014 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
- =end
7
-
8
- require 'date'
9
- require 'when_exe/core/duration'
10
-
11
- #
12
- # 標準クラスの拡張
13
- #
14
-
15
- #
16
- # Extensions to Time class
17
- #
18
- class Time
19
- #
20
- # 対応する When::TM::JulianDate を生成
21
- #
22
- # @param [Hash] options 以下の通り
23
- # @option options [When::TM::Clock] :clock
24
- # @option options [When::Parts::Timezone] :tz
25
- #
26
- # @return [When::TM::JulianDate]
27
- #
28
- # @note core/extension
29
- #
30
- def julian_date(options={})
31
- options[:clock] ||= Clock(self.utc_offset)
32
- When::TM::JulianDate.universal_time(self.to_f * When::TM::IntervalLength::SECOND, options)
33
- end
34
- alias :to_julian_date :julian_date
35
-
36
- #
37
- # 対応する When::TM::DateAndTime を生成
38
- #
39
- # @param [Hash] options 暦法や時法などの指定
40
- #
41
- # @see When::TM::TemporalPosition._instance
42
- #
43
- # @return [When::TM::DateAndTime]
44
- #
45
- # @note core/extension
46
- #
47
- def tm_pos(options={})
48
- When.at(self, options)
49
- end
50
- alias :to_tm_pos :tm_pos
51
- end
52
-
53
- #
54
- # Extensions to Date class
55
- #
56
- class Date
57
-
58
- if When::TM.const_defined?(:TemporalPosition)
59
-
60
- include When::TM::TemporalPosition::Conversion
61
-
62
- #
63
- # 対応する When::TM::CalDate or DateAndTime を生成
64
- #
65
- # @param [Hash] options 暦法や時法などの指定
66
- # see {When::TM::TemporalPosition._instance}
67
- #
68
- # @return [When::TM::CalDate, When::TM::DateAndTime]
69
- #
70
- # @note 暦法の指定がない場合、start メソッドの値によって
71
- # Julian / Gregorian / Civil 暦法を選択する
72
- #
73
- def tm_pos(options={})
74
- options[:frame] ||= When::CalendarTypes::Christian._default_start(self)
75
- super(options)
76
- end
77
- alias :to_tm_pos :tm_pos
78
- end
79
-
80
- alias :__method_missing :method_missing
81
-
82
- # その他のメソッド
83
- #
84
- # @note
85
- # self で定義されていないメソッドは
86
- # tm_pos で変換して処理する
87
- #
88
- def method_missing(name, *args, &block)
89
- return __method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
90
- self.class.module_eval %Q{
91
- def #{name}(*args, &block)
92
- result = tm_pos.send("#{name}", *args, &block)
93
- case result
94
- when When::TM::DateAndTime ; result.to_date_time
95
- when When::TM::CalDate ; result.to_date
96
- else ; result
97
- end
98
- end
99
- } unless When::Parts::MethodCash.escape(name)
100
- result = tm_pos.send(name, *args, &block)
101
- case result
102
- when When::TM::DateAndTime ; result.to_date_time
103
- when When::TM::CalDate ; result.to_date
104
- else ; result
105
- end
106
- end
107
- end
108
-
109
- #
110
- # Extensions to Numeric class
111
- #
112
- class Numeric
113
-
114
- include When::TM::TemporalPosition::Conversion if When::TM.const_defined?(:TemporalPosition)
115
-
116
- #
117
- # 曜日(剰余類)
118
- #
119
- # @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類)
120
- #
121
- # @note core/extension
122
- #
123
- def to_day_of_week
124
- When::Coordinates::Residue.day_of_week(self)
125
- end
126
- alias :day_of_week :to_day_of_week
127
-
128
- #
129
- # 月名
130
- #
131
- # self が 月番号の月名を返します
132
- #
133
- # @return [When::BasicTypes::M17n] 月名
134
- #
135
- # @note core/extension
136
- #
137
- def to_month_name
138
- When::BasicTypes::M17n.month_name(self)
139
- end
140
- alias :month_name :to_month_name
141
-
142
- # self を幹の要素と解釈してWhen::Coordinates::Pair を生成
143
- #
144
- # @see When::Coordinates::Pair._force_pair
145
- #
146
- # @return [When::Coordinates::Pair]
147
- #
148
- def to_pair(branch=nil)
149
- Coordinates::Pair._force_pair(self, branch)
150
- end
151
- alias :pair :to_pair
152
-
153
- #
154
- # self を秒数とみなして When::Parts::Timezone::Base を取得
155
- #
156
- # @return [When::Parts::Timezone::Base]
157
- #
158
- # @note core/extension
159
- #
160
- def clock
161
- When.Clock(self)
162
- end
163
- alias :to_clock :clock
164
-
165
- # メソッド名に相当する単位で表した When::TM::IntervalLength
166
- # @method unit_interval_length
167
- # @return [When::TM::IntervalLength]
168
- #
169
- # @note unit は second, minute, hour, day, week または
170
- # seconds, minutes, hours, days, weeks に読み替える
171
- #
172
- # @note core/extension
173
-
174
- # メソッド名に相当する単位で表した When::TM::PeriodDuration
175
- # @method unit_period_duration
176
- # @return [When::TM::PeriodDuration]
177
- #
178
- # @note unit は second, minute, hour, day, week, month, year または
179
- # seconds, minutes, hours, days, weeks, months, years に読み替える
180
- #
181
- # @note core/extension
182
-
183
- # @private
184
- When::TM::Duration::Unit.keys.each do |key|
185
-
186
- module_eval %Q{
187
- # for When::TM::IntervalLength
188
- def #{key}_interval_length
189
- When::TM::IntervalLength.new(self, '#{key}')
190
- end
191
- alias :#{key}s_interval_length :#{key}_interval_length
192
-
193
- # for When::TM::PeriodDuration
194
- def #{key}_period_duration
195
- When::TM::PeriodDuration.new(self, When::#{key.upcase})
196
- end
197
- alias :#{key}s_period_duration :#{key}_period_duration
198
- }
199
- end
200
- end
201
-
202
- #
203
- # Extensions to String class
204
- #
205
- class String
206
-
207
- include When::EncodingConversion
208
-
209
- #
210
- # self を When::BasicTypes::M17n に変換する
211
- #
212
- # @return [When::BasicTypes::M17n]
213
- #
214
- # @note core/extension
215
- #
216
- def to_m17n
217
- When::BasicTypes::M17n.new(self)
218
- end
219
-
220
- # 特定 locale に対応した文字列の取得
221
- #
222
- # @param [String] loc locale の指定
223
- #
224
- # @return [String] loc に対応した文字列
225
- #
226
- # @note core/extension
227
- #
228
- def translate(loc='')
229
- return encode($1) if loc =~ /\.(.+)$/
230
- return self
231
- end
232
- alias :/ :translate
233
-
234
- # 包摂リストに登録されている文字を包摂する
235
- #
236
- # @param [Hash] pattern 包摂ルール
237
- #
238
- # @return [String] 包摂結果
239
- #
240
- def ideographic_unification(pattern=When::Locale._unification)
241
- When::Locale.ideographic_unification(self, pattern)
242
- end
243
-
244
- #
245
- # self を IRI とみなして When::Parts::Resource を取得
246
- #
247
- # @param [String] namespace デフォルトの namespace
248
- #
249
- # @return [When::Parts::Resource]
250
- #
251
- # @note core/extension
252
- #
253
- def resource(namespace=nil)
254
- When::Parts::Resource._instance(self, namespace)
255
- end
256
- alias :to_resource :resource
257
-
258
- #
259
- # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::Calendar を取得
260
- #
261
- # @return [When::TM::Calendar]
262
- #
263
- # @note core/extension
264
- #
265
- def calendar
266
- When::Parts::Resource._instance(self, '_c:')
267
- end
268
- alias :to_calendar :calendar
269
-
270
- #
271
- # self を時間帯文字列とみなして When::Parts::Timezone::Base を取得
272
- #
273
- # @return [When::Parts::Timezone::Base]
274
- #
275
- # @note core/extension
276
- #
277
- def clock
278
- When.Clock(self)
279
- end
280
- alias :to_clock :clock
281
-
282
- #
283
- # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::CalendarNote を取得
284
- #
285
- # @return [When::TM::CalendarNote]
286
- #
287
- # @note core/extension
288
- #
289
- def calendar_note
290
- When::Parts::Resource._instance(self, '_n:')
291
- end
292
- alias :to_calendar_note :calendar_note
293
-
294
- #
295
- # self をプレフィクス '_e:' を省略した IRI とみなして When::TM::CalendarEra を取得
296
- #
297
- # @return [When::TM::CalendarEra]
298
- #
299
- # @note core/extension
300
- #
301
- def calendar_era
302
- When::Parts::Resource._instance(self, '_e:')
303
- end
304
- alias :to_calendar_era :calendar_era
305
-
306
- #
307
- # self をプレフィクス '_m:' を省略した IRI とみなして When::BasicTypes::M17n を取得
308
- #
309
- # @return [When::BasicTypes::M17n]
310
- #
311
- # @note core/extension
312
- #
313
- def m17n
314
- When::Parts::Resource._instance(self, '_m:')
315
- end
316
-
317
- # self を幹と枝の要素と解釈してWhen::Coordinates::Pair を生成
318
- #
319
- # @see When::Coordinates::Pair._force_pair
320
- #
321
- # @return [When::Coordinates::Pair]
322
- #
323
- def to_pair
324
- Coordinates::Pair._force_pair(self)
325
- end
326
- alias :pair :to_pair
327
-
328
- #
329
- # self を検索する暦年代とみなして登録された When::TM::CalendarEraを検索
330
- #
331
- # @overload calendar_era(options={}
332
- # @param [Hash] options
333
- # see alse {When.era}
334
- #
335
- # @return [Array<When::TM::CalendarEra>]
336
- #
337
- # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
338
- # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
339
- # 生成しつつ読み込んで検索する。
340
- #
341
- # @note core/extension
342
- #
343
- def era(*args)
344
- When::TM::CalendarEra._instance(*([self] + args))
345
- end
346
- alias :to_era :era
347
-
348
- #
349
- # self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成
350
- #
351
- # @param [Hash] options 暦法や時法などの指定
352
- #
353
- # @see When::TM::TemporalPosition._instance
354
- #
355
- # @return [When::TM::TemporalPosition]
356
- #
357
- # @note core/extension
358
- #
359
- def when?(options={})
360
- When.when?(self, options)
361
- end
362
- alias :tm_pos :when?
363
- alias :to_tm_pos :when?
364
-
365
- #
366
- # 曜日(剰余類)
367
- #
368
- # self の最初の3文字から決定した七曜(剰余類)を返します。
369
- # 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
370
- #
371
- # @return [When::Coordinates::Residue]
372
- # [ 月曜を 0 とする七曜(剰余類) ]
373
- # [ 名前の一致するその他の剰余類 ]
374
- #
375
- # @note core/extension
376
- #
377
- def to_residue
378
- When::Coordinates::Residue.to_residue(self)
379
- end
380
- alias :residue :to_residue
381
- alias :day_of_week :to_residue
382
-
383
- #
384
- # 月名
385
- #
386
- # self の最初の3文字から決定した月名を返します。
387
- # 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
388
- # (self が M17n なら name 自身をそのまま返します)
389
- #
390
- # @return [When::BasicTypes::M17n] 月名
391
- #
392
- # @note core/extension
393
- #
394
- def to_month_name
395
- When::BasicTypes::M17n.month_name(self)
396
- end
397
- alias :month_name :to_month_name
398
-
399
- #
400
- # self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成し“^”演算を実行
401
- #
402
- # @return [When::TM::TemporalPosition の “^”演算結果]
403
- #
404
- # @note core/extension
405
- #
406
- def ^(other)
407
- When::TM::TemporalPosition._instance(self, {}) ^ other
408
- end
409
- end
410
-
411
- #
412
- # Extensions to Regexp class
413
- #
414
- class Regexp
415
-
416
- include When::EncodingConversion
417
-
418
- #
419
- # self を検索する暦年代にマッチする正規表現とみなして登録された When::TM::CalendarEraを検索
420
- #
421
- # @overload calendar_era(options={}
422
- # @param [Hash] options
423
- # see also {When.era}
424
- #
425
- # @return [Array<When::TM::CalendarEra>]
426
- #
427
- # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
428
- # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
429
- # 生成しつつ読み込んで検索する。
430
- #
431
- # @note core/extension
432
- #
433
- def era(*args)
434
- When::TM::CalendarEra._instance(*([self] + args))
435
- end
436
- alias :to_era :era
437
-
438
- # 包摂リストに登録されている文字を包摂する
439
- #
440
- # @param [Hash] pattern 包摂ルール
441
- #
442
- # @return [Regexp] 包摂結果
443
- #
444
- def ideographic_unification(pattern=When::Locale._unification)
445
- When::Locale.ideographic_unification(self, pattern)
446
- end
447
- end
448
-
449
- #
450
- # Extensions to Array class
451
- #
452
- class Array
453
- #
454
- # self を暦要素の Array とみなして [When::TM::TemporalPosition] を生成
455
- #
456
- # @param [Hash] options 暦法や時法などの指定
457
- # @option options [Symbol] :invalid
458
- # [:raise 日時が存在しない場合例外発生 ]
459
- # [:check 日時が存在しない場合 nil を返す ]
460
- # [その他/nil 日時が存在することを確認しない(デフォルト)]
461
- # see also {When::TM::TemporalPosition._instance}
462
- #
463
- # @return [When::TM::TemporalPosition]
464
- # @raise [ArgumentError]
465
- # options[ :invalid ] が :raise で、日時が存在しない場合
466
- #
467
- # @note core/extension
468
- #
469
- def tm_pos(options={})
470
- When.TemporalPosition(*(self.dup << options))
471
- end
472
- alias :to_tm_pos :tm_pos
473
-
474
- # self を[幹,枝]と解釈してWhen::Coordinates::Pair を生成
475
- #
476
- # @see When::Coordinates::Pair._force_pair
477
- #
478
- # @return [When::Coordinates::Pair]
479
- #
480
- def to_pair
481
- Coordinates::Pair._force_pair(*self)
482
- end
483
- alias :pair :to_pair
484
- end
485
-
486
- #
487
- # Extensions to Module class
488
- #
489
- class Module
490
- unless method_defined?(:_const_missing)
491
- alias :_const_missing :const_missing
492
-
493
- #
494
- # When 直下に定数として定義する時法・暦法(暗黙的追加)
495
- #
496
- def const_missing(name)
497
- if When.const_defined?(name)
498
- _const_missing(name)
499
- else
500
- When.const_missing(name)
501
- end
502
- end
503
- end
504
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2013-2014 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
+ =end
7
+
8
+ require 'date'
9
+ require 'when_exe/core/duration'
10
+
11
+ #
12
+ # 標準クラスの拡張
13
+ #
14
+
15
+ #
16
+ # Extensions to Time class
17
+ #
18
+ class Time
19
+ #
20
+ # 対応する When::TM::JulianDate を生成
21
+ #
22
+ # @param [Hash] options 以下の通り
23
+ # @option options [When::TM::Clock] :clock
24
+ # @option options [When::Parts::Timezone] :tz
25
+ #
26
+ # @return [When::TM::JulianDate]
27
+ #
28
+ # @note core/extension
29
+ #
30
+ def julian_date(options={})
31
+ options[:clock] ||= Clock(self.utc_offset)
32
+ When::TM::JulianDate.universal_time(self.to_f * When::TM::IntervalLength::SECOND, options)
33
+ end
34
+ alias :to_julian_date :julian_date
35
+
36
+ #
37
+ # 対応する When::TM::DateAndTime を生成
38
+ #
39
+ # @param [Hash] options 暦法や時法などの指定
40
+ #
41
+ # @see When::TM::TemporalPosition._instance
42
+ #
43
+ # @return [When::TM::DateAndTime]
44
+ #
45
+ # @note core/extension
46
+ #
47
+ def tm_pos(options={})
48
+ When.at(self, options)
49
+ end
50
+ alias :to_tm_pos :tm_pos
51
+ end
52
+
53
+ #
54
+ # Extensions to Date class
55
+ #
56
+ class Date
57
+
58
+ if When::TM.const_defined?(:TemporalPosition)
59
+
60
+ include When::TM::TemporalPosition::Conversion
61
+
62
+ #
63
+ # 対応する When::TM::CalDate or DateAndTime を生成
64
+ #
65
+ # @param [Hash] options 暦法や時法などの指定
66
+ # see {When::TM::TemporalPosition._instance}
67
+ #
68
+ # @return [When::TM::CalDate, When::TM::DateAndTime]
69
+ #
70
+ # @note 暦法の指定がない場合、start メソッドの値によって
71
+ # Julian / Gregorian / Civil 暦法を選択する
72
+ #
73
+ def tm_pos(options={})
74
+ options[:frame] ||= When::CalendarTypes::Christian._default_start(self)
75
+ super(options)
76
+ end
77
+ alias :to_tm_pos :tm_pos
78
+ end
79
+
80
+ alias :__method_missing :method_missing
81
+
82
+ # その他のメソッド
83
+ #
84
+ # @note
85
+ # self で定義されていないメソッドは
86
+ # tm_pos で変換して処理する
87
+ #
88
+ def method_missing(name, *args, &block)
89
+ return __method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
90
+ self.class.module_eval %Q{
91
+ def #{name}(*args, &block)
92
+ result = tm_pos.send("#{name}", *args, &block)
93
+ case result
94
+ when When::TM::DateAndTime ; result.to_date_time
95
+ when When::TM::CalDate ; result.to_date
96
+ else ; result
97
+ end
98
+ end
99
+ } unless When::Parts::MethodCash.escape(name)
100
+ result = tm_pos.send(name, *args, &block)
101
+ case result
102
+ when When::TM::DateAndTime ; result.to_date_time
103
+ when When::TM::CalDate ; result.to_date
104
+ else ; result
105
+ end
106
+ end
107
+ end
108
+
109
+ #
110
+ # Extensions to Numeric class
111
+ #
112
+ class Numeric
113
+
114
+ include When::TM::TemporalPosition::Conversion if When::TM.const_defined?(:TemporalPosition)
115
+
116
+ #
117
+ # 曜日(剰余類)
118
+ #
119
+ # @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類)
120
+ #
121
+ # @note core/extension
122
+ #
123
+ def to_day_of_week
124
+ When::Coordinates::Residue.day_of_week(self)
125
+ end
126
+ alias :day_of_week :to_day_of_week
127
+
128
+ #
129
+ # 月名
130
+ #
131
+ # self が 月番号の月名を返します
132
+ #
133
+ # @return [When::BasicTypes::M17n] 月名
134
+ #
135
+ # @note core/extension
136
+ #
137
+ def to_month_name
138
+ When::BasicTypes::M17n.month_name(self)
139
+ end
140
+ alias :month_name :to_month_name
141
+
142
+ # self を幹の要素と解釈してWhen::Coordinates::Pair を生成
143
+ #
144
+ # @see When::Coordinates::Pair._force_pair
145
+ #
146
+ # @return [When::Coordinates::Pair]
147
+ #
148
+ def to_pair(branch=nil)
149
+ Coordinates::Pair._force_pair(self, branch)
150
+ end
151
+ alias :pair :to_pair
152
+
153
+ #
154
+ # self を秒数とみなして When::Parts::Timezone::Base を取得
155
+ #
156
+ # @return [When::Parts::Timezone::Base]
157
+ #
158
+ # @note core/extension
159
+ #
160
+ def clock
161
+ When.Clock(self)
162
+ end
163
+ alias :to_clock :clock
164
+
165
+ # メソッド名に相当する単位で表した When::TM::IntervalLength
166
+ # @method unit_interval_length
167
+ # @return [When::TM::IntervalLength]
168
+ #
169
+ # @note unit は second, minute, hour, day, week または
170
+ # seconds, minutes, hours, days, weeks に読み替える
171
+ #
172
+ # @note core/extension
173
+
174
+ # メソッド名に相当する単位で表した When::TM::PeriodDuration
175
+ # @method unit_period_duration
176
+ # @return [When::TM::PeriodDuration]
177
+ #
178
+ # @note unit は second, minute, hour, day, week, month, year または
179
+ # seconds, minutes, hours, days, weeks, months, years に読み替える
180
+ #
181
+ # @note core/extension
182
+
183
+ # @private
184
+ When::TM::Duration::Unit.keys.each do |key|
185
+
186
+ module_eval %Q{
187
+ # for When::TM::IntervalLength
188
+ def #{key}_interval_length
189
+ When::TM::IntervalLength.new(self, '#{key}')
190
+ end
191
+ alias :#{key}s_interval_length :#{key}_interval_length
192
+
193
+ # for When::TM::PeriodDuration
194
+ def #{key}_period_duration
195
+ When::TM::PeriodDuration.new(self, When::#{key.upcase})
196
+ end
197
+ alias :#{key}s_period_duration :#{key}_period_duration
198
+ }
199
+ end
200
+ end
201
+
202
+ #
203
+ # Extensions to String class
204
+ #
205
+ class String
206
+
207
+ include When::EncodingConversion
208
+
209
+ #
210
+ # self を When::BasicTypes::M17n に変換する
211
+ #
212
+ # @return [When::BasicTypes::M17n]
213
+ #
214
+ # @note core/extension
215
+ #
216
+ def to_m17n
217
+ When::BasicTypes::M17n.new(self)
218
+ end
219
+
220
+ # 特定 locale に対応した文字列の取得
221
+ #
222
+ # @param [String] loc locale の指定
223
+ #
224
+ # @return [String] loc に対応した文字列
225
+ #
226
+ # @note core/extension
227
+ #
228
+ def translate(loc='')
229
+ return encode($1) if loc =~ /\.(.+)\z/
230
+ return self
231
+ end
232
+ alias :/ :translate
233
+
234
+ # 包摂リストに登録されている文字を包摂する
235
+ #
236
+ # @param [Hash] pattern 包摂ルール
237
+ #
238
+ # @return [String] 包摂結果
239
+ #
240
+ def ideographic_unification(pattern=When::Locale._unification)
241
+ When::Locale.ideographic_unification(self, pattern)
242
+ end
243
+
244
+ #
245
+ # self を IRI とみなして When::Parts::Resource を取得
246
+ #
247
+ # @param [String] namespace デフォルトの namespace
248
+ #
249
+ # @return [When::Parts::Resource]
250
+ #
251
+ # @note core/extension
252
+ #
253
+ def resource(namespace=nil)
254
+ When::Parts::Resource._instance(self, namespace)
255
+ end
256
+ alias :to_resource :resource
257
+
258
+ #
259
+ # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::Calendar を取得
260
+ #
261
+ # @return [When::TM::Calendar]
262
+ #
263
+ # @note core/extension
264
+ #
265
+ def calendar
266
+ When::Parts::Resource._instance(self, '_c:')
267
+ end
268
+ alias :to_calendar :calendar
269
+
270
+ #
271
+ # self を時間帯文字列とみなして When::Parts::Timezone::Base を取得
272
+ #
273
+ # @return [When::Parts::Timezone::Base]
274
+ #
275
+ # @note core/extension
276
+ #
277
+ def clock
278
+ When.Clock(self)
279
+ end
280
+ alias :to_clock :clock
281
+
282
+ #
283
+ # self をプレフィクス '_c:' を省略した IRI とみなして When::TM::CalendarNote を取得
284
+ #
285
+ # @return [When::TM::CalendarNote]
286
+ #
287
+ # @note core/extension
288
+ #
289
+ def calendar_note
290
+ When::Parts::Resource._instance(self, '_n:')
291
+ end
292
+ alias :to_calendar_note :calendar_note
293
+
294
+ #
295
+ # self をプレフィクス '_e:' を省略した IRI とみなして When::TM::CalendarEra を取得
296
+ #
297
+ # @return [When::TM::CalendarEra]
298
+ #
299
+ # @note core/extension
300
+ #
301
+ def calendar_era
302
+ When::Parts::Resource._instance(self, '_e:')
303
+ end
304
+ alias :to_calendar_era :calendar_era
305
+
306
+ #
307
+ # self をプレフィクス '_m:' を省略した IRI とみなして When::BasicTypes::M17n を取得
308
+ #
309
+ # @return [When::BasicTypes::M17n]
310
+ #
311
+ # @note core/extension
312
+ #
313
+ def m17n
314
+ When::Parts::Resource._instance(self, '_m:')
315
+ end
316
+
317
+ # self を幹と枝の要素と解釈してWhen::Coordinates::Pair を生成
318
+ #
319
+ # @see When::Coordinates::Pair._force_pair
320
+ #
321
+ # @return [When::Coordinates::Pair]
322
+ #
323
+ def to_pair
324
+ Coordinates::Pair._force_pair(self)
325
+ end
326
+ alias :pair :to_pair
327
+
328
+ #
329
+ # self を検索する暦年代とみなして登録された When::TM::CalendarEraを検索
330
+ #
331
+ # @overload calendar_era(options={}
332
+ # @param [Hash] options
333
+ # see alse {When.era}
334
+ #
335
+ # @return [Array<When::TM::CalendarEra>]
336
+ #
337
+ # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
338
+ # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
339
+ # 生成しつつ読み込んで検索する。
340
+ #
341
+ # @note core/extension
342
+ #
343
+ def era(*args)
344
+ When::TM::CalendarEra._instance(*([self] + args))
345
+ end
346
+ alias :to_era :era
347
+
348
+ #
349
+ # self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成
350
+ #
351
+ # @param [Hash] options 暦法や時法などの指定
352
+ #
353
+ # @see When::TM::TemporalPosition._instance
354
+ #
355
+ # @return [When::TM::TemporalPosition]
356
+ #
357
+ # @note core/extension
358
+ #
359
+ def when?(options={})
360
+ When.when?(self, options)
361
+ end
362
+ alias :tm_pos :when?
363
+ alias :to_tm_pos :when?
364
+
365
+ #
366
+ # 曜日(剰余類)
367
+ #
368
+ # self の最初の3文字から決定した七曜(剰余類)を返します。
369
+ # 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
370
+ #
371
+ # @return [When::Coordinates::Residue]
372
+ # [ 月曜を 0 とする七曜(剰余類) ]
373
+ # [ 名前の一致するその他の剰余類 ]
374
+ #
375
+ # @note core/extension
376
+ #
377
+ def to_residue
378
+ When::Coordinates::Residue.to_residue(self)
379
+ end
380
+ alias :residue :to_residue
381
+ alias :day_of_week :to_residue
382
+
383
+ #
384
+ # 月名
385
+ #
386
+ # self の最初の3文字から決定した月名を返します。
387
+ # 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
388
+ # (self が M17n なら name 自身をそのまま返します)
389
+ #
390
+ # @return [When::BasicTypes::M17n] 月名
391
+ #
392
+ # @note core/extension
393
+ #
394
+ def to_month_name
395
+ When::BasicTypes::M17n.month_name(self)
396
+ end
397
+ alias :month_name :to_month_name
398
+
399
+ #
400
+ # self をWhen.exe Standard Expression とみなして When::TM::TemporalPosition を生成し“^”演算を実行
401
+ #
402
+ # @return [When::TM::TemporalPosition の “^”演算結果]
403
+ #
404
+ # @note core/extension
405
+ #
406
+ def ^(other)
407
+ When::TM::TemporalPosition._instance(self, {}) ^ other
408
+ end
409
+ end
410
+
411
+ #
412
+ # Extensions to Regexp class
413
+ #
414
+ class Regexp
415
+
416
+ include When::EncodingConversion
417
+
418
+ #
419
+ # self を検索する暦年代にマッチする正規表現とみなして登録された When::TM::CalendarEraを検索
420
+ #
421
+ # @overload calendar_era(options={}
422
+ # @param [Hash] options
423
+ # see also {When.era}
424
+ #
425
+ # @return [Array<When::TM::CalendarEra>]
426
+ #
427
+ # 検索結果を When::TM::CalendarEra オブジェクトの Array で返す。
428
+ # ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを
429
+ # 生成しつつ読み込んで検索する。
430
+ #
431
+ # @note core/extension
432
+ #
433
+ def era(*args)
434
+ When::TM::CalendarEra._instance(*([self] + args))
435
+ end
436
+ alias :to_era :era
437
+
438
+ # 包摂リストに登録されている文字を包摂する
439
+ #
440
+ # @param [Hash] pattern 包摂ルール
441
+ #
442
+ # @return [Regexp] 包摂結果
443
+ #
444
+ def ideographic_unification(pattern=When::Locale._unification)
445
+ When::Locale.ideographic_unification(self, pattern)
446
+ end
447
+ end
448
+
449
+ #
450
+ # Extensions to Array class
451
+ #
452
+ class Array
453
+ #
454
+ # self を暦要素の Array とみなして [When::TM::TemporalPosition] を生成
455
+ #
456
+ # @param [Hash] options 暦法や時法などの指定
457
+ # @option options [Symbol] :invalid
458
+ # [:raise 日時が存在しない場合例外発生 ]
459
+ # [:check 日時が存在しない場合 nil を返す ]
460
+ # [その他/nil 日時が存在することを確認しない(デフォルト)]
461
+ # see also {When::TM::TemporalPosition._instance}
462
+ #
463
+ # @return [When::TM::TemporalPosition]
464
+ # @raise [ArgumentError]
465
+ # options[ :invalid ] が :raise で、日時が存在しない場合
466
+ #
467
+ # @note core/extension
468
+ #
469
+ def tm_pos(options={})
470
+ When.TemporalPosition(*(self.dup << options))
471
+ end
472
+ alias :to_tm_pos :tm_pos
473
+
474
+ # self を[幹,枝]と解釈してWhen::Coordinates::Pair を生成
475
+ #
476
+ # @see When::Coordinates::Pair._force_pair
477
+ #
478
+ # @return [When::Coordinates::Pair]
479
+ #
480
+ def to_pair
481
+ Coordinates::Pair._force_pair(*self)
482
+ end
483
+ alias :pair :to_pair
484
+ end
485
+
486
+ #
487
+ # Extensions to Module class
488
+ #
489
+ class Module
490
+ unless method_defined?(:_const_missing)
491
+ alias :_const_missing :const_missing
492
+
493
+ #
494
+ # When 直下に定数として定義する時法・暦法(暗黙的追加)
495
+ #
496
+ def const_missing(name)
497
+ if When.const_defined?(name)
498
+ _const_missing(name)
499
+ else
500
+ When.const_missing(name)
501
+ end
502
+ end
503
+ end
504
+ end