when_exe 0.3.2 → 0.3.3

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 (93) hide show
  1. data/LICENSE.ja.txt +25 -25
  2. data/LICENSE.txt +31 -31
  3. data/bin/locales.rb +2 -1
  4. data/bin/when.rb.config +1 -1
  5. data/lib/when_exe.rb +70 -48
  6. data/lib/when_exe/basictypes.rb +99 -65
  7. data/lib/when_exe/calendartypes.rb +40 -178
  8. data/lib/when_exe/coordinates.rb +156 -62
  9. data/lib/when_exe/core/compatibility.rb +10 -0
  10. data/lib/when_exe/core/extension.rb +40 -0
  11. data/lib/when_exe/ephemeris.rb +112 -50
  12. data/lib/when_exe/icalendar.rb +125 -91
  13. data/lib/when_exe/inspect.rb +100 -48
  14. data/lib/when_exe/locales/ar.rb +48 -48
  15. data/lib/when_exe/locales/bg.rb +1 -1
  16. data/lib/when_exe/locales/bs.rb +4 -2
  17. data/lib/when_exe/locales/ca.rb +1 -1
  18. data/lib/when_exe/locales/en_CA.rb +3 -4
  19. data/lib/when_exe/locales/en_IE.rb +88 -0
  20. data/lib/when_exe/locales/en_US.rb +87 -0
  21. data/lib/when_exe/locales/es_CR.rb +84 -0
  22. data/lib/when_exe/locales/es_EC.rb +85 -0
  23. data/lib/when_exe/locales/es_PA.rb +85 -0
  24. data/lib/when_exe/locales/fr.rb +39 -39
  25. data/lib/when_exe/locales/hu.rb +15 -14
  26. data/lib/when_exe/locales/it.rb +1 -1
  27. data/lib/when_exe/locales/ja.rb +2 -2
  28. data/lib/when_exe/locales/locales.rb +7 -0
  29. data/lib/when_exe/locales/lt.rb +21 -19
  30. data/lib/when_exe/locales/ms.rb +84 -0
  31. data/lib/when_exe/locales/nl.rb +2 -2
  32. data/lib/when_exe/locales/ru.rb +1 -1
  33. data/lib/when_exe/locales/uk.rb +1 -1
  34. data/lib/when_exe/locales/ur.rb +84 -0
  35. data/lib/when_exe/mini_application.rb +44 -43
  36. data/lib/when_exe/parts/enumerator.rb +3 -3
  37. data/lib/when_exe/parts/geometric_complex.rb +6 -1
  38. data/lib/when_exe/parts/locale.rb +49 -18
  39. data/lib/when_exe/parts/method_cash.rb +61 -0
  40. data/lib/when_exe/parts/resource.rb +221 -106
  41. data/lib/when_exe/parts/timezone.rb +70 -33
  42. data/lib/when_exe/region/bahai.rb +2 -2
  43. data/lib/when_exe/region/balinese.rb +40 -43
  44. data/lib/when_exe/region/chinese.rb +93 -33
  45. data/lib/when_exe/region/chinese_calendar.rb +117 -1
  46. data/lib/when_exe/region/chinese_epoch.rb +65 -10
  47. data/lib/when_exe/region/christian.rb +97 -2
  48. data/lib/when_exe/region/ephemeric_notes.rb +353 -0
  49. data/lib/when_exe/region/french.rb +1 -1
  50. data/lib/when_exe/region/geologicalage.rb +171 -171
  51. data/lib/when_exe/region/indian.rb +18 -14
  52. data/lib/when_exe/region/iranian.rb +1 -1
  53. data/lib/when_exe/region/japanese.rb +49 -12
  54. data/lib/when_exe/region/japanese_notes.rb +838 -507
  55. data/lib/when_exe/region/japanese_residues.rb +724 -662
  56. data/lib/when_exe/region/javanese.rb +7 -7
  57. data/lib/when_exe/region/mayan.rb +19 -17
  58. data/lib/when_exe/region/nihon_shoki.rb +3 -3
  59. data/lib/when_exe/region/residue.rb +29 -28
  60. data/lib/when_exe/region/shire.rb +2 -2
  61. data/lib/when_exe/region/tibetan.rb +87 -5
  62. data/lib/when_exe/region/world.rb +1 -1
  63. data/lib/when_exe/timestandard.rb +85 -7
  64. data/lib/when_exe/tmobjects.rb +32 -4
  65. data/lib/when_exe/tmposition.rb +104 -55
  66. data/lib/when_exe/tmreference.rb +157 -60
  67. data/lib/when_exe/version.rb +2 -2
  68. data/test/examples/JapanHolidays.ics +3 -3
  69. data/test/examples/JapanHolidaysRFC6350.ics +499 -0
  70. data/test/examples/Residue.m17n +3 -2
  71. data/test/examples/Spatial.m17n +3 -3
  72. data/test/examples/USA-DST.ics +27 -27
  73. data/test/examples/today.rb +1 -1
  74. data/test/test.rb +4 -2
  75. data/test/test/basictypes.rb +40 -15
  76. data/test/test/coordinates.rb +9 -4
  77. data/test/test/icalendar.rb +24 -14
  78. data/test/test/inspect.rb +5 -3
  79. data/test/test/parts.rb +11 -2
  80. data/test/test/region/chinese.rb +4 -4
  81. data/test/test/region/civil.rb +124 -0
  82. data/test/test/region/geologicalage.rb +5 -2
  83. data/test/test/region/indian.rb +2 -0
  84. data/test/test/region/japanese.rb +156 -1
  85. data/test/test/region/jewish.rb +3 -3
  86. data/test/test/region/m17n.rb +9 -9
  87. data/test/test/region/mayan.rb +122 -5
  88. data/test/test/region/residue.rb +1 -1
  89. data/test/test/tmobjects.rb +27 -64
  90. data/test/test/tmposition.rb +48 -1
  91. data/test/test/tmreference.rb +66 -4
  92. data/when_exe.gemspec +1 -1
  93. metadata +15 -6
