when_exe 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/bin/irb.rc +1 -0
  2. data/bin/locales.rb +8 -6
  3. data/bin/when.rb +1 -1
  4. data/lib/when_exe.rb +231 -146
  5. data/lib/when_exe/basictypes.rb +108 -18
  6. data/lib/when_exe/calendarnote.rb +263 -116
  7. data/lib/when_exe/calendartypes.rb +413 -22
  8. data/lib/when_exe/coordinates.rb +58 -36
  9. data/lib/when_exe/core/compatibility.rb +8 -6
  10. data/lib/when_exe/core/extension.rb +40 -15
  11. data/lib/when_exe/ephemeris.rb +20 -19
  12. data/lib/when_exe/{region → ephemeris}/moon.rb +4 -4
  13. data/lib/when_exe/{region/ephemeric_notes.rb → ephemeris/notes.rb} +25 -6
  14. data/lib/when_exe/{region → ephemeris}/planets.rb +0 -0
  15. data/lib/when_exe/{region → ephemeris}/sun.rb +7 -3
  16. data/lib/when_exe/{region → ephemeris}/v50.rb +0 -0
  17. data/lib/when_exe/googlecalendar.rb +2 -2
  18. data/lib/when_exe/icalendar.rb +3 -3
  19. data/lib/when_exe/inspect.rb +130 -70
  20. data/lib/when_exe/locales/af.rb +2 -2
  21. data/lib/when_exe/locales/akt.rb +176 -0
  22. data/lib/when_exe/locales/ar.rb +2 -2
  23. data/lib/when_exe/locales/{locales.rb → autoload.rb} +6 -2
  24. data/lib/when_exe/locales/az.rb +2 -2
  25. data/lib/when_exe/locales/bg.rb +2 -2
  26. data/lib/when_exe/locales/bn.rb +2 -2
  27. data/lib/when_exe/locales/bs.rb +2 -2
  28. data/lib/when_exe/locales/ca.rb +2 -2
  29. data/lib/when_exe/locales/cs.rb +2 -2
  30. data/lib/when_exe/locales/cy.rb +2 -2
  31. data/lib/when_exe/locales/da.rb +2 -2
  32. data/lib/when_exe/locales/de.rb +2 -2
  33. data/lib/when_exe/locales/de_AT.rb +2 -2
  34. data/lib/when_exe/locales/de_CH.rb +2 -2
  35. data/lib/when_exe/locales/el.rb +2 -2
  36. data/lib/when_exe/locales/en.rb +2 -2
  37. data/lib/when_exe/locales/en_AU.rb +2 -2
  38. data/lib/when_exe/locales/en_CA.rb +2 -2
  39. data/lib/when_exe/locales/en_GB.rb +2 -2
  40. data/lib/when_exe/locales/en_IE.rb +2 -2
  41. data/lib/when_exe/locales/en_IN.rb +3 -3
  42. data/lib/when_exe/locales/en_NZ.rb +2 -2
  43. data/lib/when_exe/locales/en_US.rb +2 -2
  44. data/lib/when_exe/locales/en_ZA.rb +88 -0
  45. data/lib/when_exe/locales/encoding_conversion.rb +126 -0
  46. data/lib/when_exe/locales/eo.rb +2 -2
  47. data/lib/when_exe/locales/es.rb +2 -2
  48. data/lib/when_exe/locales/es_419.rb +2 -2
  49. data/lib/when_exe/locales/es_AR.rb +2 -2
  50. data/lib/when_exe/locales/es_CL.rb +2 -2
  51. data/lib/when_exe/locales/es_CO.rb +2 -2
  52. data/lib/when_exe/locales/es_CR.rb +2 -2
  53. data/lib/when_exe/locales/es_EC.rb +2 -2
  54. data/lib/when_exe/locales/es_MX.rb +2 -2
  55. data/lib/when_exe/locales/es_PA.rb +2 -2
  56. data/lib/when_exe/locales/es_PE.rb +2 -2
  57. data/lib/when_exe/locales/es_US.rb +84 -0
  58. data/lib/when_exe/locales/es_VE.rb +2 -2
  59. data/lib/when_exe/locales/et.rb +2 -2
  60. data/lib/when_exe/locales/eu.rb +2 -2
  61. data/lib/when_exe/locales/fa.rb +2 -2
  62. data/lib/when_exe/locales/fi.rb +3 -3
  63. data/lib/when_exe/locales/fr.rb +2 -2
  64. data/lib/when_exe/locales/fr_CA.rb +2 -2
  65. data/lib/when_exe/locales/fr_CH.rb +2 -2
  66. data/lib/when_exe/locales/gl.rb +2 -2
  67. data/lib/when_exe/locales/he.rb +3 -3
  68. data/lib/when_exe/locales/hi.rb +2 -2
  69. data/lib/when_exe/locales/hi_IN.rb +2 -2
  70. data/lib/when_exe/locales/hr.rb +2 -2
  71. data/lib/when_exe/locales/hu.rb +6 -5
  72. data/lib/when_exe/locales/iast.rb +90 -0
  73. data/lib/when_exe/locales/id.rb +2 -2
  74. data/lib/when_exe/locales/is.rb +2 -2
  75. data/lib/when_exe/locales/it.rb +2 -2
  76. data/lib/when_exe/locales/it_CH.rb +2 -2
  77. data/lib/when_exe/locales/ja.rb +2 -2
  78. data/lib/when_exe/locales/kn.rb +2 -2
  79. data/lib/when_exe/locales/ko.rb +2 -2
  80. data/lib/when_exe/locales/links.rb +3 -3
  81. data/lib/when_exe/locales/lo.rb +2 -2
  82. data/lib/when_exe/{parts → locales}/locale.rb +77 -49
  83. data/lib/when_exe/locales/lt.rb +6 -2
  84. data/lib/when_exe/locales/lv.rb +2 -2
  85. data/lib/when_exe/locales/mk.rb +2 -2
  86. data/lib/when_exe/locales/mn.rb +2 -2
  87. data/lib/when_exe/locales/ms.rb +2 -2
  88. data/lib/when_exe/locales/nb.rb +2 -2
  89. data/lib/when_exe/locales/ne.rb +2 -2
  90. data/lib/when_exe/locales/nl.rb +2 -2
  91. data/lib/when_exe/locales/nn.rb +2 -2
  92. data/lib/when_exe/locales/or.rb +2 -2
  93. data/lib/when_exe/locales/pl.rb +2 -2
  94. data/lib/when_exe/locales/pt.rb +2 -2
  95. data/lib/when_exe/locales/pt_BR.rb +2 -2
  96. data/lib/when_exe/locales/rm.rb +2 -2
  97. data/lib/when_exe/locales/ro.rb +2 -2
  98. data/lib/when_exe/locales/ru.rb +2 -2
  99. data/lib/when_exe/locales/sk.rb +2 -2
  100. data/lib/when_exe/locales/sl.rb +2 -2
  101. data/lib/when_exe/locales/sr.rb +2 -2
  102. data/lib/when_exe/locales/sv.rb +2 -2
  103. data/lib/when_exe/locales/sw.rb +2 -2
  104. data/lib/when_exe/locales/ta.rb +95 -0
  105. data/lib/when_exe/locales/th.rb +2 -2
  106. data/lib/when_exe/locales/tl.rb +3 -3
  107. data/lib/when_exe/locales/tr.rb +2 -2
  108. data/lib/when_exe/locales/transliteration_table.rb +62 -0
  109. data/lib/when_exe/locales/uk.rb +15 -15
  110. data/lib/when_exe/locales/ur.rb +2 -2
  111. data/lib/when_exe/locales/uz.rb +2 -2
  112. data/lib/when_exe/locales/vi.rb +2 -2
  113. data/lib/when_exe/locales/wo.rb +2 -2
  114. data/lib/when_exe/locales/zh_CN.rb +2 -2
  115. data/lib/when_exe/locales/zh_HK.rb +15 -15
  116. data/lib/when_exe/locales/zh_TW.rb +2 -2
  117. data/lib/when_exe/locales/zh_YUE.rb +77 -0
  118. data/lib/when_exe/mini_application.rb +22 -12
  119. data/lib/when_exe/parts/geometric_complex.rb +16 -1
  120. data/lib/when_exe/parts/method_cash.rb +184 -238
  121. data/lib/when_exe/parts/resource.rb +65 -16
  122. data/lib/when_exe/region/armenian.rb +56 -0
  123. data/lib/when_exe/region/bahai.rb +13 -13
  124. data/lib/when_exe/region/balinese.rb +33 -35
  125. data/lib/when_exe/region/chinese.rb +82 -78
  126. data/lib/when_exe/region/{chinese_calendar.rb → chinese/calendars.rb} +59 -40
  127. data/lib/when_exe/region/{chinese_epoch.rb → chinese/epochs.rb} +3 -4
  128. data/lib/when_exe/region/{chinese_twin.rb → chinese/twins.rb} +48 -51
  129. data/lib/when_exe/region/christian.rb +236 -127
  130. data/lib/when_exe/region/coptic.rb +9 -10
  131. data/lib/when_exe/region/dee.rb +48 -0
  132. data/lib/when_exe/region/discordian.rb +225 -0
  133. data/lib/when_exe/region/far_east.rb +2 -6
  134. data/lib/when_exe/region/french.rb +7 -17
  135. data/lib/when_exe/region/geologicalage.rb +0 -1
  136. data/lib/when_exe/region/goddess.rb +58 -0
  137. data/lib/when_exe/region/indian.rb +323 -231
  138. data/lib/when_exe/region/iranian.rb +159 -22
  139. data/lib/when_exe/region/islamic.rb +7 -9
  140. data/lib/when_exe/region/japanese.rb +14 -803
  141. data/lib/when_exe/region/japanese/calendars.rb +397 -0
  142. data/lib/when_exe/region/japanese/epochs.rb +426 -0
  143. data/lib/when_exe/region/{nihon_shoki.rb → japanese/nihon_shoki.rb} +0 -2
  144. data/lib/when_exe/region/{japanese_notes.rb → japanese/notes.rb} +179 -150
  145. data/lib/when_exe/region/japanese/residues.rb +1306 -0
  146. data/lib/when_exe/region/{japanese_twin.rb → japanese/twins.rb} +12 -15
  147. data/lib/when_exe/region/javanese.rb +16 -14
  148. data/lib/when_exe/region/jewish.rb +8 -9
  149. data/lib/when_exe/region/korean.rb +146 -35
  150. data/lib/when_exe/region/m17n.rb +8 -10
  151. data/lib/when_exe/region/martian.rb +44 -16
  152. data/lib/when_exe/region/mayan.rb +12 -10
  153. data/lib/when_exe/region/pope.rb +0 -1
  154. data/lib/when_exe/region/residue.rb +4 -5
  155. data/lib/when_exe/region/roman.rb +20 -24
  156. data/lib/when_exe/region/ryukyu.rb +3 -4
  157. data/lib/when_exe/region/shire.rb +97 -94
  158. data/lib/when_exe/region/symmetry.rb +50 -0
  159. data/lib/when_exe/region/thai.rb +164 -56
  160. data/lib/when_exe/region/tibetan.rb +86 -86
  161. data/lib/when_exe/region/vietnamese.rb +9 -12
  162. data/lib/when_exe/region/weekdate.rb +80 -0
  163. data/lib/when_exe/region/world.rb +65 -70
  164. data/lib/when_exe/region/yerm.rb +98 -0
  165. data/lib/when_exe/region/zoroastrian.rb +203 -0
  166. data/lib/when_exe/timestandard.rb +4 -4
  167. data/lib/when_exe/tmobjects.rb +1 -3
  168. data/lib/when_exe/tmposition.rb +13 -12
  169. data/lib/when_exe/tmreference.rb +11 -10
  170. data/lib/when_exe/version.rb +1 -1
  171. data/link_to_online_documents +3 -3
  172. data/test/examples/Residue.m17n +1 -1
  173. data/test/examples/Terms.m17n +1 -1
  174. data/test/test.rb +2 -1
  175. data/test/test/basictypes.rb +18 -2
  176. data/test/test/calendarnote.rb +1 -1
  177. data/test/test/calendartypes.rb +1 -1
  178. data/test/test/coordinates.rb +7 -7
  179. data/test/test/{region → ephemeris}/moon.rb +0 -0
  180. data/test/test/{region → ephemeris}/planets.rb +0 -0
  181. data/test/test/{region → ephemeris}/sun.rb +0 -0
  182. data/test/test/parts.rb +8 -13
  183. data/test/test/region/christian.rb +245 -0
  184. data/test/test/region/french.rb +16 -16
  185. data/test/test/region/iran.rb +34 -34
  186. data/test/test/region/japanese.rb +6 -4
  187. data/test/test/region/m17n.rb +8 -7
  188. data/test/test/region/mayan.rb +12 -12
  189. data/test/test/region/residue.rb +20 -4
  190. data/test/test/region/thai.rb +25 -3
  191. data/test/test/region/yerm.rb +146 -0
  192. metadata +39 -20
  193. data/lib/when_exe/region/japanese_residues.rb +0 -1212
  194. data/test/test/region/civil.rb +0 -124
