Module: Fugit::Cron::Parser
- Includes:
- Raabro
- Defined in:
- lib/fugit/cron.rb
Constant Summary collapse
- WEEKDAYS =
%w[ sunday monday tuesday wednesday thursday friday saturday ].freeze
- WEEKDS =
WEEKDAYS.collect { |d| d[0, 3] }.freeze
- DOW_REX =
/([0-7]|#{WEEKDS.join('|')})/i.freeze
- MONTHS =
%w[ - jan feb mar apr may jun jul aug sep oct nov dec ].freeze
- MONTH_REX =
/(1[0-2]|0?[1-9]|#{MONTHS[1..-1].join('|')})/i.freeze
Instance Method Summary collapse
- #_dom(i) ⇒ Object
- #_dow(i) ⇒ Object
- #_hou(i) ⇒ Object
- #_mon(i) ⇒ Object
- #_mos(i) ⇒ Object
- #_tz(i) ⇒ Object
- #_tz_delta(i) ⇒ Object
- #_tz_name(i) ⇒ Object
- #and?(i) ⇒ Boolean
- #classic_cron(i) ⇒ Object
- #comma(i) ⇒ Object
- #comma?(i) ⇒ Boolean
- #cron(i) ⇒ Object
- #dom(i) ⇒ Object
- #dom_elt(i) ⇒ Object
- #dow(i) ⇒ Object
- #dow_elt(i) ⇒ Object
- #dow_elt_(i) ⇒ Object
- #dow_hash(i) ⇒ Object
- #h_dow(i) ⇒ Object
- #hou(i) ⇒ Object
- #hou_elt(i) ⇒ Object
- #hyphen(i) ⇒ Object
- #ldom_(i) ⇒ Object
- #ldow(i) ⇒ Object
- #lhou_(i) ⇒ Object
- #list_dom(i) ⇒ Object
- #list_dow(i) ⇒ Object
- #list_hou(i) ⇒ Object
- #list_min(i) ⇒ Object
- #list_mon(i) ⇒ Object
- #list_sec(i) ⇒ Object
- #lmin_(i) ⇒ Object
- #lmon_(i) ⇒ Object
- #lsec_(i) ⇒ Object
- #mod(i) ⇒ Object
- #mod_dow(i) ⇒ Object
- #mon(i) ⇒ Object
- #mon_elt(i) ⇒ Object
-
#mos(i) ⇒ Object
min or sec.
-
#mos_elt(i) ⇒ Object
ssws: slash or sorws.
- #r_dom(i) ⇒ Object
- #r_dow(i) ⇒ Object
- #r_hou(i) ⇒ Object
- #r_mon(i) ⇒ Object
-
#r_mos(i) ⇒ Object
r: range.
-
#rewrite_bound(k, t) ⇒ Object
rewriting the parsed tree.
- #rewrite_cron(t) ⇒ Object
- #rewrite_elt(k, t) ⇒ Object
- #rewrite_entry(t) ⇒ Object
- #rewrite_mod(k, t) ⇒ Object
- #rewrite_tz(t) ⇒ Object
-
#s(i) ⇒ Object
piece parsers bottom to top.
- #second_cron(i) ⇒ Object
- #slash(i) ⇒ Object
- #sor_dom(i) ⇒ Object
- #sor_dow(i) ⇒ Object
- #sor_hou(i) ⇒ Object
- #sor_mon(i) ⇒ Object
-
#sor_mos(i) ⇒ Object
sor: star or range.
- #sorws_dom(i) ⇒ Object
- #sorws_dow(i) ⇒ Object
- #sorws_hou(i) ⇒ Object
- #sorws_mon(i) ⇒ Object
-
#sorws_mos(i) ⇒ Object
sorws: star or range with slash.
- #star(i) ⇒ Object
Instance Method Details
#_dom(i) ⇒ Object
769 |
# File 'lib/fugit/cron.rb', line 769 def _dom(i); seq(nil, i, :hyphen, :dom); end |
#_dow(i) ⇒ Object
771 |
# File 'lib/fugit/cron.rb', line 771 def _dow(i); seq(nil, i, :hyphen, :dow); end |
#_hou(i) ⇒ Object
768 |
# File 'lib/fugit/cron.rb', line 768 def _hou(i); seq(nil, i, :hyphen, :hou); end |
#_mon(i) ⇒ Object
770 |
# File 'lib/fugit/cron.rb', line 770 def _mon(i); seq(nil, i, :hyphen, :mon); end |
#_mos(i) ⇒ Object
767 |
# File 'lib/fugit/cron.rb', line 767 def _mos(i); seq(nil, i, :hyphen, :mos); end |
#_tz(i) ⇒ Object
828 |
# File 'lib/fugit/cron.rb', line 828 def _tz(i); alt(:tz, i, :_tz_delta, :_tz_name); end |
#_tz_delta(i) ⇒ Object
825 826 827 |
# File 'lib/fugit/cron.rb', line 825 def _tz_delta(i) rex(nil, i, / +[-+]([01][0-9]|2[0-4]):?(00|15|30|45)/) end |
#_tz_name(i) ⇒ Object
822 823 824 |
# File 'lib/fugit/cron.rb', line 822 def _tz_name(i) rex(nil, i, / +[A-Z][a-zA-Z0-9+\-]+(\/[A-Z][a-zA-Z0-9+\-_]+){0,2}/) end |
#and?(i) ⇒ Boolean
755 |
# File 'lib/fugit/cron.rb', line 755 def and?(i); rex(nil, i, /&?/); end |
#classic_cron(i) ⇒ Object
830 831 832 833 |
# File 'lib/fugit/cron.rb', line 830 def classic_cron(i) seq(:ccron, i, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') end |
#comma(i) ⇒ Object
753 |
# File 'lib/fugit/cron.rb', line 753 def comma(i); rex(nil, i, /,([ \t]*,)*/); end |
#comma?(i) ⇒ Boolean
754 |
# File 'lib/fugit/cron.rb', line 754 def comma?(i); rex(nil, i, /([ \t]*,)*/); end |
#cron(i) ⇒ Object
839 840 841 |
# File 'lib/fugit/cron.rb', line 839 def cron(i) alt(:cron, i, :second_cron, :classic_cron) end |
#dom(i) ⇒ Object
761 |
# File 'lib/fugit/cron.rb', line 761 def dom(i); rex(:dom, i, /(-?(3[01]|[12][0-9]|0?[1-9])|last|l)/i); end |
#dom_elt(i) ⇒ Object
797 |
# File 'lib/fugit/cron.rb', line 797 def dom_elt(i); alt(:elt, i, :slash, :sorws_dom); end |
#dow(i) ⇒ Object
763 |
# File 'lib/fugit/cron.rb', line 763 def dow(i); rex(:dow, i, DOW_REX); end |
#dow_elt(i) ⇒ Object
799 |
# File 'lib/fugit/cron.rb', line 799 def dow_elt(i); alt(:elt, i, :slash, :sorws_dow); end |
#dow_elt_(i) ⇒ Object
806 |
# File 'lib/fugit/cron.rb', line 806 def dow_elt_(i); alt(nil, i, :h_dow, :mod_dow, :dow_elt); end |
#dow_hash(i) ⇒ Object
765 |
# File 'lib/fugit/cron.rb', line 765 def dow_hash(i); rex(:hash, i, /#(-?[1-5]|last|l)/i); end |
#h_dow(i) ⇒ Object
804 |
# File 'lib/fugit/cron.rb', line 804 def h_dow(i); seq(:elt, i, :dow, :dow_hash); end |
#hou(i) ⇒ Object
760 |
# File 'lib/fugit/cron.rb', line 760 def hou(i); rex(:hou, i, /(2[0-4]|[01]?[0-9])/); end |
#hou_elt(i) ⇒ Object
796 |
# File 'lib/fugit/cron.rb', line 796 def hou_elt(i); alt(:elt, i, :slash, :sorws_hou); end |
#hyphen(i) ⇒ Object
752 |
# File 'lib/fugit/cron.rb', line 752 def hyphen(i); str(nil, i, '-'); end |
#ldom_(i) ⇒ Object
818 |
# File 'lib/fugit/cron.rb', line 818 def ldom_(i); seq(nil, i, :comma?, :list_dom, :comma?, :and?, :s); end |
#ldow(i) ⇒ Object
820 |
# File 'lib/fugit/cron.rb', line 820 def ldow(i); seq(nil, i, :comma?, :list_dow, :comma?, :and?); end |
#lhou_(i) ⇒ Object
817 |
# File 'lib/fugit/cron.rb', line 817 def lhou_(i); seq(nil, i, :comma?, :list_hou, :comma?, :s); end |
#list_dom(i) ⇒ Object
811 |
# File 'lib/fugit/cron.rb', line 811 def list_dom(i); jseq(:dom, i, :dom_elt, :comma); end |
#list_dow(i) ⇒ Object
813 |
# File 'lib/fugit/cron.rb', line 813 def list_dow(i); jseq(:dow, i, :dow_elt_, :comma); end |
#list_hou(i) ⇒ Object
810 |
# File 'lib/fugit/cron.rb', line 810 def list_hou(i); jseq(:hou, i, :hou_elt, :comma); end |
#list_min(i) ⇒ Object
809 |
# File 'lib/fugit/cron.rb', line 809 def list_min(i); jseq(:min, i, :mos_elt, :comma); end |
#list_mon(i) ⇒ Object
812 |
# File 'lib/fugit/cron.rb', line 812 def list_mon(i); jseq(:mon, i, :mon_elt, :comma); end |
#list_sec(i) ⇒ Object
808 |
# File 'lib/fugit/cron.rb', line 808 def list_sec(i); jseq(:sec, i, :mos_elt, :comma); end |
#lmin_(i) ⇒ Object
816 |
# File 'lib/fugit/cron.rb', line 816 def lmin_(i); seq(nil, i, :comma?, :list_min, :comma?, :s); end |
#lmon_(i) ⇒ Object
819 |
# File 'lib/fugit/cron.rb', line 819 def lmon_(i); seq(nil, i, :comma?, :list_mon, :comma?, :s); end |
#lsec_(i) ⇒ Object
815 |
# File 'lib/fugit/cron.rb', line 815 def lsec_(i); seq(nil, i, :comma?, :list_sec, :comma?, :s); end |
#mod(i) ⇒ Object
801 |
# File 'lib/fugit/cron.rb', line 801 def mod(i); rex(:mod, i, /%\d+(\+\d+)?/); end |
#mod_dow(i) ⇒ Object
803 |
# File 'lib/fugit/cron.rb', line 803 def mod_dow(i); seq(:elt, i, :dow, :mod); end |
#mon(i) ⇒ Object
762 |
# File 'lib/fugit/cron.rb', line 762 def mon(i); rex(:mon, i, MONTH_REX); end |
#mon_elt(i) ⇒ Object
798 |
# File 'lib/fugit/cron.rb', line 798 def mon_elt(i); alt(:elt, i, :slash, :sorws_mon); end |
#mos(i) ⇒ Object
min or sec
759 |
# File 'lib/fugit/cron.rb', line 759 def mos(i); rex(:mos, i, /[0-5]?\d/); end |
#mos_elt(i) ⇒ Object
ssws: slash or sorws
795 |
# File 'lib/fugit/cron.rb', line 795 def mos_elt(i); alt(:elt, i, :slash, :sorws_mos); end |
#r_dom(i) ⇒ Object
776 |
# File 'lib/fugit/cron.rb', line 776 def r_dom(i); seq(nil, i, :dom, :_dom, '?'); end |
#r_dow(i) ⇒ Object
778 |
# File 'lib/fugit/cron.rb', line 778 def r_dow(i); seq(nil, i, :dow, :_dow, '?'); end |
#r_hou(i) ⇒ Object
775 |
# File 'lib/fugit/cron.rb', line 775 def r_hou(i); seq(nil, i, :hou, :_hou, '?'); end |
#r_mon(i) ⇒ Object
777 |
# File 'lib/fugit/cron.rb', line 777 def r_mon(i); seq(nil, i, :mon, :_mon, '?'); end |
#r_mos(i) ⇒ Object
r: range
774 |
# File 'lib/fugit/cron.rb', line 774 def r_mos(i); seq(nil, i, :mos, :_mos, '?'); end |
#rewrite_bound(k, t) ⇒ Object
rewriting the parsed tree
845 846 847 848 849 850 851 852 853 |
# File 'lib/fugit/cron.rb', line 845 def rewrite_bound(k, t) s = t.string.downcase (k == :mon && MONTHS.index(s)) || (k == :dow && WEEKDS.index(s)) || ((k == :dom) && s[0, 1] == 'l' && -1) || # L, l, last s.to_i end |
#rewrite_cron(t) ⇒ Object
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
# File 'lib/fugit/cron.rb', line 906 def rewrite_cron(t) st = t .sublookup(nil) # go to :ccron or :scron return nil unless st hcron = st .subgather(nil) # list min, hou, mon, ... .inject({}) { |h, tt| h[tt.name] = tt.name == :tz ? rewrite_tz(tt) : rewrite_entry(tt) h } hcron[:&] = true if t.string.index('&') z, tz = hcron[:tz]; return nil if z && ! tz hcron end |
#rewrite_elt(k, t) ⇒ Object
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/fugit/cron.rb', line 863 def rewrite_elt(k, t) at, zt, slt, hat, mot = nil; t.subgather(nil).each do |tt| case tt.name when :slash then slt = tt when :hash then hat = tt when :mod then mot = tt else if at; zt ||= tt; else; at = tt; end end end sl = slt ? slt.string[1..-1].to_i : nil ha = hat ? hat.string[1..-1] : nil ha = -1 if ha && ha.upcase[0, 1] == 'L' ha = ha.to_i if ha mo = mot ? rewrite_mod(k, mot) : nil a = at ? rewrite_bound(k, at) : nil z = zt ? rewrite_bound(k, zt) : nil #a, z = z, a if a && z && a > z # handled downstream since gh-27 [ a, z, sl, ha, mo ] end |
#rewrite_entry(t) ⇒ Object
891 892 893 894 895 896 |
# File 'lib/fugit/cron.rb', line 891 def rewrite_entry(t) t .subgather(:elt) .collect { |et| rewrite_elt(t.name, et) } end |
#rewrite_mod(k, t) ⇒ Object
855 856 857 858 859 860 861 |
# File 'lib/fugit/cron.rb', line 855 def rewrite_mod(k, t) mod, plus = t.string .split(/[%+]/).reject(&:empty?).collect(&:to_i) [ mod, plus || 0 ] end |
#rewrite_tz(t) ⇒ Object
898 899 900 901 902 903 904 |
# File 'lib/fugit/cron.rb', line 898 def rewrite_tz(t) s = t.strim z = EtOrbi.get_tzone(s) [ s, z ] end |
#s(i) ⇒ Object
piece parsers bottom to top
750 |
# File 'lib/fugit/cron.rb', line 750 def s(i); rex(nil, i, /[ \t]+/); end |
#second_cron(i) ⇒ Object
834 835 836 837 |
# File 'lib/fugit/cron.rb', line 834 def second_cron(i) seq(:scron, i, :lsec_, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') end |
#slash(i) ⇒ Object
757 |
# File 'lib/fugit/cron.rb', line 757 def slash(i); rex(:slash, i, /\/\d\d?/); end |
#sor_dom(i) ⇒ Object
783 |
# File 'lib/fugit/cron.rb', line 783 def sor_dom(i); alt(nil, i, :star, :r_dom); end |
#sor_dow(i) ⇒ Object
785 |
# File 'lib/fugit/cron.rb', line 785 def sor_dow(i); alt(nil, i, :star, :r_dow); end |
#sor_hou(i) ⇒ Object
782 |
# File 'lib/fugit/cron.rb', line 782 def sor_hou(i); alt(nil, i, :star, :r_hou); end |
#sor_mon(i) ⇒ Object
784 |
# File 'lib/fugit/cron.rb', line 784 def sor_mon(i); alt(nil, i, :star, :r_mon); end |
#sor_mos(i) ⇒ Object
sor: star or range
781 |
# File 'lib/fugit/cron.rb', line 781 def sor_mos(i); alt(nil, i, :star, :r_mos); end |
#sorws_dom(i) ⇒ Object
790 |
# File 'lib/fugit/cron.rb', line 790 def sorws_dom(i); seq(nil, i, :sor_dom, :slash, '?'); end |
#sorws_dow(i) ⇒ Object
792 |
# File 'lib/fugit/cron.rb', line 792 def sorws_dow(i); seq(nil, i, :sor_dow, :slash, '?'); end |
#sorws_hou(i) ⇒ Object
789 |
# File 'lib/fugit/cron.rb', line 789 def sorws_hou(i); seq(nil, i, :sor_hou, :slash, '?'); end |
#sorws_mon(i) ⇒ Object
791 |
# File 'lib/fugit/cron.rb', line 791 def sorws_mon(i); seq(nil, i, :sor_mon, :slash, '?'); end |
#sorws_mos(i) ⇒ Object
sorws: star or range with slash
788 |
# File 'lib/fugit/cron.rb', line 788 def sorws_mos(i); seq(nil, i, :sor_mos, :slash, '?'); end |
#star(i) ⇒ Object
751 |
# File 'lib/fugit/cron.rb', line 751 def star(i); str(nil, i, '*'); end |