@@ -12,7 +12,7 @@ module When::BasicTypes
12
12
 
13
13
  Locale_nl =
14
14
  {"date"=>
15
- {"abbr_day_names"=>["zon", "maa", "din", "woe", "don", "vri", "zat"],
15
+ {"abbr_day_names"=>["zo", "ma", "di", "wo", "do", "vr", "za"],
16
16
  "abbr_month_names"=>
17
17
  [nil,
18
18
  "jan",
@@ -35,7 +35,7 @@ module When::BasicTypes
35
35
  "donderdag",
36
36
  "vrijdag",
37
37
  "zaterdag"],
38
- "formats"=>{"default"=>"%d/%m/%Y", "long"=>"%e %B %Y", "short"=>"%e %b"},
38
+ "formats"=>{"default"=>"%d-%m-%Y", "long"=>"%e %B %Y", "short"=>"%e %b"},
39
39
  "month_names"=>
40
40
  [nil,
41
41
  "januari",
@@ -35,7 +35,7 @@ module When::BasicTypes
35
35
  "четверг",
36
36
  "пятница",
37
37
  "суббота"],
38
- "formats"=>{"default"=>"%d.%m.%Y", "long"=>"%d %B %Y", "short"=>"%d %b"},
38
+ "formats"=>{"default"=>"%d.%m.%Y", "long"=>"%-d %B %Y", "short"=>"%-d %b"},
39
39
  "month_names"=>
40
40
  [nil,
41
41
  "января",
@@ -35,7 +35,7 @@ module When::BasicTypes
35
35
  "четвер",
36
36
  "п'ятниця",
37
37
  "субота"],
38
- "formats"=>{"default"=>"%d.%m.%Y", "long"=>"%d %B %Y", "short"=>"%d %b"},
38
+ "formats"=>{"default"=>"%d.%m.%Y", "long"=>"%-d %B %Y", "short"=>"%-d %b"},
39
39
  "month_names"=>
40
40
  [nil,
41
41
  "Січень",
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2012-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
+ module When::BasicTypes
9
+ class M17n
10
+
11
+ # from https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/ur.yml
12
+
13
+ Locale_ur =
14
+ {"date"=>
15
+ {"abbr_day_names"=>
16
+ ["اتوار", "سوموار", "منگل", "ندھ", "جمعرات", "جمعہ", "ہفتہ"],
17
+ "abbr_month_names"=>
18
+ [nil,
19
+ "جنوری",
20
+ "فروری",
21
+ "مارچ",
22
+ "اپریل",
23
+ "مئی",
24
+ "جون",
25
+ "جولائی",
26
+ "اگست",
27
+ "ستمبر",
28
+ "اکتوبر",
29
+ "نومبر",
30
+ "دسمبر"],
31
+ "day_names"=>["اتوار", "سوموار", "منگل", "ندھ", "جمعرات", "جمعہ", "ہفتہ"],
32
+ "formats"=>{"default"=>"%d %B %Y", "long"=>"%B %d، %Y", "short"=>"%d %b"},
33
+ "month_names"=>
34
+ [nil,
35
+ "جنوری",
36
+ "فروری",
37
+ "مارچ",
38
+ "اپریل",
39
+ "مئی",
40
+ "جون",
41
+ "جولائی",
42
+ "اگست",
43
+ "ستمبر",
44
+ "اکتوبر",
45
+ "نومبر",
46
+ "دسمبر"],
47
+ "order"=>[:day, :month, :year]},
48
+ "time"=>
49
+ {"am"=>"صبح",
50
+ "pm"=>"شام",
51
+ "formats"=>
52
+ {"default"=>"%a، %d %b %Y، %p %l:%M %Z",
53
+ "long"=>"%B %d، %Y %p %H:%M",
54
+ "short"=>"%d %b، %H:%M"}},
55
+ "datetime"=>
56
+ {"distance_in_words"=>
57
+ {"about_x_hours"=>
58
+ {"one"=>"تقریبا ایک گھنٹہ", "other"=>"تقریبا %{count} گھنٹے"},
59
+ "about_x_months"=>
60
+ {"one"=>"تقریبا ایک مہینہ", "other"=>"تقریبا %{count} مہینہ"},
61
+ "about_x_years"=>
62
+ {"one"=>"تقریبا ایک سال", "other"=>"تقریبا %{count} سال"},
63
+ "almost_x_years"=>
64
+ {"one"=>"تقریبا ایک سال", "other"=>"تقریبا %{count} سال"},
65
+ "half_a_minute"=>"آدھا منٹ",
66
+ "less_than_x_minutes"=>
67
+ {"one"=>"ایک مںٹ سے کم", "other"=>"%{count} مںٹوں سے کم"},
68
+ "less_than_x_seconds"=>
69
+ {"one"=>"ایک سیکنڈ سے کم", "other"=>"%{count} سیکنڈوں سے کم"},
70
+ "over_x_years"=>
71
+ {"one"=>"ایک سال سے زیادہ", "other"=>"%{count} سالوں سے زیادہ"},
72
+ "x_days"=>{"one"=>"ایک دن", "other"=>"%{count} دن"},
73
+ "x_minutes"=>{"one"=>"ایک منٹ", "other"=>"%{count} منٹ"},
74
+ "x_months"=>{"one"=>"ایک ماہ", "other"=>"%{count} ماہ"},
75
+ "x_seconds"=>{"one"=>"ایک سیکنڈ", "other"=>"%{count} سیکنڈ"}},
76
+ "prompts"=>
77
+ {"day"=>"دن",
78
+ "hour"=>"گہنٹہ",
79
+ "minute"=>"منٹ",
80
+ "month"=>"ماہ",
81
+ "second"=>"سیکنڈ",
82
+ "year"=>"سال"}}}
83
+ end
84
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2013 Takashi SUGA
3
+ Copyright (C) 2013-2014 Takashi SUGA
4
4
 
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
@@ -102,40 +102,6 @@ module When
102
102
  end
103
103
  end
104
104
 
105
- # JSONで通信するために Symbol を String に変換する
106
- def _to_string(source)
107
- case source
108
- when Array
109
- source.map {|e| _to_string(e)}
110
- when Hash
111
- result = {}
112
- source.each_pair {|k,v|
113
- result[k.kind_of?(Symbol) ? '_sym_' + k.to_s : k] = _to_string(v)
114
- }
115
- result
116
- else
117
- source
118
- end
119
- end
120
- private :_to_string
121
-
122
- # JSONで通信するために String を Symbol に変換する
123
- def _to_symbol(source)
124
- case source
125
- when Array
126
- source.map {|e| _to_symbol(e)}
127
- when Hash
128
- result = {}
129
- source.each_pair {|k,v|
130
- result[k =~ /^_sym_(.+)$/ ? $1.to_sym : k] = _to_symbol(v)
131
- }
132
- result
133
- else
134
- source
135
- end
136
- end
137
- private :_to_symbol
138
-
139
105
  # 日付の自由変換
140
106
  #
141
107
  # @param [Array<String>] args コマンドライン入力
@@ -148,7 +114,7 @@ module When
148
114
  # @note mini_application
149
115
  #
150
116
  def free_conv(*args, &block)
151
- calendars, dates, numbers, methods, output, options = _parse(args)
117
+ calendars, dates, numbers, methods, output, options = _parse_command(args)
152
118
 
153
119
  if numbers.size >= 2 && calendars.size == 0
154
120
  result = []
@@ -173,6 +139,8 @@ module When
173
139
  _free_conv(calendars, dates, methods, output, options, &block)
174
140
  end
175
141
 
142
+ private
143
+
176
144
  # 引数読み込み
177
145
  #
178
146
  # args [String] コマンドライン入力
@@ -185,8 +153,7 @@ module When
185
153
  # [ output [Array<Symbol, String>] 出力処理に使うメソッドのシンボルと引数 ]
186
154
  # [ options [Hash{ :extent=>Boolean, :go_back=><:All || :Before(nil) || :After> }]
187
155
  #
188
- # @private
189
- def _parse(args)
156
+ def _parse_command(args)
190
157
  calendars = []
191
158
  dates = []
192
159
  numbers = []
@@ -244,16 +211,18 @@ module When
244
211
  #
245
212
  # @return [Array] 変換結果
246
213
  #
247
- # @private
248
214
  def _free_conv(calendars, dates, methods, output, options, &block)
249
215
  dates[0] ||= When.now
250
216
  calendars[0] ||= When.Calendar('Gregorian')
251
217
  result = dates.map {|date|
252
218
  date = When.when?(date)
219
+ opts = {}
220
+ opts[:location] = date.location if date.location
221
+ opts[:clock ] = date.clock if date.respond_to?(:clock) && date.clock
253
222
  list = calendars.dup
254
223
  (0...calendars.size).to_a.reverse.each do |i|
255
224
  case list[i]
256
- when When::TM::Calendar ; list.slice!(i) if options[:extent] && !list[i].domain.include?(date)
225
+ when When::TM::Calendar ; list.slice!(i) if options[:extent] && !list[i].domain[''].include?(date)
257
226
  when Class ;
258
227
  else
259
228
  eras = (date ^ list[i]).delete_if {|e| !e.leaf?}
@@ -271,12 +240,12 @@ module When
271
240
  if methods.size == 0
272
241
  list.map {|calendar|
273
242
  calendar.kind_of?(Class) ?
274
- yield(calendar.new(date)) :
275
- yield(calendar ^ (calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date))
243
+ yield(calendar.new(date, opts.dup)) :
244
+ yield(calendar.^(calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date, opts))
276
245
  }
277
246
  else
278
247
  list.map {|calendar|
279
- date_for_calendar = calendar ^ (calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date)
248
+ date_for_calendar = calendar.^(calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date, opts)
280
249
  methods.map {|method|
281
250
  date_for_calendar.send(method[0].to_sym, method[1], &block)
282
251
  }
@@ -286,5 +255,37 @@ module When
286
255
  result = result[0] while result.kind_of?(Array) && result.size == 1
287
256
  return result
288
257
  end
258
+
259
+ # JSONで通信するために Symbol を String に変換する
260
+ def _to_string(source)
261
+ case source
262
+ when Array
263
+ source.map {|e| _to_string(e)}
264
+ when Hash
265
+ result = {}
266
+ source.each_pair {|k,v|
267
+ result[k.kind_of?(Symbol) ? '_sym_' + k.to_s : k] = _to_string(v)
268
+ }
269
+ result
270
+ else
271
+ source
272
+ end
273
+ end
274
+
275
+ # JSONで通信するために String を Symbol に変換する
276
+ def _to_symbol(source)
277
+ case source
278
+ when Array
279
+ source.map {|e| _to_symbol(e)}
280
+ when Hash
281
+ result = {}
282
+ source.each_pair {|k,v|
283
+ result[k =~ /^_sym_(.+)$/ ? $1.to_sym : k] = _to_symbol(v)
284
+ }
285
+ result
286
+ else
287
+ source
288
+ end
289
+ end
289
290
  end
290
291
  end
@@ -262,7 +262,7 @@ module When::Parts
262
262
  def _range(args)
263
263
  if (args[0].instance_of?(Range))
264
264
  range, @count_limit, others = args
265
- raise ArgumentError, "Too many arguments" if (others)
265
+ raise ArgumentError, "Too many arguments" if others
266
266
  @first = When.when?(range.first)
267
267
  @last = When.when?(range.last)
268
268
  @exdate |= @last if (range.exclude_end?)
@@ -274,8 +274,8 @@ module When::Parts
274
274
  end
275
275
  else
276
276
  @first, @direction, @count_limit, others = args
277
- raise ArgumentError, "Too many arguments" if (others)
278
- raise ArgumentError, "Too few arguments" unless (@first)
277
+ raise ArgumentError, "Too many arguments" if others
278
+ raise ArgumentError, "Too few arguments" unless @first
279
279
  @direction ||= :forward
280
280
  @last = nil
281
281
  end
@@ -373,7 +373,12 @@ module When::Parts
373
373
  # 処理を first (type: When::TM::(Temporal)Position) に委譲する
374
374
  #
375
375
  def method_missing(name, *args, &block)
376
- first.send(name.to_sym, *args, &block)
376
+ self.class.module_eval %Q{
377
+ def #{name}(*args, &block)
378
+ first.send("#{name}", *args, &block)
379
+ end
380
+ } unless When::Parts::MethodCash.escape(name)
381
+ first.send(name, *args, &block)
377
382
  end
378
383
  end
379
384
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2012 Takashi SUGA
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
4
 
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
@@ -45,8 +45,14 @@ module When::Parts
45
45
  '竜' => '龍',
46
46
  }
47
47
 
48
+ # Escape
48
49
  # @private
49
- Escape = '__!_ESCAPE_%2C_!__'
50
+ Escape = {
51
+ "\\\\" => "\\",
52
+ "\\n" => "\n",
53
+ "\\r" => "\r",
54
+ "\\," => ","
55
+ }
50
56
 
51
57
  class << self
52
58
 
@@ -128,8 +134,8 @@ module When::Parts
128
134
  # @private
129
135
  def _namespace(source=nil)
130
136
  case source
131
- when Hash ; return source
132
- when nil ; return {}
137
+ when Hash ; source
138
+ when nil ; {}
133
139
  when String
134
140
  namespace = {}
135
141
  source = $1 if (source=~/\A\s*\[?(.+?)\]?\s*\z/m)
@@ -139,8 +145,10 @@ module When::Parts
139
145
  pair = [''] + v.split(/\s*=\s*/, 2)
140
146
  namespace[pair[-2]] = pair[-1]
141
147
  end
142
- return namespace
143
- else ; raise TypeError, "Irregal Namespace Type"
148
+ namespace
149
+ when When::Parts::Resource::ContentLine
150
+ source.object.names
151
+ else ; raise TypeError, "Irregal Namespace Type: #{source.class}"
144
152
  end
145
153
  end
146
154
 
@@ -153,7 +161,9 @@ module When::Parts
153
161
  # source の配列化
154
162
  if source.kind_of?(String)
155
163
  source = $1 if (source=~/\A\s*\[?(.+?)\]?\s*\z/m)
156
- source = source.split(/[\n\r,]+/)
164
+ source = source.scan(/((?:[^\\\n\r,]|\\.)+)(?:[\n\r,]+(?!\z))?|[\n\r,]+/m).flatten.map {|token|
165
+ (token||'').gsub(/\\./) {|escape| Escape[escape] || escape}
166
+ }
157
167
  end
158
168
 
159
169
  # 各Localeの展開
@@ -170,10 +180,12 @@ module When::Parts
170
180
 
171
181
  # 文字列 [.., .., ..] を分割する
172
182
  # @private
173
- def _split(line)
174
- line = line.dup
183
+ def _split(source)
184
+ line = source.dup
185
+ return [line] unless line =~ /,/
186
+ list = []
175
187
  b = d = s = 0
176
- (line.length-1).downto(0) do |i|
188
+ (source.length-1).downto(0) do |i|
177
189
  bs = 0
178
190
  (i-1).downto(0) do |k|
179
191
  break unless (line[k,1] == '\\')
@@ -181,14 +193,18 @@ module When::Parts
181
193
  end
182
194
  next if (bs[0] == 1)
183
195
  case line[i,1]
184
- when "'" ; s = 1-s if (d == 0)
185
- when '"' ; d = 1-d if (s == 0)
186
- when ']' ; b += 1 if (d+s == 0)
187
- when '[' ; b -= 1 if (d+s == 0 && b > 0)
188
- when ',' ; line[i,1] = Escape if (b+d+s == 0)
196
+ when "'" ; s = 1-s if (d == 0)
197
+ when '"' ; d = 1-d if (s == 0)
198
+ when ']','}',')' ; b += 1 if (d+s == 0)
199
+ when '[','{','(' ; b -= 1 if (d+s == 0 && b > 0)
200
+ when ','
201
+ if (b+d+s == 0)
202
+ list.unshift(line[i+1..-1])
203
+ line = i > 0 ? line[0..i-1] : ''
204
+ end
189
205
  end
190
206
  end
191
- return (line =='') ? [''] : line.split(Escape, -1)
207
+ list.unshift(line)
192
208
  end
193
209
 
194
210
  # locale 指定を解析して Hash の値を取り出す
@@ -299,6 +315,21 @@ module When::Parts
299
315
  return nil
300
316
  end
301
317
 
318
+ # 部分文字列の位置
319
+ #
320
+ # @param [String] other 部分文字列
321
+ #
322
+ # @return [Integer] 部分文字列の先頭のindex(いずれかの locale で部分文字列を含んだ場合)
323
+ # @return [nil] すべての locale で部分文字列を含まない場合
324
+ #
325
+ def index(other)
326
+ @keys.each do |key|
327
+ index = @names[key].index(Locale.translate(other, key))
328
+ return index if index
329
+ end
330
+ return nil
331
+ end
332
+
302
333
  # 文字列の連結
303
334
  #
304
335
  # @param [String, When::Toos::Locale] other 連結する文字列
@@ -493,7 +524,7 @@ module When::Parts
493
524
  case v
494
525
  when '', /^#/ ;
495
526
  when /^\/(.+)/; @access_key = $1
496
- when /^(\*)?(?:([^=%]*?)\s*:)?\s*(.+?)\s*(=\s*(.+?)?)?$/
527
+ when /^(\*)?(?:([^=%]*?)\s*:)?\s*(.+?)\s*(=\s*([^=]+?)?)?$/
497
528
  asterisk[0], locale, name, assignment, ref = $~[1..5]
498
529
  asterisk[1], locale, default_ref = default_locale.shift unless locale
499
530
  locale ||= ''
@@ -523,7 +554,7 @@ module When::Parts
523
554
  # encode URI from patterns %%(...) or %.(...)
524
555
  def _encode(source)
525
556
  source.gsub(/%.<.+?>/) do |match|
526
- URI.encode(match[3..-2].gsub(match[1], '%'))
557
+ URI.encode(match[3..-2]).gsub('%', match[1..1])
527
558
  end
528
559
  end
529
560
  end
@@ -51,6 +51,66 @@ module When::Parts
51
51
  #
52
52
  module MethodCash
53
53
 
54
+ # @private
55
+ Escape = {:to_str => true,
56
+ :to_ary => true,
57
+ :to_hash => true}
58
+
59
+ class << self
60
+
61
+ # '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
62
+ #
63
+ # @return [Boolean] キャッシュしない true, キャッシュする false/nil
64
+ #
65
+ attr_accessor :direct
66
+
67
+ # When::Parts::MethodCash のグローバルな設定を行う
68
+ #
69
+ # @param [Boolean] direct '_' で終わるメソッドをキャッシュせずに毎回計算する場合 true, キャッシュする場合 false/nil
70
+ # @param [Hash{Symbol=>boolean}] escape 毎回 method_missing を発生させるメソッドを true にして指定
71
+ # @param [false, nil] escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
72
+ # @param [true] escape すべて毎回 method_missing を発生させる
73
+ #
74
+ # @return [void]
75
+ #
76
+ # @note When::TM::Calendar クラスの一部はキャッシュ使用を前提としているため direct=true では動作しません
77
+ #
78
+ def _setup_(direct=false, escape=false)
79
+ @direct = direct
80
+ case escape
81
+ when true
82
+ instance_eval %Q{
83
+ def escape(method)
84
+ true
85
+ end
86
+ }
87
+ when Hash
88
+ @escape = Escape.merge(escape)
89
+ instance_eval %Q{
90
+ def escape(method)
91
+ @escape[method]
92
+ end
93
+ }
94
+ else
95
+ instance_eval %Q{
96
+ def escape(method)
97
+ Escape.key?(method)
98
+ end
99
+ }
100
+ end
101
+ end
102
+
103
+ # method_missing メソッドを forward するか否か
104
+ #
105
+ # @param [Symbol] method メソッドシンボル
106
+ #
107
+ # @return [boolean] true - しない, false/nil - する
108
+ #
109
+ def escape(method)
110
+ Escape.key?(method)
111
+ end
112
+ end
113
+
54
114
  alias :method_missing_ :method_missing
55
115
 
56
116
  #
@@ -65,6 +125,7 @@ module When::Parts
65
125
  def method_missing(name, *args, &block)
66
126
 
67
127
  return method_missing_(name, *args, &block) unless respond_to?("#{name}_", true)
128
+ return send("#{name}_", *args, &block) if MethodCash.direct
68
129
 
69
130
  if ((name.to_s =~ /^(_*)(.+?)_to_(.+)$/) && respond_to?("#{$1}#{$3}_to_#{$2}_", true))
70
131
  prefix, from, to = $~[1..3]