@@ -112,10 +112,10 @@ module When::Coordinates
112
112
  return day if day.kind_of?(self)
113
113
 
114
114
  day ||= 0
115
- week = When.Resource('_co:CommonResidue::Week').child
115
+ week = When.Resource('_co:Common::Week').child
116
116
  case day
117
117
  when Numeric ; return week[day]
118
- when String ;
118
+ when String ; day = When::EncodingConversion.to_internal_encoding(day)
119
119
  else ; return nil
120
120
  end
121
121
 
@@ -696,20 +696,14 @@ module When::Coordinates
696
696
  private
697
697
 
698
698
  def _normalize(args=[], options={})
699
- label, unit, base, trunk, shift, branch = args
700
- label ||= @label
701
- unit ||= @unit
702
- base ||= @base || 1
703
- shift ||= @shift || 0
704
- @label = m17n(label, nil, nil, @options) if label
705
- @unit = unit.to_i if unit
706
- @base = base.to_i
707
- @trunk = trunk if trunk
708
- @shift = shift.to_i
709
- @branch = branch if branch
699
+ @label = m17n(@label, nil, nil, @options) if @label
700
+ @unit = @unit.to_i if @unit
701
+ @base = (@base || 1).to_i
702
+ @trunk = When::BasicTypes::M17n.labels(args[0]) unless args.empty?
703
+ @shift = (@shift || 0).to_i
710
704
  @keys = []
