Module: Fugit::Nat::Parser
- Includes:
- Raabro
- Defined in:
- lib/fugit/nat.rb
Constant Summary collapse
- NHOURS =
sixties[0, 13] .each_with_index .inject({}) { |h, (n, i)| h[n] = i; h } .merge!( 'midnight' => 0, 'oh' => 0, 'noon' => 12) .freeze
- NMINUTES =
sixties .each_with_index .inject({}) { |h, (n, i)| h[n] = i; h } .merge!( "o'clock" => 0, 'hundred' => 0) .freeze
- WEEKDAYS =
( Fugit::Cron::Parser::WEEKDAYS + Fugit::Cron::Parser::WEEKDS).freeze
- POINTS =
%w[ minutes? mins? seconds? secs? hours? hou h ].freeze
- INTERVALS =
%w[ seconds? minutes? hours? days? months? sec min s m h d M ].freeze
- OMONTHDAYS =
oh.freeze
- OMONTHDAY_REX =
/#{OMONTHDAYS.keys.join('|')}/i.freeze
- MONTHDAY_REX =
/3[0-1]|[0-2]?[0-9]/.freeze
- WEEKDAY_REX =
/(#{WEEKDAYS.join('|')})(?=($|[-, \t]))/i.freeze
- NAMED_M_REX =
prevent “mon” from eating “monday”
/#{NMINUTES.keys.join('|')}/i.freeze
- NAMED_H_REX =
/#{NHOURS.keys.join('|')}/i.freeze
- POINT_REX =
/(#{POINTS.join('|')})[ \t]+/i.freeze
- INTERVAL_REX =
/[ \t]*(#{INTERVALS.join('|')})/.freeze
Instance Method Summary collapse
- #_and(i) ⇒ Object
- #_and_or_or(i) ⇒ Object
- #_and_or_or_or_comma(i) ⇒ Object
- #_at(i) ⇒ Object
- #_day_s(i) ⇒ Object
- #_dmin(i) ⇒ Object
-
#_every(i) ⇒ Object
parsers bottom to top #################################################.
- #_from(i) ⇒ Object
- #_in_or_on(i) ⇒ Object
- #_minute(i) ⇒ Object
- #_on(i) ⇒ Object
- #_point(i) ⇒ Object
- #_rewrite_sub(t, key = nil) ⇒ Object
- #_rewrite_subs(t, key = nil) ⇒ Object
- #_sep(i) ⇒ Object
- #_space(i) ⇒ Object
- #_the(i) ⇒ Object
- #_to(i) ⇒ Object
- #_to_or_dash(i) ⇒ Object
- #adjust_h(h, m, ap) ⇒ Object
- #ampm(i) ⇒ Object
- #and_dmin(i) ⇒ Object
- #at(i) ⇒ Object
-
#at_object(i) ⇒ Object
at five at five pm at five o’clock at 16:30 at noon at 18:00 UTC <– …tz.
- #at_objects(i) ⇒ Object
- #at_p(i) ⇒ Object
- #at_point(i) ⇒ Object
- #city_tz(i) ⇒ Object
- #count(i) ⇒ Object
- #counts(i) ⇒ Object
- #dark(i) ⇒ Object
- #delta_tz(i) ⇒ Object
- #digital_h(i) ⇒ Object
- #digital_hour(i) ⇒ Object
- #every(i) ⇒ Object
-
#every_interval(i) ⇒ Object
every day every 1 minute.
- #every_named(i) ⇒ Object
- #every_object(i) ⇒ Object
- #every_objects(i) ⇒ Object
-
#every_of_the_month(i) ⇒ Object
every 1st of the month every first of the month Every 2nd of the month Every second of the month every 15th of the month.
- #every_single_interval(i) ⇒ Object
-
#every_weekday(i) ⇒ Object
every monday every Fri-Sun every Monday and Tuesday.
- #from(i) ⇒ Object
- #from_object(i) ⇒ Object
- #from_objects(i) ⇒ Object
- #interval(i) ⇒ Object
- #monthday(i) ⇒ Object
- #monthdays(i) ⇒ Object
- #named_h(i) ⇒ Object
- #named_hour(i) ⇒ Object
- #named_m(i) ⇒ Object
- #named_min(i) ⇒ Object
- #named_tz(i) ⇒ Object
- #nat(i) ⇒ Object
- #nat_elt(i) ⇒ Object
- #omonthday(i) ⇒ Object
- #omonthdays(i) ⇒ Object
-
#on(i) ⇒ Object
‘every month on day 2 at 10:00’ => ‘0 10 2 * *’, ‘every month on day 2 and 5 at 10:00’ => ‘0 10 2,5 * *’, ‘every month on days 1,15 at 10:00’ => ‘0 10 1,15 * *’,.
- #on_days(i) ⇒ Object
- #on_minutes(i) ⇒ Object
- #on_object(i) ⇒ Object
- #on_objects(i) ⇒ Object
- #on_the(i) ⇒ Object
- #on_thes(i) ⇒ Object
- #on_thex(i) ⇒ Object
- #on_weekdays(i) ⇒ Object
- #otm(i) ⇒ Object
- #rewrite_at(t) ⇒ Object
- #rewrite_at_p(t) ⇒ Object
- #rewrite_digital_hour(t) ⇒ Object
- #rewrite_dmin(t) ⇒ Object
- #rewrite_every(t) ⇒ Object
- #rewrite_every_interval(t) ⇒ Object
- #rewrite_every_named(t) ⇒ Object
- #rewrite_every_single_interval(t) ⇒ Object
- #rewrite_monthday(t) ⇒ Object
- #rewrite_named_hour(t) ⇒ Object
- #rewrite_nat(t) ⇒ Object
- #rewrite_omonthday(t) ⇒ Object
- #rewrite_on(t) ⇒ Object
- #rewrite_on_days(t) ⇒ Object
- #rewrite_on_minutes(t) ⇒ Object
- #rewrite_on_thes(t) ⇒ Object
- #rewrite_on_thex(t) ⇒ Object
- #rewrite_simple_hour(t) ⇒ Object
- #rewrite_to_hour(t) ⇒ Object
- #rewrite_to_omonthday(t) ⇒ Object
- #rewrite_to_weekday(t) ⇒ Object
- #rewrite_tz(t) ⇒ Object
- #rewrite_weekday(t) ⇒ Object
- #rewrite_weekdays(t) ⇒ Object (also: #rewrite_on_weekdays)
- #simple_h(i) ⇒ Object
- #simple_hour(i) ⇒ Object
-
#slot(key, data0, data1 = nil, opts = nil) ⇒ Object
rewrite parsed tree ###################################################.
- #to_hour(i) ⇒ Object
- #to_omonthday(i) ⇒ Object
- #to_weekday(i) ⇒ Object
- #tz(i) ⇒ Object
- #tzone(i) ⇒ Object
- #weekday(i) ⇒ Object
- #weekday_range(i) ⇒ Object
- #weekdays(i) ⇒ Object
Instance Method Details
#_and(i) ⇒ Object
121 |
# File 'lib/fugit/nat.rb', line 121 def _and(i); rex(nil, i, /[ \t]*and[ \t]+/i); end |
#_and_or_or(i) ⇒ Object
122 |
# File 'lib/fugit/nat.rb', line 122 def _and_or_or(i); rex(nil, i, /[ \t]*(and|or)[ \t]+/i); end |
#_and_or_or_or_comma(i) ⇒ Object
125 126 |
# File 'lib/fugit/nat.rb', line 125 def _and_or_or_or_comma(i) rex(nil, i, /[ \t]*(,[ \t]*)?((and|or)[ \t]+|,[ \t]*)/i); end |
#_at(i) ⇒ Object
117 |
# File 'lib/fugit/nat.rb', line 117 def _at(i); rex(nil, i, /[ \t]*at[ \t]+/i); end |
#_day_s(i) ⇒ Object
131 |
# File 'lib/fugit/nat.rb', line 131 def _day_s(i); rex(nil, i, /[ \t]*days?[ \t]+/i); end |
#_dmin(i) ⇒ Object
158 159 160 |
# File 'lib/fugit/nat.rb', line 158 def _dmin(i) rex(:dmin, i, /[0-5]?[0-9]/) end |
#_every(i) ⇒ Object
parsers bottom to top #################################################
115 |
# File 'lib/fugit/nat.rb', line 115 def _every(i); rex(nil, i, /[ \t]*every[ \t]+/i); end |
#_from(i) ⇒ Object
116 |
# File 'lib/fugit/nat.rb', line 116 def _from(i); rex(nil, i, /[ \t]*from[ \t]+/i); end |
#_in_or_on(i) ⇒ Object
123 |
# File 'lib/fugit/nat.rb', line 123 def _in_or_on(i); rex(nil, i, /(in|on)[ \t]+/i); end |
#_minute(i) ⇒ Object
156 |
# File 'lib/fugit/nat.rb', line 156 def _minute(i); rex(nil, i, /[ \t]*minute[ \t]+/i) end |
#_on(i) ⇒ Object
118 |
# File 'lib/fugit/nat.rb', line 118 def _on(i); rex(nil, i, /[ \t]*on[ \t]+/i); end |
#_point(i) ⇒ Object
247 |
# File 'lib/fugit/nat.rb', line 247 def _point(i); rex(:point, i, POINT_REX); end |
#_rewrite_sub(t, key = nil) ⇒ Object
373 374 375 376 |
# File 'lib/fugit/nat.rb', line 373 def _rewrite_sub(t, key=nil) st = t.sublookup(key) st ? rewrite(st) : nil end |
#_rewrite_subs(t, key = nil) ⇒ Object
370 371 372 |
# File 'lib/fugit/nat.rb', line 370 def _rewrite_subs(t, key=nil) t.subgather(key).collect { |ct| rewrite(ct) } end |
#_sep(i) ⇒ Object
135 |
# File 'lib/fugit/nat.rb', line 135 def _sep(i); rex(nil, i, /([ \t]+|[ \t]*,[ \t]*)/); end |
#_space(i) ⇒ Object
134 |
# File 'lib/fugit/nat.rb', line 134 def _space(i); rex(nil, i, /[ \t]+/); end |
#_the(i) ⇒ Object
132 |
# File 'lib/fugit/nat.rb', line 132 def _the(i); rex(nil, i, /[ \t]*the[ \t]+/i); end |
#_to(i) ⇒ Object
119 |
# File 'lib/fugit/nat.rb', line 119 def _to(i); rex(nil, i, /[ \t]*to[ \t]+/i); end |
#_to_or_dash(i) ⇒ Object
128 129 |
# File 'lib/fugit/nat.rb', line 128 def _to_or_dash(i); rex(nil, i, /[ \t]*-[ \t]*|[ \t]+(to|through)[ \t]+/i); end |
#adjust_h(h, m, ap) ⇒ Object
498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/fugit/nat.rb', line 498 def adjust_h(h, m, ap) if ap == 'midnight' && h == 12 24 elsif ap == 'pm' && h < 12 # post meridian h + 12 elsif ap == 'am' && h == 12 # ante meridian 0 else h end end |
#ampm(i) ⇒ Object
212 213 214 |
# File 'lib/fugit/nat.rb', line 212 def ampm(i) rex(:ampm, i, /[ \t]*(am|pm|noon|midday|midnight)/i) end |
#and_dmin(i) ⇒ Object
161 162 163 |
# File 'lib/fugit/nat.rb', line 161 def and_dmin(i) seq(nil, i, :_and_or_or_or_comma, :_minute, '?', :_dmin) end |
#at(i) ⇒ Object
273 274 275 |
# File 'lib/fugit/nat.rb', line 273 def at(i) seq(:at, i, :_at, '?', :at_objects) end |
#at_object(i) ⇒ Object
at five at five pm at five o’clock at 16:30 at noon at 18:00 UTC <– …tz
266 267 268 |
# File 'lib/fugit/nat.rb', line 266 def at_object(i) alt(nil, i, :named_hour, :digital_hour, :simple_hour, :at_point) end |
#at_objects(i) ⇒ Object
269 270 271 |
# File 'lib/fugit/nat.rb', line 269 def at_objects(i) jseq(nil, i, :at_object, :_and_or_or_or_comma) end |
#at_p(i) ⇒ Object
253 254 255 |
# File 'lib/fugit/nat.rb', line 253 def at_p(i) seq(:at_p, i, :_point, :counts) end |
#at_point(i) ⇒ Object
256 257 258 |
# File 'lib/fugit/nat.rb', line 256 def at_point(i) jseq(nil, i, :at_p, :_and_or_or) end |
#city_tz(i) ⇒ Object
196 197 198 |
# File 'lib/fugit/nat.rb', line 196 def city_tz(i) rex(nil, i, /[A-Z][a-zA-Z0-9+\-]+(\/[A-Z][a-zA-Z0-9+\-_]+){0,2}/) end |
#count(i) ⇒ Object
137 |
# File 'lib/fugit/nat.rb', line 137 def count(i); rex(:count, i, /\d+/); end |
#counts(i) ⇒ Object
249 250 251 |
# File 'lib/fugit/nat.rb', line 249 def counts(i) jseq(nil, i, :count, :_and_or_or_or_comma) end |
#dark(i) ⇒ Object
215 216 217 |
# File 'lib/fugit/nat.rb', line 215 def dark(i) rex(:dark, i, /[ \t]*dark/i) end |
#delta_tz(i) ⇒ Object
202 203 204 |
# File 'lib/fugit/nat.rb', line 202 def delta_tz(i) rex(nil, i, /[-+]([01][0-9]|2[0-4])(:?(00|15|30|45))?/) end |
#digital_h(i) ⇒ Object
219 220 221 |
# File 'lib/fugit/nat.rb', line 219 def digital_h(i) rex(:digital_h, i, /(2[0-4]|[0-1]?[0-9]):([0-5][0-9])/i) end |
#digital_hour(i) ⇒ Object
222 223 224 |
# File 'lib/fugit/nat.rb', line 222 def digital_hour(i) seq(:digital_hour, i, :digital_h, :ampm, '?') end |
#every(i) ⇒ Object
352 353 354 |
# File 'lib/fugit/nat.rb', line 352 def every(i) seq(:every, i, :_every, :every_objects) end |
#every_interval(i) ⇒ Object
every day every 1 minute
283 284 285 |
# File 'lib/fugit/nat.rb', line 283 def every_interval(i) seq(:every_interval, i, :count, '?', :interval) end |
#every_named(i) ⇒ Object
338 339 340 |
# File 'lib/fugit/nat.rb', line 338 def every_named(i) rex(:every_named, i, /weekday/i) end |
#every_object(i) ⇒ Object
342 343 344 345 346 347 |
# File 'lib/fugit/nat.rb', line 342 def every_object(i) alt( nil, i, :every_weekday, :every_of_the_month, :every_interval, :every_named, :every_single_interval) end |
#every_objects(i) ⇒ Object
348 349 350 |
# File 'lib/fugit/nat.rb', line 348 def every_objects(i) jseq(nil, i, :every_object, :_and_or_or) end |
#every_of_the_month(i) ⇒ Object
every 1st of the month every first of the month Every 2nd of the month Every second of the month every 15th of the month
334 335 336 |
# File 'lib/fugit/nat.rb', line 334 def every_of_the_month(i) seq(nil, i, :omonthdays, :otm) end |
#every_single_interval(i) ⇒ Object
287 288 289 |
# File 'lib/fugit/nat.rb', line 287 def every_single_interval(i) rex(:every_single_interval, i, /(1[ \t]+)?(week|year)/) end |
#every_weekday(i) ⇒ Object
every monday every Fri-Sun every Monday and Tuesday
321 322 323 |
# File 'lib/fugit/nat.rb', line 321 def every_weekday(i) jseq(nil, i, :weekday_range, :_and_or_or) end |
#from(i) ⇒ Object
314 315 316 |
# File 'lib/fugit/nat.rb', line 314 def from(i) seq(nil, i, :_from, '?', :from_objects) end |
#from_object(i) ⇒ Object
308 309 310 |
# File 'lib/fugit/nat.rb', line 308 def from_object(i) alt(nil, i, :to_weekday, :to_omonthday, :to_hour) end |
#from_objects(i) ⇒ Object
311 312 313 |
# File 'lib/fugit/nat.rb', line 311 def from_objects(i) jseq(nil, i, :from_object, :_and_or_or) end |
#interval(i) ⇒ Object
277 278 279 |
# File 'lib/fugit/nat.rb', line 277 def interval(i) rex(:interval, i, INTERVAL_REX) end |
#monthday(i) ⇒ Object
142 143 144 |
# File 'lib/fugit/nat.rb', line 142 def monthday(i) rex(:monthday, i, MONTHDAY_REX) end |
#monthdays(i) ⇒ Object
150 |
# File 'lib/fugit/nat.rb', line 150 def monthdays(i); jseq(nil, i, :monthday, :_and_or_or_or_comma); end |
#named_h(i) ⇒ Object
240 241 242 |
# File 'lib/fugit/nat.rb', line 240 def named_h(i) rex(:named_h, i, NAMED_H_REX) end |
#named_hour(i) ⇒ Object
243 244 245 |
# File 'lib/fugit/nat.rb', line 243 def named_hour(i) seq(:named_hour, i, :named_h, :dark, '?', :named_min, '?', :ampm, '?') end |
#named_m(i) ⇒ Object
233 234 235 |
# File 'lib/fugit/nat.rb', line 233 def named_m(i) rex(:named_m, i, NAMED_M_REX) end |
#named_min(i) ⇒ Object
236 237 238 |
# File 'lib/fugit/nat.rb', line 236 def named_min(i) seq(nil, i, :_space, :named_m) end |
#named_tz(i) ⇒ Object
199 200 201 |
# File 'lib/fugit/nat.rb', line 199 def named_tz(i) rex(nil, i, /Z|UTC/) end |
#nat(i) ⇒ Object
359 360 361 |
# File 'lib/fugit/nat.rb', line 359 def nat(i) jseq(:nat, i, :nat_elt, :_sep) end |
#nat_elt(i) ⇒ Object
356 357 358 |
# File 'lib/fugit/nat.rb', line 356 def nat_elt(i) alt(nil, i, :every, :from, :at, :tzone, :on) end |
#omonthday(i) ⇒ Object
139 140 141 |
# File 'lib/fugit/nat.rb', line 139 def omonthday(i) rex(:omonthday, i, OMONTHDAY_REX) end |
#omonthdays(i) ⇒ Object
149 |
# File 'lib/fugit/nat.rb', line 149 def omonthdays(i); jseq(nil, i, :omonthday, :_and_or_or_or_comma); end |
#on(i) ⇒ Object
‘every month on day 2 at 10:00’ => ‘0 10 2 * *’, ‘every month on day 2 and 5 at 10:00’ => ‘0 10 2,5 * *’, ‘every month on days 1,15 at 10:00’ => ‘0 10 1,15 * *’,
‘every week on monday 18:23’ => ‘23 18 * * 1’,
every month on the 1st
192 193 194 |
# File 'lib/fugit/nat.rb', line 192 def on(i) seq(:on, i, :_on, :on_objects) end |
#on_days(i) ⇒ Object
174 |
# File 'lib/fugit/nat.rb', line 174 def on_days(i); seq(:on_days, i, :_day_s, :monthdays); end |
#on_minutes(i) ⇒ Object
165 166 167 |
# File 'lib/fugit/nat.rb', line 165 def on_minutes(i) seq(:on_minutes, i, :_minute, :_dmin, :and_dmin, '*') end |
#on_object(i) ⇒ Object
177 178 179 |
# File 'lib/fugit/nat.rb', line 177 def on_object(i) alt(nil, i, :on_days, :on_weekdays, :on_minutes, :on_thes, :on_thex) end |
#on_objects(i) ⇒ Object
180 181 182 |
# File 'lib/fugit/nat.rb', line 180 def on_objects(i) jseq(nil, i, :on_object, :_and) end |
#on_the(i) ⇒ Object
154 |
# File 'lib/fugit/nat.rb', line 154 def on_the(i); seq(nil, i, :_the, :omonthdays); end |
#on_thes(i) ⇒ Object
173 |
# File 'lib/fugit/nat.rb', line 173 def on_thes(i); jseq(:on_thes, i, :on_the, :_and_or_or_or_comma); end |
#on_thex(i) ⇒ Object
169 170 171 |
# File 'lib/fugit/nat.rb', line 169 def on_thex(i); rex(:on_thex, i, /[ \t]*the[ \t]+(hour|minute)[ \t]*/i); end |
#on_weekdays(i) ⇒ Object
175 |
# File 'lib/fugit/nat.rb', line 175 def on_weekdays(i); ren(:on_weekdays, i, :weekdays); end |
#otm(i) ⇒ Object
325 326 327 |
# File 'lib/fugit/nat.rb', line 325 def otm(i) rex(nil, i, /[ \t]+of the month/) end |
#rewrite_at(t) ⇒ Object
554 555 556 |
# File 'lib/fugit/nat.rb', line 554 def rewrite_at(t) _rewrite_subs(t) end |
#rewrite_at_p(t) ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/fugit/nat.rb', line 417 def rewrite_at_p(t) pt = t.sublookup(:point).strinpd pt = pt.start_with?('mon') ? 'M' : pt[0, 1] pts = t.subgather(:count).collect { |e| e.string.to_i } #p [ pt, pts ] case pt #when 'm' then slot(:m, pts) when 'm' then slot(:hm, '*', pts, strong: 1) when 's' then slot(:second, pts) else slot(pt.to_sym, pts) end end |
#rewrite_digital_hour(t) ⇒ Object
511 512 513 514 515 516 517 518 |
# File 'lib/fugit/nat.rb', line 511 def rewrite_digital_hour(t) h, m = t.sublookup(:digital_h).strinpd.split(':').collect(&:to_i) ap = t.sublookup(:ampm) h, m = adjust_h(h, m, ap && ap.strinpd), m slot(:hm, h, m) end |
#rewrite_dmin(t) ⇒ Object
378 379 380 |
# File 'lib/fugit/nat.rb', line 378 def rewrite_dmin(t) t.strinp end |
#rewrite_every(t) ⇒ Object
558 559 560 |
# File 'lib/fugit/nat.rb', line 558 def rewrite_every(t) _rewrite_sub(t) end |
#rewrite_every_interval(t) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/fugit/nat.rb', line 438 def rewrite_every_interval(t) #Raabro.pp(t, colours: true) ci = t.subgather(nil).collect(&:string) i = ci.pop.strip[0, 3] c = (ci.pop || '1').strip i = (i == 'M' || i.downcase == 'mon') ? 'M' : i[0, 1].downcase cc = c == '1' ? '*' : "*/#{c}" case i when 'M' then slot(:month, cc) when 'd' then slot(:monthday, cc, :weak) #when 'h' then slot(:hm, cc, 0, weak: :minute) when 'h' then slot(:hm, cc, 0, weak: 1) when 'm' then slot(:hm, '*', cc, strong: 1) when 's' then slot(:second, cc) else {} end end |
#rewrite_every_named(t) ⇒ Object
458 459 460 461 462 463 464 465 |
# File 'lib/fugit/nat.rb', line 458 def rewrite_every_named(t) case s = t.string when /weekday/i then slot(:weekday, '1-5', :weak) when /week/i then slot(:weekday, '0', :weak) else fail "cannot rewrite #{s.inspect}" end end |
#rewrite_every_single_interval(t) ⇒ Object
430 431 432 433 434 435 436 |
# File 'lib/fugit/nat.rb', line 430 def rewrite_every_single_interval(t) case t.string when /year/i then [ slot(:month, 1, :weak), slot(:monthday, 1, :weak) ] #when /week/i then xxx... else slot(:weekday, 0, :weak) end end |
#rewrite_monthday(t) ⇒ Object
409 410 411 |
# File 'lib/fugit/nat.rb', line 409 def rewrite_monthday(t) slot(:monthday, t.string.to_i) end |
#rewrite_named_hour(t) ⇒ Object
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/fugit/nat.rb', line 528 def rewrite_named_hour(t) ht = t.sublookup(:named_h) mt = t.sublookup(:named_m) apt = t.sublookup(:ampm) h = ht.strinp m = mt ? mt.strinp : 0 h = NHOURS[h] m = NMINUTES[m] || m h = adjust_h(h, m, apt && apt.strinpd) slot(:hm, h, m) end |
#rewrite_nat(t) ⇒ Object
562 563 564 565 |
# File 'lib/fugit/nat.rb', line 562 def rewrite_nat(t) #Raabro.pp(t, colours: true) Fugit::Nat::SlotGroup.new(_rewrite_subs(t).flatten) end |
#rewrite_omonthday(t) ⇒ Object
413 414 415 |
# File 'lib/fugit/nat.rb', line 413 def rewrite_omonthday(t) slot(:monthday, OMONTHDAYS[t.string.downcase]) end |
#rewrite_on(t) ⇒ Object
405 406 407 |
# File 'lib/fugit/nat.rb', line 405 def rewrite_on(t) _rewrite_subs(t) end |
#rewrite_on_days(t) ⇒ Object
401 402 403 |
# File 'lib/fugit/nat.rb', line 401 def rewrite_on_days(t) _rewrite_subs(t, :monthday) end |
#rewrite_on_minutes(t) ⇒ Object
382 383 384 385 386 387 |
# File 'lib/fugit/nat.rb', line 382 def rewrite_on_minutes(t) #Raabro.pp(t, colours: true) mins = t.subgather(:dmin).collect(&:strinp) #slot(:m, mins.join(',')) slot(:hm, '*', mins.join(','), strong: 1) end |
#rewrite_on_thes(t) ⇒ Object
398 399 400 |
# File 'lib/fugit/nat.rb', line 398 def rewrite_on_thes(t) _rewrite_subs(t, :omonthday) end |
#rewrite_on_thex(t) ⇒ Object
389 390 391 392 393 394 395 396 |
# File 'lib/fugit/nat.rb', line 389 def rewrite_on_thex(t) case s = t.string #when /hour/i then slot(:h, 0) #else slot(:m, '*') when /hour/i then slot(:hm, 0, '*', strong: 0) else slot(:hm, '*', '*', strong: 1) end end |
#rewrite_simple_hour(t) ⇒ Object
520 521 522 523 524 525 526 |
# File 'lib/fugit/nat.rb', line 520 def rewrite_simple_hour(t) h, ap = t.subgather(nil).collect(&:strinpd) h = adjust_h(h.to_i, 0, ap) slot(:hm, h, 0) end |
#rewrite_to_hour(t) ⇒ Object
544 545 546 547 548 549 550 551 552 |
# File 'lib/fugit/nat.rb', line 544 def rewrite_to_hour(t) #Raabro.pp(t, colours: true) ht0, ht1 = t.subgather(nil) h0, h1 = rewrite(ht0), rewrite(ht1) fail ArgumentError.new( "cannot deal with #{ht0.strinp} to #{ht1.strinp}, minutes diverge" ) if h0.data1 != h1.data1 slot(:hm, "#{h0._data0}-#{h1._data0}", 0, strong: 0) end |
#rewrite_to_omonthday(t) ⇒ Object
491 492 493 494 |
# File 'lib/fugit/nat.rb', line 491 def rewrite_to_omonthday(t) md0, md1 = _rewrite_subs(t, :omonthday).collect(&:_data0) slot(:monthday, "#{md0}-#{md1}") end |
#rewrite_to_weekday(t) ⇒ Object
484 485 486 487 488 489 |
# File 'lib/fugit/nat.rb', line 484 def rewrite_to_weekday(t) wd0, wd1 = _rewrite_subs(t, :weekday) #wd1 = 7 if wd1 == 0 slot(:weekday, "#{wd0}-#{wd1}") end |
#rewrite_tz(t) ⇒ Object
467 468 469 470 |
# File 'lib/fugit/nat.rb', line 467 def rewrite_tz(t) slot(:tz, t.string) end |
#rewrite_weekday(t) ⇒ Object
472 473 474 475 |
# File 'lib/fugit/nat.rb', line 472 def rewrite_weekday(t) Fugit::Cron::Parser::WEEKDS.index(t.string[0, 3].downcase) end |
#rewrite_weekdays(t) ⇒ Object Also known as: rewrite_on_weekdays
477 478 479 480 481 |
# File 'lib/fugit/nat.rb', line 477 def rewrite_weekdays(t) #Raabro.pp(t, colours: true) slot(:weekday, _rewrite_subs(t, :weekday)) end |
#simple_h(i) ⇒ Object
226 227 228 |
# File 'lib/fugit/nat.rb', line 226 def simple_h(i) rex(:simple_h, i, /#{(0..24).to_a.reverse.join('|')}/) end |
#simple_hour(i) ⇒ Object
229 230 231 |
# File 'lib/fugit/nat.rb', line 229 def simple_hour(i) seq(:simple_hour, i, :simple_h, :ampm, '?') end |
#slot(key, data0, data1 = nil, opts = nil) ⇒ Object
rewrite parsed tree ###################################################
366 367 368 |
# File 'lib/fugit/nat.rb', line 366 def slot(key, data0, data1=nil, opts=nil) Slot.new(key, data0, data1, opts) end |
#to_hour(i) ⇒ Object
304 305 306 |
# File 'lib/fugit/nat.rb', line 304 def to_hour(i) seq(:to_hour, i, :at_object, :_to, :at_object) end |
#to_omonthday(i) ⇒ Object
299 300 301 302 |
# File 'lib/fugit/nat.rb', line 299 def to_omonthday(i) seq(:to_omonthday, i, :_the, '?', :omonthday, :_to, :_the, '?', :omonthday) end |
#to_weekday(i) ⇒ Object
291 292 293 |
# File 'lib/fugit/nat.rb', line 291 def to_weekday(i) seq(:to_weekday, i, :weekday, :_to_or_dash, :weekday) end |
#tz(i) ⇒ Object
205 206 207 |
# File 'lib/fugit/nat.rb', line 205 def tz(i) alt(:tz, i, :city_tz, :named_tz, :delta_tz) end |
#tzone(i) ⇒ Object
208 209 210 |
# File 'lib/fugit/nat.rb', line 208 def tzone(i) seq(nil, i, :_in_or_on, '?', :tz) end |
#weekday(i) ⇒ Object
145 146 147 |
# File 'lib/fugit/nat.rb', line 145 def weekday(i) rex(:weekday, i, WEEKDAY_REX) end |
#weekday_range(i) ⇒ Object
295 296 297 |
# File 'lib/fugit/nat.rb', line 295 def weekday_range(i) alt(nil, i, :to_weekday, :weekdays) end |
#weekdays(i) ⇒ Object
152 |
# File 'lib/fugit/nat.rb', line 152 def weekdays(i); jseq(:weekdays, i, :weekday, :_and_or_or_or_comma); end |