when_exe 0.3.5 → 0.3.6

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 (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
@@ -5,8 +5,8 @@
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
- module When::BasicTypes
9
- class M17n
8
+ module When
9
+ module Locale
10
10
 
11
11
  # from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/vi.yml
12
12
 
@@ -5,8 +5,8 @@
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
- module When::BasicTypes
9
- class M17n
8
+ module When
9
+ module Locale
10
10
 
11
11
  # from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/wo.yml
12
12
 
@@ -5,8 +5,8 @@
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
- module When::BasicTypes
9
- class M17n
8
+ module When
9
+ module Locale
10
10
 
11
11
  # from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/zh-CN.yml
12
12
 
@@ -5,8 +5,8 @@
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
- module When::BasicTypes
9
- class M17n
8
+ module When
9
+ module Locale
10
10
 
11
11
  # from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/zh-HK.yml
12
12
 
@@ -45,30 +45,30 @@ module When::BasicTypes
45
45
  "十二月"],
46
46
  "order"=>[:year, :month, :day]},
47
47
  "time"=>
48
- {"am"=>"上晝",
48
+ {"am"=>"上午",
49
49
  "formats"=>
50
- {"default"=>"%Y年%b%d %A %H:%M:%S %Z",
51
- "long"=>"%Y年%b%d %H:%M",
52
- "short"=>"%b%d %H:%M",
50
+ {"default"=>"%Y年%b%d %A %H:%M:%S %Z",
51
+ "long"=>"%Y年%b%d %H:%M",
52
+ "short"=>"%b%d %H:%M",
53
53
  "time"=>"%H:%M:%S %Z"},
54
- "pm"=>"下晝"},
54
+ "pm"=>"下午"},
55
55
  "datetime"=>
56
56
  {"distance_in_words"=>
57
- {"about_x_hours"=>{"one"=>"大概一個鐘", "other"=>"大概%{count}個鐘"},
58
- "about_x_months"=>{"one"=>"大概一個月", "other"=>"大概%{count}個月"},
59
- "about_x_years"=>{"one"=>"大概一年", "other"=>"大概%{count}年"},
60
- "almost_x_years"=>{"one"=>"差唔多一年", "other"=>"差唔多%{count}年"},
57
+ {"about_x_hours"=>{"one"=>"約一小時", "other"=>"約%{count}小時"},
58
+ "about_x_months"=>{"one"=>"約一個月", "other"=>"約%{count}個月"},
59
+ "about_x_years"=>{"one"=>"約一年", "other"=>"約%{count}年"},
60
+ "almost_x_years"=>{"one"=>"接近一年", "other"=>"接近%{count}年"},
61
61
  "half_a_minute"=>"半分鐘",
62
- "less_than_x_minutes"=>{"one"=>"唔夠一分鐘", "other"=>"唔夠%{count}分鐘"},
63
- "less_than_x_seconds"=>{"one"=>"唔夠一秒", "other"=>"唔夠%{count}秒"},
62
+ "less_than_x_minutes"=>{"one"=>"不到一分鐘", "other"=>"不到%{count}分鐘"},
63
+ "less_than_x_seconds"=>{"one"=>"不到一秒", "other"=>"不到%{count}秒"},
64
64
  "over_x_years"=>{"one"=>"超過一年", "other"=>"超過%{count}年"},
65
- "x_days"=>{"one"=>"一日", "other"=>"%{count}"},
65
+ "x_days"=>{"one"=>"一天", "other"=>"%{count}"},
66
66
  "x_minutes"=>{"one"=>"一分鐘", "other"=>"%{count}分鐘"},
67
67
  "x_months"=>{"one"=>"一個月", "other"=>"%{count}個月"},
68
68
  "x_seconds"=>{"one"=>"一秒", "other"=>"%{count}秒"}},
69
69
  "prompts"=>
70
70
  {"day"=>"日",
71
- "hour"=>"",
71
+ "hour"=>"",
72
72
  "minute"=>"分",
73
73
  "month"=>"月",
74
74
  "second"=>"秒",
@@ -5,8 +5,8 @@
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
- module When::BasicTypes
9
- class M17n
8
+ module When
9
+ module Locale
10
10
 
11
11
  # from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/zh-TW.yml
12
12
 
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2012-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
+ module Locale
10
+
11
+ # from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/zh-YUE.yml
12
+
13
+ Locale_zh_YUE =
14
+ {"date"=>
15
+ {"abbr_day_names"=>["日", "一", "二", "三", "四", "五", "六"],
16
+ "abbr_month_names"=>
17
+ [nil,
18
+ "1月",
19
+ "2月",
20
+ "3月",
21
+ "4月",
22
+ "5月",
23
+ "6月",
24
+ "7月",
25
+ "8月",
26
+ "9月",
27
+ "10月",
28
+ "11月",
29
+ "12月"],
30
+ "day_names"=>["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
31
+ "formats"=>{"default"=>"%Y-%m-%d", "long"=>"%Y年%b%d日", "short"=>"%b%d日"},
32
+ "month_names"=>
33
+ [nil,
34
+ "一月",
35
+ "二月",
36
+ "三月",
37
+ "四月",
38
+ "五月",
39
+ "六月",
40
+ "七月",
41
+ "八月",
42
+ "九月",
43
+ "十月",
44
+ "十一月",
45
+ "十二月"],
46
+ "order"=>[:year, :month, :day]},
47
+ "time"=>
48
+ {"am"=>"上晝",
49
+ "formats"=>
50
+ {"default"=>"%Y年%b%d號 %A %H:%M:%S %Z",
51
+ "long"=>"%Y年%b%d號 %H:%M",
52
+ "short"=>"%b%d號 %H:%M",
53
+ "time"=>"%H:%M:%S %Z"},
54
+ "pm"=>"下晝"},
55
+ "datetime"=>
56
+ {"distance_in_words"=>
57
+ {"about_x_hours"=>{"one"=>"大概一個鐘", "other"=>"大概%{count}個鐘"},
58
+ "about_x_months"=>{"one"=>"大概一個月", "other"=>"大概%{count}個月"},
59
+ "about_x_years"=>{"one"=>"大概一年", "other"=>"大概%{count}年"},
60
+ "almost_x_years"=>{"one"=>"差唔多一年", "other"=>"差唔多%{count}年"},
61
+ "half_a_minute"=>"半分鐘",
62
+ "less_than_x_minutes"=>{"one"=>"唔夠一分鐘", "other"=>"唔夠%{count}分鐘"},
63
+ "less_than_x_seconds"=>{"one"=>"唔夠一秒", "other"=>"唔夠%{count}秒"},
64
+ "over_x_years"=>{"one"=>"超過一年", "other"=>"超過%{count}年"},
65
+ "x_days"=>{"one"=>"一日", "other"=>"%{count}日"},
66
+ "x_minutes"=>{"one"=>"一分鐘", "other"=>"%{count}分鐘"},
67
+ "x_months"=>{"one"=>"一個月", "other"=>"%{count}個月"},
68
+ "x_seconds"=>{"one"=>"一秒", "other"=>"%{count}秒"}},
69
+ "prompts"=>
70
+ {"day"=>"日",
71
+ "hour"=>"點",
72
+ "minute"=>"分",
73
+ "month"=>"月",
74
+ "second"=>"秒",
75
+ "year"=>"年"}}}
76
+ end
77
+ end
@@ -61,10 +61,10 @@ module When
61
61
  Thread.start(socket.accept) do |client|
62
62
  query = client.gets.chomp.force_encoding("UTF-8")
63
63
  start = Time.now
64
- puts start._log_('%FT%X.%L') + ': Query - ' + When::Parts::Locale.translate(query, config['!'])
64
+ puts start._log_('%FT%X.%L') + ': Query - ' + When::Locale.translate(query, config['!'])
65
65
  begin
66
66
  result = free_conv(*query.split(/\s+/))
67
- result = When::Parts::Locale.translate(result, config['!'])
67
+ result = When::Locale.translate(result, config['!'])
68
68
  client.puts JSON.generate(Array(_to_string(result))).to_s
69
69
  stop = Time.now
70
70
  puts stop._log_('%FT%X.%L') + ": Respond (%7.0f ms)" % (1000 * (stop.to_f - start.to_f))
@@ -126,19 +126,28 @@ module When
126
126
  if methods.size == 0
127
127
  lambda {|date| date.send(*output)}
128
128
  else
129
- lambda {|date, type|
130
- case type
131
- when When::YEAR ; date.strftime("%Y")
132
- when When::MONTH ; date.strftime("%B %Y")
133
- when When::WEEK ; nil
134
- when When::DAY ; date[0]
135
- else ; '-'
136
- end
137
- }
129
+ lambda {|date, type| column(date, type)}
138
130
  end
139
131
  _free_conv(calendars, dates, methods, output, options, &block)
140
132
  end
141
133
 
134
+ # 七曜表の一日分
135
+ #
136
+ # @param [When::TM::TemporalPosition] date 処理する一日
137
+ # @param [Integer, nil] type 当該日の種類
138
+ #
139
+ # @return [Object>] 処理結果
140
+ #
141
+ def column(date, type)
142
+ case type
143
+ when When::YEAR ; date.strftime("%Y")
144
+ when When::MONTH ; date.strftime("%B %Y")
145
+ when When::WEEK ; nil
146
+ when When::DAY ; date[0]
147
+ else ; '-'
148
+ end
149
+ end
150
+
142
151
  private
143
152
 
144
153
  # to_h メソッドのオプション設定
@@ -173,6 +182,7 @@ module When
173
182
  when Range ; arg.each {|d| dates << d}
174
183
  when Symbol ; output = [arg]
175
184
  when String
185
+ arg = When::EncodingConversion.to_internal_encoding(arg)
176
186
  case arg
177
187
  when /^:(.+?)(?:\[(..)\])?$/ ; output = [$1.to_sym, $2].compact
178
188
  when /^(year|month|week)(?:\[(..)\])?$/i ; methods << [$1.downcase + '_included', $2||'SU']
@@ -217,7 +227,7 @@ module When
217
227
  #
218
228
  def _free_conv(calendars, dates, methods, output, options, &block)
219
229
  dates[0] ||= When.now
220
- calendars[0] ||= When.Calendar('Gregorian')
230
+ calendars[0] ||= When::Gregorian
221
231
  result = dates.map {|date|
222
232
  date = When.when?(date)
223
233
  opts = {}
@@ -5,6 +5,9 @@
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/parts/method_cash'
9
+ require 'when_exe/tmduration'
10
+
8
11
  #
9
12
  # 本ライブラリのための諸々の部品
10
13
  #
@@ -105,7 +108,7 @@ module When::Parts
105
108
  # 分解能がない場合は、When::SYSTEM を返す
106
109
  #
107
110
  def precision
108
- @node[0] && @node[0][0].respond_to?(:precision) ? @node[0][0].precision : Coordinates::SYSTEM
111
+ @node[0] && @node[0][0].respond_to?(:precision) ? @node[0][0].precision : When::SYSTEM
109
112
  end
110
113
 
111
114
  # 範囲を反転する
@@ -150,6 +153,16 @@ module When::Parts
150
153
  return GeometricComplex.new(copy, self.reverse)
151
154
  end
152
155
 
156
+ # 共通集合
157
+ #
158
+ # @param [Range, When::Parts::GeometricComplex] other
159
+ #
160
+ # @return [When::Parts::GeometricComplex] self と other の共通集合を返す
161
+ #
162
+ def &(other)
163
+ -(-self | -other)
164
+ end
165
+
153
166
  # ISO19108 の TM オブジェクトに変換する
154
167
  #
155
168
  # @param [Hash] options When::TM::TemporalPosition の生成を行う場合に使用する
@@ -172,6 +185,8 @@ module When::Parts
172
185
  end
173
186
  return objects[0] if objects.length==1
174
187
  return When::TM::TopologicalComplex.new(objects)
188
+ rescue NameError
189
+ raise NameError, "Please require 'when_exe' to use Temporal Objects Package"
175
190
  end
176
191
 
177
192
  # 範囲に含まれるか?
@@ -5,274 +5,220 @@
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
- #
9
- # 本ライブラリのための諸々の部品
10
- #
11
- module When::Parts
12
-
13
- #
14
- # == メソッドの実行結果をキャッシュし処理の高速化を行う
15
- #
16
- # === fn というメソッドをキャッシュ化
17
- # * fn ではなく fn_ を定義しておく
18
- # * fn メソッドが呼ばれると fn_ を実行し、{引数=>戻り値} を Hash に記憶する
19
- # * 同じ引数で再度 fn メソッドが呼ばれると Hash から戻り値を取り出して返す
20
- #
21
- # === a_to_b と b_to_a という互いに逆関数のメソッドをキャッシュ化
22
- # * a_to_b ではなく a_to_b_ , b_to_a ではなく b_to_a_ を定義しておく
23
- # * a_to_b メソッドが呼ばれると a_to_b_ を実行し、{引数=>戻り値}, {戻り値=>引数}を Hash に記憶する
24
- # * 同じ引数で再度 a_to_b メソッドが呼ばれると Hash から戻り値を取り出して返す
25
- # * b_to_a メソッドが呼ばれ Hash に戻り値があれば Hash から戻り値を取り出して返す
26
- #
27
- # == 特記事項
28
- #
29
- # === Argument identification
30
- # The eql? method of When::TM::(Temporal)Position is not overridden.
31
- # It seems that the cost of identification of the argument exceeds the merit of the method cash.
32
- # I do not recommend applying the methodcash to the method which takes
33
- # When::TM::(Temporal)Position as an argument.
8
+ module When
34
9
  #
35
- # === Multi-thread critical situation
36
- # There is a problem in consistency of hash when this function is used in multi-thread environment.
37
- # If the initialize method sets Mutex in instance variable @_m_cash_lock_,
38
- # this function gives up use of hash in the critical situation.
10
+ # 本ライブラリのための諸々の部品
39
11
  #
40
- # class Foo
41
- # include MethodCash
42
- #
43
- # def initialize
44
- # ...
45
- # @_m_cash_lock_ = Mutex.new
46
- # ...
47
- # end
48
- # end
49
- #
50
- # 参考 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/47663
51
- #
52
- module MethodCash
12
+ module Parts
53
13
 
54
- # @private
55
- Escape = {:to_str => true,
56
- :to_ary => true,
57
- :to_hash => true}
58
-
59
- class << self
14
+ #
15
+ # == メソッドの実行結果をキャッシュし処理の高速化を行う
16
+ #
17
+ # === fn というメソッドをキャッシュ化
18
+ # * fn ではなく fn_ を定義しておく
19
+ # * fn メソッドが呼ばれると fn_ を実行し、{引数=>戻り値} を Hash に記憶する
20
+ # * 同じ引数で再度 fn メソッドが呼ばれると Hash から戻り値を取り出して返す
21
+ #
22
+ # === a_to_b と b_to_a という互いに逆関数のメソッドをキャッシュ化
23
+ # * a_to_b ではなく a_to_b_ , b_to_a ではなく b_to_a_ を定義しておく
24
+ # * a_to_b メソッドが呼ばれると a_to_b_ を実行し、{引数=>戻り値}, {戻り値=>引数}を Hash に記憶する
25
+ # * 同じ引数で再度 a_to_b メソッドが呼ばれると Hash から戻り値を取り出して返す
26
+ # * b_to_a メソッドが呼ばれ Hash に戻り値があれば Hash から戻り値を取り出して返す
27
+ #
28
+ # == 特記事項
29
+ #
30
+ # === Argument identification
31
+ # The eql? method of When::TM::(Temporal)Position is not overridden.
32
+ # It seems that the cost of identification of the argument exceeds the merit of the method cash.
33
+ # I do not recommend applying the methodcash to the method which takes
34
+ # When::TM::(Temporal)Position as an argument.
35
+ #
36
+ # === Multi-thread critical situation
37
+ # There is a problem in consistency of hash when this function is used in multi-thread environment.
38
+ # If the initialize method sets Mutex in instance variable @_m_cash_lock_,
39
+ # this function gives up use of hash in the critical situation.
40
+ #
41
+ # class Foo
42
+ # include MethodCash
43
+ #
44
+ # def initialize
45
+ # ...
46
+ # @_m_cash_lock_ = Mutex.new
47
+ # ...
48
+ # end
49
+ # end
50
+ #
51
+ # 参考 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/47663
52
+ #
53
+ module MethodCash
54
+
55
+ # @private
56
+ Escape = {:to_str => true,
57
+ :to_ary => true,
58
+ :to_hash => true}
59
+
60
+ class << self
61
+
62
+ # '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
63
+ #
64
+ # @return [Boolean] キャッシュしない true, キャッシュする false/nil
65
+ #
66
+ attr_accessor :direct
67
+
68
+ # When::Parts::MethodCash のグローバルな設定を行う
69
+ #
70
+ # @param [Hash] options 以下の通り
71
+ # @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
72
+ # @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
73
+ # @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
74
+ # @option options [true] :escape すべて毎回 method_missing を発生させる
75
+ #
76
+ # @return [void]
77
+ #
78
+ # @note When::TM::Calendar クラスの一部はキャッシュ使用を前提としているため :direct=>true では動作しません
79
+ #
80
+ def _setup_(options={})
81
+ @_setup_info = options
82
+ @direct = options[:direct]
83
+ case options[:escape]
84
+ when true
85
+ instance_eval %Q{
86
+ def escape(method)
87
+ true
88
+ end
89
+ }
90
+ when Hash
91
+ @escape = Escape.merge(options[:escape])
92
+ instance_eval %Q{
93
+ def escape(method)
94
+ @escape[method]
95
+ end
96
+ }
97
+ else
98
+ instance_eval %Q{
99
+ def escape(method)
100
+ Escape.key?(method)
101
+ end
102
+ }
103
+ end
104
+ end
60
105
 
61
- # '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
62
- #
63
- # @return [Boolean] キャッシュしない true, キャッシュする false/nil
64
- #
65
- attr_accessor :direct
106
+ # 設定情報を取得する
107
+ #
108
+ # @return [Hash] 設定情報
109
+ #
110
+ def _setup_info
111
+ @_setup_info ||= {}
112
+ end
66
113
 
67
- # When::Parts::MethodCash のグローバルな設定を行う
68
- #
69
- # @param [Hash] options 以下の通り
70
- # @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
71
- # @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
72
- # @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
73
- # @option options [true] :escape すべて毎回 method_missing を発生させる
74
- #
75
- # @return [void]
76
- #
77
- # @note When::TM::Calendar クラスの一部はキャッシュ使用を前提としているため :direct=>true では動作しません
78
- #
79
- def _setup_(options={})
80
- @_setup_info = options
81
- @direct = options[:direct]
82
- case options[:escape]
83
- when true
84
- instance_eval %Q{
85
- def escape(method)
86
- true
87
- end
88
- }
89
- when Hash
90
- @escape = Escape.merge(options[:escape])
91
- instance_eval %Q{
92
- def escape(method)
93
- @escape[method]
94
- end
95
- }
96
- else
97
- instance_eval %Q{
98
- def escape(method)
99
- Escape.key?(method)
100
- end
101
- }
114
+ # method_missing メソッドを forward するか否か
115
+ #
116
+ # @param [Symbol] method メソッドシンボル
117
+ #
118
+ # @return [boolean] true - しない, false/nil - する
119
+ #
120
+ def escape(method)
121
+ Escape.key?(method)
102
122
  end
103
123
  end
104
124
 
105
- # 設定情報を取得する
106
- #
107
- # @return [Hash] 設定情報
108
- #
109
- def _setup_info
110
- @_setup_info ||= {}
111
- end
125
+ alias :method_missing_ :method_missing
112
126
 
113
- # method_missing メソッドを forward するか否か
114
127
  #
115
- # @param [Symbol] method メソッドシンボル
128
+ # 最初に発生する method_missing で、キャッシュ機能を登録する
116
129
  #
117
- # @return [boolean] true - しない, false/nil - する
130
+ # @param [Symbol] name メソッド名
131
+ # @param [Array] args メソッド引数
132
+ # @param [block] block ブロック(省略可)
118
133
  #
119
- def escape(method)
120
- Escape.key?(method)
121
- end
122
- end
123
-
124
- alias :method_missing_ :method_missing
125
-
126
- #
127
- # 最初に発生する method_missing で、キャッシュ機能を登録する
128
- #
129
- # @param [Symbol] name メソッド名
130
- # @param [Array] args メソッド引数
131
- # @param [block] block ブロック(省略可)
132
- #
133
- # @return [void]
134
- #
135
- def method_missing(name, *args, &block)
134
+ # @return [void]
135
+ #
136
+ def method_missing(name, *args, &block)
136
137
 
137
- return method_missing_(name, *args, &block) unless respond_to?("#{name}_", true)
138
- return send("#{name}_", *args, &block) if MethodCash.direct
138
+ return method_missing_(name, *args, &block) unless respond_to?("#{name}_", true)
139
+ return send("#{name}_", *args, &block) if MethodCash.direct
139
140
 
140
- if ((name.to_s =~ /^(_*)(.+?)_to_(.+)$/) && respond_to?("#{$1}#{$3}_to_#{$2}_", true))
141
- prefix, from, to = $~[1..3]
142
- begin
143
- if (@_m_cash_lock_)
144
- return send("#{prefix}#{from}_to_#{to}_", *args, &block) unless @_m_cash_lock_.try_lock
145
- unlock = "ensure ; @_m_cash_lock_.locked? && @_m_cash_lock_.unlock"
141
+ if ((name.to_s =~ /^(_*)(.+?)_to_(.+)$/) && respond_to?("#{$1}#{$3}_to_#{$2}_", true))
142
+ prefix, from, to = $~[1..3]
143
+ begin
144
+ if (@_m_cash_lock_)
145
+ return send("#{prefix}#{from}_to_#{to}_", *args, &block) unless @_m_cash_lock_.try_lock
146
+ unlock = "ensure ; @_m_cash_lock_.locked? && @_m_cash_lock_.unlock"
147
+ end
148
+ [[from, to],[to, from]].each do |pair|
149
+ a, b = pair
150
+ lock = @_m_cash_lock_ ? " return #{prefix}#{a}_to_#{b}_(*args) unless @_m_cash_lock_.try_lock" : ''
151
+ instance_eval %Q{
152
+ def #{prefix}#{a}_to_#{b}(*args)
153
+ key = _key_simplefy(args)
154
+ inv = @_m_cash_["#{prefix}#{a}_to_#{b}"][key]
155
+ return inv if inv
156
+ begin
157
+ #{lock}
158
+ inv = #{prefix}#{a}_to_#{b}_(*args)
159
+ @_m_cash_["#{prefix}#{b}_to_#{a}"][_key_simplefy(inv)] = args
160
+ @_m_cash_["#{prefix}#{a}_to_#{b}"][key] = inv
161
+ return inv
162
+ #{unlock}
163
+ end
164
+ end
165
+ }
166
+ end
167
+ key = _key_simplefy(args)
168
+ inv = send("#{prefix}#{from}_to_#{to}_", *args)
169
+ @_m_cash_ ||= {}
170
+ @_m_cash_["#{prefix}#{to}_to_#{from}"] ||= {}
171
+ @_m_cash_["#{prefix}#{from}_to_#{to}"] ||= {}
172
+ @_m_cash_["#{prefix}#{to}_to_#{from}"][_key_simplefy(inv)] = args
173
+ @_m_cash_["#{prefix}#{from}_to_#{to}"][key] = inv
174
+ return inv
175
+ ensure
176
+ @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
146
177
  end
147
- [[from, to],[to, from]].each do |pair|
148
- a, b = pair
149
- lock = @_m_cash_lock_ ? " return #{prefix}#{a}_to_#{b}_(*args) unless @_m_cash_lock_.try_lock" : ''
178
+
179
+ else
180
+ begin
181
+ respond = respond_to?("#{name}_setup", true)
182
+ setup = respond ? "#{name}_setup(key, *args)" :
183
+ "(@_m_cash_[\"#{name}\"][key] = #{name}_(*args))"
184
+ if (@_m_cash_lock_)
185
+ return send("#{name}_", *args, &block) unless @_m_cash_lock_.try_lock
186
+ lock = " return #{name}_(*args) unless @_m_cash_lock_.try_lock"
187
+ unlock = "ensure ; @_m_cash_lock_.locked? && @_m_cash_lock_.unlock"
188
+ end
150
189
  instance_eval %Q{
151
- def #{prefix}#{a}_to_#{b}(*args)
190
+ def #{name}(*args)
152
191
  key = _key_simplefy(args)
153
- inv = @_m_cash_["#{prefix}#{a}_to_#{b}"][key]
154
- return inv if inv
192
+ ret = @_m_cash_["#{name}"][key]
193
+ return ret if ret
155
194
  begin
156
195
  #{lock}
157
- inv = #{prefix}#{a}_to_#{b}_(*args)
158
- @_m_cash_["#{prefix}#{b}_to_#{a}"][_key_simplefy(inv)] = args
159
- @_m_cash_["#{prefix}#{a}_to_#{b}"][key] = inv
160
- return inv
196
+ return #{setup}
161
197
  #{unlock}
162
198
  end
163
199
  end
164
200
  }
165
- end
166
- key = _key_simplefy(args)
167
- inv = send("#{prefix}#{from}_to_#{to}_", *args)
168
- @_m_cash_ ||= {}
169
- @_m_cash_["#{prefix}#{to}_to_#{from}"] ||= {}
170
- @_m_cash_["#{prefix}#{from}_to_#{to}"] ||= {}
171
- @_m_cash_["#{prefix}#{to}_to_#{from}"][_key_simplefy(inv)] = args
172
- @_m_cash_["#{prefix}#{from}_to_#{to}"][key] = inv
173
- return inv
174
- ensure
175
- @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
176
- end
177
-
178
- else
179
- begin
180
- respond = respond_to?("#{name}_setup", true)
181
- setup = respond ? "#{name}_setup(key, *args)" :
182
- "(@_m_cash_[\"#{name}\"][key] = #{name}_(*args))"
183
- if (@_m_cash_lock_)
184
- return send("#{name}_", *args, &block) unless @_m_cash_lock_.try_lock
185
- lock = " return #{name}_(*args) unless @_m_cash_lock_.try_lock"
186
- unlock = "ensure ; @_m_cash_lock_.locked? && @_m_cash_lock_.unlock"
187
- end
188
- instance_eval %Q{
189
- def #{name}(*args)
190
- key = _key_simplefy(args)
191
- ret = @_m_cash_["#{name}"][key]
192
- return ret if ret
193
- begin
194
- #{lock}
195
- return #{setup}
196
- #{unlock}
197
- end
198
- end
199
- }
200
- key = _key_simplefy(args)
201
- @_m_cash_ ||= {}
202
- @_m_cash_["#{name}"] ||= {}
203
- if (respond)
204
- return send("#{name}_setup", key, *args)
205
- else
206
- return(@_m_cash_["#{name}"][key] ||= send("#{name}_", *args))
207
- end
208
- ensure
209
- @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
210
- end
211
- end
212
- end
213
-
214
- private
215
-
216
- def _key_simplefy(args)
217
- key = args.kind_of?(Array) ? args.dup : args
218
- key = key[0] while key.kind_of?(Array) && key.length<=1
219
- return key
220
- end
221
- end
222
-
223
- #
224
- # デバッグのためのオブジェクト内部記録用
225
- # @private
226
- module SnapShot
227
-
228
- @@depth = 2
229
-
230
- class << self
231
- def _default(depth=2)
232
- @@depth = depth
233
- end
234
-
235
- def _snapshot(object, depth=@@depth, processed={})
236
- obj = object.dup rescue (return object)
237
- # def obj.is_snapshoted? ; true ; end
238
- if (depth==0 || processed.key?(object))
239
- return object if object.instance_of?(String)
240
- string = object.to_s
241
- string = "<##{object.class}>" + string unless (string =~ /^#</)
242
- return string
243
- else
244
- object.instance_variables.each do |v|
245
- if ((v =~ /^@_/) && object.kind_of?(SnapShot))
246
- obj._remove_instance_variable(v)
201
+ key = _key_simplefy(args)
202
+ @_m_cash_ ||= {}
203
+ @_m_cash_["#{name}"] ||= {}
204
+ if (respond)
205
+ return send("#{name}_setup", key, *args)
247
206
  else
248
- src = object.instance_variable_get(v)
249
- case src
250
- when Array
251
- val = src.map {|e| _snapshot(e, depth-1, processed)}
252
- when Hash
253
- val = {}
254
- src.each_pair {|k,c| val[_snapshot(k, depth-1, processed)] = _snapshot(c, depth-1, processed)}
255
- else
256
- val = _snapshot(src, depth-1, processed)
257
- end
258
- obj.instance_variable_set(v, val)
207
+ return(@_m_cash_["#{name}"][key] ||= send("#{name}_", *args))
259
208
  end
209
+ ensure
210
+ @_m_cash_lock_ && @_m_cash_lock_.locked? && @_m_cash_lock_.unlock
260
211
  end
261
- processed[object] = true
262
212
  end
263
- return obj
264
213
  end
265
- end
266
214
 
267
- def _snapshot(depth=@@depth, processed={})
268
- SnapShot._snapshot(self, depth, processed)
269
- end
215
+ private
270
216
 
271
- private
272
-
273
- def _remove_instance_variable(name)
274
- remove_instance_variable(name) if (name =~ /^@_/)
217
+ def _key_simplefy(args)
218
+ key = args.kind_of?(Array) ? args.dup : args
219
+ key = key[0] while key.kind_of?(Array) && key.length<=1
220
+ return key
221
+ end
275
222
  end
276
223
  end
277
- # module Resource ; include SnapShot ; end
278
224
  end