711
- if (@trunk)
712
- if (@trunk.kind_of?(Array))
705
+ if @trunk
706
+ if @trunk.kind_of?(Array)
713
707
  m17n = {}
714
708
  @trunk.length.times do |i|
715
709
  m17n[(i-@shift) % @trunk.length + @base] = @trunk[i]
@@ -718,11 +712,11 @@ module When::Coordinates
718
712
  end
719
713
  raise TypeError, "Trunk must be Hash" unless @trunk.kind_of?(Hash)
720
714
  @trunk.values.each do |v|
721
- @keys |= v.keys if v.kind_of?(When::Parts::Locale)
715
+ @keys |= v.keys if v.kind_of?(When::Locale)
722
716
  end
723
717
  end
724
- if (@branch)
725
- if (@branch.kind_of?(Array))
718
+ if @branch
719
+ if @branch.kind_of?(Array)
726
720
  m17n = {}
727
721
  @branch.length.times do |i|
728
722
  m17n[i] = @branch[i]
@@ -730,8 +724,10 @@ module When::Coordinates
730
724
  @branch = m17n
731
725
  end
732
726
  raise TypeError, "Branch must be Hash" unless @branch.kind_of?(Hash)
733
- @branch.values.each do |v|
734
- @keys |= v.keys if v.kind_of?(When::Parts::Locale)
727
+ @branch.each_pair do |key, value|
728
+ value = When::BasicTypes::M17n.label(value)
729
+ @keys |= value.keys if value.kind_of?(When::Locale)
730
+ @branch[key] = value
735
731
  end
736
732
  end
737
733
  @trunk_branch = {}
@@ -1585,7 +1581,7 @@ module When::Coordinates
1585
1581
  # Formula
1586
1582
  instance_eval('class << self; attr_reader :formula; end') if @location && @border
1587
1583
  if respond_to?(:formula)
1588
- instance_eval('class << self; include When::Ephemeris::Formula::ForwardedFormula; end')
1584
+ extend When::Ephemeris::Formula::ForwardedFormula
1589
1585
  @formula ||= When::Ephemeris::Formula.new({:location=>@location})
1590
1586
  @formula = When.Resource(Array(@formula), '_ep:')
1591
1587
  end
@@ -1680,7 +1676,10 @@ module When::Coordinates
1680
1676
  # block [Block] (デフォルト なし)
1681
1677
  #
1682
1678
  def note
1683
- @note = When.CalendarNote(@note) if @note.kind_of?(String)
1679
+ case @note
1680
+ when String ; @note = When.CalendarNote(@note)
1681
+ when Array ; @note = When::CalendarNote.new(*@note)
1682
+ end
1684
1683
  @note
1685
1684
  end
1686
1685
 
@@ -1944,15 +1943,18 @@ module When::Coordinates
1944
1943
  # method cash
1945
1944
  @_m_cash_lock_ = Mutex.new if When.multi_thread
1946
1945
 
1946
+ # label
1947
+ @label = When::BasicTypes::M17n.label(@label)
1948
+
1947
1949
  # Origin and Upper Digits
1948
1950
  @origin_of_MSC ||= - +@border.behavior if @border
1949
1951
  @origin_of_MSC = Pair._en_number(@origin_of_MSC)
1950
1952
  @origin_of_LSC = Pair._en_number(@origin_of_LSC)
1951
1953
  @index_of_MSC = Pair._en_number(@index_of_MSC)
1952
- if (@index_of_MSC != 0)
1953
- class << self; include OriginAndUpperDigits; end
1954
- elsif (@origin_of_MSC != 0)
1955
- class << self; include OriginOnly; end
1954
+ if @index_of_MSC != 0
1955
+ extend OriginAndUpperDigits
1956
+ elsif @origin_of_MSC != 0
1957
+ extend OriginOnly
1956
1958
  end
1957
1959
 
1958
1960
  # unit
@@ -1970,13 +1972,24 @@ module When::Coordinates
1970
1972
  @base << @indices[i].base
1971
1973
  @pair << (@indices[i].branch != nil)
1972
1974
  end
1973
- class << self; include IndexConversion; end unless @pair.uniq == [false]
1975
+ extend IndexConversion unless @pair.uniq == [false]
1974
1976
 
1975
1977
  # note
1976
- @note ||= 'DefaultNotes'
1978
+ @note ||= 'Default'
1977
1979
 
1978
1980
  # keys
1979
- @keys = @indices.inject(label.instance_of?(When::Parts::Locale) ? label.keys : []) {|key, index| key |= index.keys}
1981
+ @keys = @indices.inject(label.instance_of?(When::Locale) ? label.keys : []) {|key, index| key |= index.keys}
1982
+ end
1983
+
1984
+ def _default_index_of_MSC
1985
+ unless @index_of_MSC
1986
+ [:_coordinates_to_number, :_coordinates_to_number_].each do |to_n|
1987
+ if respond_to?(to_n)
1988
+ @index_of_MSC = @indices.length - method(to_n).arity + 1
1989
+ break
1990
+ end
1991
+ end
1992
+ end
1980
1993
  end
1981
1994
 
1982
1995
  # 何もしない
@@ -2047,12 +2060,21 @@ module When::Coordinates
2047
2060
  def method_missing(name, *args, &block)
2048
2061
  unless When::Parts::MethodCash::Escape.key?(name)
2049
2062
  if note.respond_to?(name)
2050
- instance_eval %Q{
2051
- def #{name}(*args, &block)
2052
- @note.send("#{name}", *(args + [self]), &block)
2053
- end
2054
- } unless When::Parts::MethodCash.escape(name)
2055
- return @note.send(name, *(args + [self]), &block)
2063
+ if note.class::CalendarDepend
2064
+ instance_eval %Q{
2065
+ def #{name}(*args, &block)
2066
+ @note.send("#{name}", *(args + [self]), &block)
2067
+ end
2068
+ } unless When::Parts::MethodCash.escape(name)
2069
+ return @note.send(name, *(args + [self]), &block)
2070
+ else
2071
+ instance_eval %Q{
2072
+ def #{name}(*args, &block)
2073
+ @note.send("#{name}", *args, &block)
2074
+ end
2075
+ } unless When::Parts::MethodCash.escape(name)
2076
+ return @note.send(name, *args, &block)
2077
+ end
2056
2078
  end
2057
2079
  ['SolarTerms', 'LunarPhases'].each do |note|
2058
2080
  if When.CalendarNote(note).respond_to?(name)
@@ -2066,7 +2088,7 @@ module When::Coordinates
2066
2088
  end
2067
2089
  if When::Ephemeris::Formula.method_defined?(name)
2068
2090
  unless respond_to?(:forwarded_formula, true)
2069
- instance_eval('class << self; include When::Ephemeris::Formula::ForwardedFormula; end')
2091
+ extend When::Ephemeris::Formula::ForwardedFormula
2070
2092
  @formula ||= When::Ephemeris::Formula.new({:location=>@location})
2071
2093
  @formula = When.Resource(Array(@formula), '_ep:')
2072
2094
  end
@@ -6,12 +6,13 @@
6
6
  =end
7
7
 
8
8
  #
9
- # Ruby .8.x 系のためのための互換性確保用コード
9
+ # Ruby 1.8.x 系のためのための互換性確保用コード
10
10
  #
11
11
 
12
12
  class String
13
- unless "1".respond_to?(:encode)
13
+ unless method_defined?(:encode)
14
14
  require('iconv')
15
+ #
15
16
  # encode
16
17
  #
17
18
  # @param [String] code 文字コード
@@ -23,11 +24,11 @@ class String
23
24
  end
24
25
  end
25
26
 
26
- unless "1".respond_to?(:to_r)
27
+ unless method_defined?(:to_r)
28
+ #
27
29
  # to_r(もどき)
28
30
  #
29
- # 文字列を numeric に変換する
30
- # (できるだけ情報が落ちない型を選択)
31
+ # 文字列を Rational or Integer に変換する
31
32
  #
32
33
  # @return [Numeric]
33
34
  def to_r
@@ -43,7 +44,8 @@ class String
43
44
  end
44
45
  end
45
46
 
46
- unless "1".respond_to?(:ord)
47
+ unless method_defined?(:ord)
48
+ #
47
49
  # 文字列の先頭文字のコードを取得する
48
50
  # (多バイト文字非対応)
49
51
  #
@@ -44,10 +44,10 @@ class Time
44
44
  #
45
45
  # @note core/extension
46
46
  #
47
- def tm_position(options={})
47
+ def tm_pos(options={})
48
48
  When.at(self, options)
49
49
  end
50
- alias :to_tm_position :tm_position
50
+ alias :to_tm_pos :tm_pos
51
51
  end
52
52
 
53
53
  #
@@ -70,11 +70,11 @@ class Date
70
70
  # @note 暦法の指定がない場合、start メソッドの値によって
71
71
  # Julian / Gregorian / Civil 暦法を選択する
72
72
  #
73
- def tm_position(options={})
73
+ def tm_pos(options={})
74
74
  options[:frame] ||= When::CalendarTypes::Christian._default_start(self)
75
75
  super(options)
76
76
  end
77
- alias :to_tm_position :tm_position
77
+ alias :to_tm_pos :tm_pos
78
78
  end
79
79
 
80
80
  alias :__method_missing :method_missing
@@ -83,13 +83,13 @@ class Date
83
83
  #
84
84
  # @note
85
85
  # self で定義されていないメソッドは
86
- # tm_position で変換して処理する
86
+ # tm_pos で変換して処理する
87
87
  #
88
88
  def method_missing(name, *args, &block)
89
89
  return __method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
90
90
  self.class.module_eval %Q{
91
91
  def #{name}(*args, &block)
92
- result = tm_position.send("#{name}", *args, &block)
92
+ result = tm_pos.send("#{name}", *args, &block)
93
93
  case result
94
94
  when When::TM::DateAndTime ; result.to_date_time
95
95
  when When::TM::CalDate ; result.to_date
@@ -97,7 +97,7 @@ class Date
97
97
  end
98
98
  end
99
99
  } unless When::Parts::MethodCash.escape(name)
100
- result = tm_position.send(name, *args, &block)
100
+ result = tm_pos.send(name, *args, &block)
101
101
  case result
102
102
  when When::TM::DateAndTime ; result.to_date_time
103
103
  when When::TM::CalDate ; result.to_date
@@ -204,6 +204,8 @@ end
204
204
  #
205
205
  class String
206
206
 
207
+ include When::EncodingConversion
208
+
207
209
  #
208
210
  # self を When::BasicTypes::M17n に変換する
209
211
  #
@@ -235,8 +237,8 @@ class String
235
237
  #
236
238
  # @return [String] 包摂結果
237
239
  #
238
- def ideographic_unification(pattern=When::Parts::Locale._unification)
239
- When::Parts::Locale.ideographic_unification(self, pattern)
240
+ def ideographic_unification(pattern=When::Locale._unification)
241
+ When::Locale.ideographic_unification(self, pattern)
240
242
  end
241
243
 
242
244
  #
@@ -357,8 +359,8 @@ class String
357
359
  def when?(options={})
358
360
  When.when?(self, options)
359
361
  end
360
- alias :tm_position :when?
361
- alias :to_tm_position :when?
362
+ alias :tm_pos :when?
363
+ alias :to_tm_pos :when?
362
364
 
363
365
  #
364
366
  # 曜日(剰余類)
@@ -410,6 +412,9 @@ end
410
412
  # Extensions to Regexp class
411
413
  #
412
414
  class Regexp
415
+
416
+ include When::EncodingConversion
417
+
413
418
  #
414
419
  # self を検索する暦年代にマッチする正規表現とみなして登録された When::TM::CalendarEraを検索
415
420
  #
@@ -436,8 +441,8 @@ class Regexp
436
441
  #
437
442
  # @return [Regexp] 包摂結果
438
443
  #
439
- def ideographic_unification(pattern=When::Parts::Locale._unification)
440
- When::Parts::Locale.ideographic_unification(self, pattern)
444
+ def ideographic_unification(pattern=When::Locale._unification)
445
+ When::Locale.ideographic_unification(self, pattern)
441
446
  end
442
447
  end
443
448
 
@@ -461,10 +466,10 @@ class Array
461
466
  #
462
467
  # @note core/extension
463
468
  #
464
- def tm_position(options={})
469
+ def tm_pos(options={})
465
470
  When.TemporalPosition(*(self.dup << options))
466
471
  end
467
- alias :to_tm_position :tm_position
472
+ alias :to_tm_pos :tm_pos
468
473
 
469
474
  # self を[幹,枝]と解釈してWhen::Coordinates::Pair を生成
470
475
  #
@@ -477,3 +482,23 @@ class Array
477
482
  end
478
483
  alias :pair :to_pair
479
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
@@ -10,20 +10,20 @@
10
10
  #
11
11
  module When::Ephemeris
12
12
 
13
- autoload :Sun, 'when_exe/region/sun'
14
- autoload :Mercury, 'when_exe/region/planets'
15
- autoload :Venus, 'when_exe/region/planets'
16
- autoload :Earth, 'when_exe/region/sun'
17
- autoload :JGD2000, 'when_exe/region/sun'
18
- autoload :Mars, 'when_exe/region/planets'
19
- autoload :Jupiter, 'when_exe/region/planets'
20
- autoload :Saturn, 'when_exe/region/planets'
21
- autoload :Uranus, 'when_exe/region/planets'
22
- autoload :Neptune, 'when_exe/region/planets'
23
- autoload :Pluto, 'when_exe/region/planets'
24
- autoload :Moon, 'when_exe/region/moon'
25
- autoload :Shadow, 'when_exe/region/moon'
26
- autoload :V50, 'when_exe/region/v50'
13
+ autoload :Sun, 'when_exe/ephemeris/sun'
14
+ autoload :Mercury, 'when_exe/ephemeris/planets'
15
+ autoload :Venus, 'when_exe/ephemeris/planets'
16
+ autoload :Earth, 'when_exe/ephemeris/sun'
17
+ autoload :JGD2000, 'when_exe/ephemeris/sun'
18
+ autoload :Mars, 'when_exe/ephemeris/planets'
19
+ autoload :Jupiter, 'when_exe/ephemeris/planets'
20
+ autoload :Saturn, 'when_exe/ephemeris/planets'
21
+ autoload :Uranus, 'when_exe/ephemeris/planets'
22
+ autoload :Neptune, 'when_exe/ephemeris/planets'
23
+ autoload :Pluto, 'when_exe/ephemeris/planets'
24
+ autoload :Moon, 'when_exe/ephemeris/moon'
25
+ autoload :Shadow, 'when_exe/ephemeris/moon'
26
+ autoload :V50, 'when_exe/ephemeris/v50'
27
27
  autoload :Hindu, 'when_exe/region/indian'
28
28
 
29
29
  include Math
@@ -336,8 +336,9 @@ module When::Ephemeris
336
336
  y.shift
337
337
  i -= 1
338
338
  end
339
- raise RangeError, "The result does not converge." if i<=0
340
- return t[2]
339
+ return t[2] if i > 0
340
+ return t[1] + (t[0]-t[1]) / (y[0]-y[1]) * (y0-y[1]) if y0 && count < 6
341
+ raise RangeError, "The result does not converge - #{t}->#{y}."
341
342
  end
342
343
 
343
344
  # y が周期量である場合の周期の補正
@@ -1118,7 +1119,7 @@ module When::Ephemeris
1118
1119
  #
1119
1120
  def eclipse(t, target, base=Earth)
1120
1121
  t = +t
1121
- distance = self.coords(t, base).spherical_law_of_cosines(target.coords(t, base)) / CIRCLE
1122
+ distance = acos(self.coords(t, base).spherical_law_of_cosines(target.coords(t, base))) / CIRCLE
1122
1123
  self_radius = self.apparent_radius(t, base)
1123
1124
  target_radius = target.apparent_radius(t, base)
1124
1125
  return (self_radius + target_radius - distance) / (2.0 * target_radius)
@@ -1900,11 +1901,11 @@ module When::Ephemeris
1900
1901
  @month_epoch = 0
1901
1902
  @month_epoch = @longitude_shift -_mean_moon_(@epoch_shift).to_i
1902
1903
  end
1903
- class << self; include LunarMethod; end
1904
+ extend LunarMethod
1904
1905
  else
1905
1906
  # 太陽黄経の計算
1906
1907
  @solar_degree = @year_length / 360
1907
- class << self; include SolarMethod; end
1908
+ extend SolarMethod
1908
1909
  end
1909
1910
  super
1910
1911
  end
@@ -5,7 +5,7 @@
5
5
  You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
6
  =end
7
7
 
8
- require 'when_exe/region/sun'
8
+ require 'when_exe/ephemeris/sun'
9
9
  module When
10
10
  module Ephemeris
11
11
 
@@ -324,9 +324,9 @@ module When
324
324
  def apparent_radius(t, base=nil)
325
325
  t = +t
326
326
  radius = Sun.pi(t) * AU
327
- (asin(Ephemeris::Shadow.surface_radius/AU/Moon.pi(t)) -
328
- asin(Ephemeris::Sun.surface_radius/radius) +
329
- asin(Ephemeris::Shadow.surface_radius/radius)) * 1.02 / CIRCLE
327
+ (asin(surface_radius/Moon.pi(t)) -
328
+ asin(Ephemeris::Sun::Radius/radius) +
329
+ asin(surface_radius/radius)) * 1.02 / CIRCLE
330
330
  end
331
331
  end
332
332
  end
@@ -99,11 +99,31 @@ class When::CalendarNote
99
99
  # @param [String] parameter 座標の分子と分母("#{ num }/#{ den }" の形式)
100
100
  #
101
101
  # @return [When::TM::IntervalLength]
102
+ #
103
+ # @private
102
104
  def event_delta(parameter=nil)
103
105
  return @delta unless parameter
104
106
  num, den = parameter.split(/\//, 2)
105
107
  When::TM::IntervalLength.new([(den || @den).to_f,1].max*0.9, 'day')
106
108
  end
109
+
110
+ #
111
+ # イベント日付(時刻付)
112
+ #
113
+ # @private
114
+ def event_time(date, event_name, event)
115
+ etime = term(date - When.Duration('P3D'), event, When::SYSTEM)
116
+ if formula.respond_to?(:year_length) && formula.denominator && formula.denominator < 100000
117
+ fraction = etime.clk_time.universal_time
118
+ fraction += When::TM::Duration::DAY * (etime.to_i - date.to_i)
119
+ fraction = (fraction / When::TM::Duration::DAY * formula.denominator * 1000 + 0.5).floor / 1000.0
120
+ fraction = fraction.to_i if fraction == fraction.to_i
121
+ event_name + "(#{fraction}/#{formula.denominator})"
122
+ else
123
+ etime.events = [event_name]
124
+ etime
125
+ end
126
+ end
107
127
  end
108
128
 
109
129
  #
@@ -173,12 +193,11 @@ class When::CalendarNote
173
193
  #
174
194
  # 天体暦の暦注
175
195
  #
176
- class EphemericNote < self
196
+ class Ephemeris < self
177
197
 
178
- NoteObjects = [When::BasicTypes::M17n, [
179
- "namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
198
+ Notes = [When::BasicTypes::M17n, [
180
199
  "locale:[=en:, ja=ja:, alias=ja:]",
181
- "names:[Ephemeric]",
200
+ "names:[Ephemeris]",
182
201
 
183
202
  # 年の暦注 ----------------------------
184
203
  [When::BasicTypes::M17n,
@@ -201,7 +220,7 @@ class When::CalendarNote
201
220
  [When::Coordinates::Residue,
202
221
  "label:[Moon_Age=, 正午月齢=ja:%%<月齢>]",
203
222
  "divisor:60",
204
- "format:[%s(%4.1f)]"
223
+ "format:[%s(%4.1f)=]"
205
224
  ],
206
225
  "[Moonrise, 月の出 ]", # 月の出
207
226
  "[Moonset=, 月の入り ]", # 月の入り
@@ -354,7 +373,7 @@ class When::CalendarNote
354
373
  @formula = {}
355
374
  end
356
375
  @interval = @interval.sub('@','.').to_f / 24 if @interval
357
- @root = When.CalendarNote('EphemericNote/NoteObjects::day')
376
+ @root = When.CalendarNote('Ephemeris/Notes::day')
358
377
  @prime ||= [%w(Month), %w(Sunrise Sunset Moon_Age)]
359
378
  super
360
379
  end