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
- #t_dom(i) ⇒ Object
- #t_dow(i) ⇒ Object
- #t_hou(i) ⇒ Object
- #t_mon(i) ⇒ Object
-
#t_mos(i) ⇒ Object
t: tilde range.
- #tilde(i) ⇒ Object
Instance Method Details
#_dom(i) ⇒ Object
808 |
# File 'lib/fugit/cron.rb', line 808 def _dom(i); seq(nil, i, :hyphen, :dom); end |
#_dow(i) ⇒ Object
810 |
# File 'lib/fugit/cron.rb', line 810 def _dow(i); seq(nil, i, :hyphen, :dow); end |
#_hou(i) ⇒ Object
807 |
# File 'lib/fugit/cron.rb', line 807 def _hou(i); seq(nil, i, :hyphen, :hou); end |
#_mon(i) ⇒ Object
809 |
# File 'lib/fugit/cron.rb', line 809 def _mon(i); seq(nil, i, :hyphen, :mon); end |
#_mos(i) ⇒ Object
806 |
# File 'lib/fugit/cron.rb', line 806 def _mos(i); seq(nil, i, :hyphen, :mos); end |
#_tz(i) ⇒ Object
874 |
# File 'lib/fugit/cron.rb', line 874 def _tz(i); alt(:tz, i, :_tz_delta, :_tz_name); end |
#_tz_delta(i) ⇒ Object
871 872 873 |
# File 'lib/fugit/cron.rb', line 871 def _tz_delta(i) rex(nil, i, / +[-+]([01][0-9]|2[0-4]):?(00|15|30|45)/) end |
#_tz_name(i) ⇒ Object
868 869 870 |
# File 'lib/fugit/cron.rb', line 868 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
794 |
# File 'lib/fugit/cron.rb', line 794 def and?(i); rex(nil, i, /&?/); end |
#classic_cron(i) ⇒ Object
876 877 878 879 |
# File 'lib/fugit/cron.rb', line 876 def classic_cron(i) seq(:ccron, i, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') end |
#comma(i) ⇒ Object
792 |
# File 'lib/fugit/cron.rb', line 792 def comma(i); rex(nil, i, /,([ \t]*,)*/); end |
#comma?(i) ⇒ Boolean
793 |
# File 'lib/fugit/cron.rb', line 793 def comma?(i); rex(nil, i, /([ \t]*,)*/); end |
#cron(i) ⇒ Object
885 886 887 |
# File 'lib/fugit/cron.rb', line 885 def cron(i) alt(:cron, i, :second_cron, :classic_cron) end |
#dom(i) ⇒ Object
800 |
# File 'lib/fugit/cron.rb', line 800 def dom(i); rex(:dom, i, /(-?(3[01]|[12][0-9]|0?[1-9])|last|l)/i); end |
#dom_elt(i) ⇒ Object
843 |
# File 'lib/fugit/cron.rb', line 843 def dom_elt(i); alt(:elt, i, :slash, :sorws_dom); end |
#dow(i) ⇒ Object
802 |
# File 'lib/fugit/cron.rb', line 802 def dow(i); rex(:dow, i, DOW_REX); end |
#dow_elt(i) ⇒ Object
845 |
# File 'lib/fugit/cron.rb', line 845 def dow_elt(i); alt(:elt, i, :slash, :sorws_dow); end |
#dow_elt_(i) ⇒ Object
852 |
# File 'lib/fugit/cron.rb', line 852 def dow_elt_(i); alt(nil, i, :h_dow, :mod_dow, :dow_elt); end |
#dow_hash(i) ⇒ Object
804 |
# File 'lib/fugit/cron.rb', line 804 def dow_hash(i); rex(:hash, i, /#(-?[1-5]|last|l)/i); end |
#h_dow(i) ⇒ Object
850 |
# File 'lib/fugit/cron.rb', line 850 def h_dow(i); seq(:elt, i, :dow, :dow_hash); end |
#hou(i) ⇒ Object
799 |
# File 'lib/fugit/cron.rb', line 799 def hou(i); rex(:hou, i, /(2[0-4]|[01]?[0-9])/); end |
#hou_elt(i) ⇒ Object
842 |
# File 'lib/fugit/cron.rb', line 842 def hou_elt(i); alt(:elt, i, :slash, :sorws_hou); end |
#hyphen(i) ⇒ Object
790 |
# File 'lib/fugit/cron.rb', line 790 def hyphen(i); str(:hyphen, i, '-'); end |
#ldom_(i) ⇒ Object
864 |
# File 'lib/fugit/cron.rb', line 864 def ldom_(i); seq(nil, i, :comma?, :list_dom, :comma?, :and?, :s); end |
#ldow(i) ⇒ Object
866 |
# File 'lib/fugit/cron.rb', line 866 def ldow(i); seq(nil, i, :comma?, :list_dow, :comma?, :and?); end |
#lhou_(i) ⇒ Object
863 |
# File 'lib/fugit/cron.rb', line 863 def lhou_(i); seq(nil, i, :comma?, :list_hou, :comma?, :s); end |
#list_dom(i) ⇒ Object
857 |
# File 'lib/fugit/cron.rb', line 857 def list_dom(i); jseq(:dom, i, :dom_elt, :comma); end |
#list_dow(i) ⇒ Object
859 |
# File 'lib/fugit/cron.rb', line 859 def list_dow(i); jseq(:dow, i, :dow_elt_, :comma); end |
#list_hou(i) ⇒ Object
856 |
# File 'lib/fugit/cron.rb', line 856 def list_hou(i); jseq(:hou, i, :hou_elt, :comma); end |
#list_min(i) ⇒ Object
855 |
# File 'lib/fugit/cron.rb', line 855 def list_min(i); jseq(:min, i, :mos_elt, :comma); end |
#list_mon(i) ⇒ Object
858 |
# File 'lib/fugit/cron.rb', line 858 def list_mon(i); jseq(:mon, i, :mon_elt, :comma); end |
#list_sec(i) ⇒ Object
854 |
# File 'lib/fugit/cron.rb', line 854 def list_sec(i); jseq(:sec, i, :mos_elt, :comma); end |
#lmin_(i) ⇒ Object
862 |
# File 'lib/fugit/cron.rb', line 862 def lmin_(i); seq(nil, i, :comma?, :list_min, :comma?, :s); end |
#lmon_(i) ⇒ Object
865 |
# File 'lib/fugit/cron.rb', line 865 def lmon_(i); seq(nil, i, :comma?, :list_mon, :comma?, :s); end |
#lsec_(i) ⇒ Object
861 |
# File 'lib/fugit/cron.rb', line 861 def lsec_(i); seq(nil, i, :comma?, :list_sec, :comma?, :s); end |
#mod(i) ⇒ Object
847 |
# File 'lib/fugit/cron.rb', line 847 def mod(i); rex(:mod, i, /%\d+(\+\d+)?/); end |
#mod_dow(i) ⇒ Object
849 |
# File 'lib/fugit/cron.rb', line 849 def mod_dow(i); seq(:elt, i, :dow, :mod); end |
#mon(i) ⇒ Object
801 |
# File 'lib/fugit/cron.rb', line 801 def mon(i); rex(:mon, i, MONTH_REX); end |
#mon_elt(i) ⇒ Object
844 |
# File 'lib/fugit/cron.rb', line 844 def mon_elt(i); alt(:elt, i, :slash, :sorws_mon); end |
#mos(i) ⇒ Object
min or sec
798 |
# File 'lib/fugit/cron.rb', line 798 def mos(i); rex(:mos, i, /[0-5]?\d/); end |
#mos_elt(i) ⇒ Object
ssws: slash or sorws
841 |
# File 'lib/fugit/cron.rb', line 841 def mos_elt(i); alt(:elt, i, :slash, :sorws_mos); end |
#r_dom(i) ⇒ Object
815 |
# File 'lib/fugit/cron.rb', line 815 def r_dom(i); seq(nil, i, :dom, :_dom, '?'); end |
#r_dow(i) ⇒ Object
817 |
# File 'lib/fugit/cron.rb', line 817 def r_dow(i); seq(nil, i, :dow, :_dow, '?'); end |
#r_hou(i) ⇒ Object
814 |
# File 'lib/fugit/cron.rb', line 814 def r_hou(i); seq(nil, i, :hou, :_hou, '?'); end |
#r_mon(i) ⇒ Object
816 |
# File 'lib/fugit/cron.rb', line 816 def r_mon(i); seq(nil, i, :mon, :_mon, '?'); end |
#r_mos(i) ⇒ Object
r: range
813 |
# File 'lib/fugit/cron.rb', line 813 def r_mos(i); seq(nil, i, :mos, :_mos, '?'); end |
#rewrite_bound(k, t) ⇒ Object
rewriting the parsed tree
891 892 893 894 895 896 897 898 899 |
# File 'lib/fugit/cron.rb', line 891 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
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'lib/fugit/cron.rb', line 957 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
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
# File 'lib/fugit/cron.rb', line 909 def rewrite_elt(k, t) at, zt, spt, 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 when :hyphen then spt = tt when :tilde then spt = tt else if spt; 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 sp = spt ? spt.name : nil #a, z = z, a if a && z && a > z # handled downstream since gh-27 [ a, z, sp, sl, ha, mo ] end |
#rewrite_entry(t) ⇒ Object
942 943 944 945 946 947 |
# File 'lib/fugit/cron.rb', line 942 def rewrite_entry(t) t .subgather(:elt) .collect { |et| rewrite_elt(t.name, et) } end |
#rewrite_mod(k, t) ⇒ Object
901 902 903 904 905 906 907 |
# File 'lib/fugit/cron.rb', line 901 def rewrite_mod(k, t) mod, plus = t.string .split(/[%+]/).reject(&:empty?).collect(&:to_i) [ mod, plus || 0 ] end |
#rewrite_tz(t) ⇒ Object
949 950 951 952 953 954 955 |
# File 'lib/fugit/cron.rb', line 949 def rewrite_tz(t) s = t.strim z = EtOrbi.get_tzone(s) [ s, z ] end |
#s(i) ⇒ Object
piece parsers bottom to top
788 |
# File 'lib/fugit/cron.rb', line 788 def s(i); rex(nil, i, /[ \t]+/); end |
#second_cron(i) ⇒ Object
880 881 882 883 |
# File 'lib/fugit/cron.rb', line 880 def second_cron(i) seq(:scron, i, :lsec_, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') end |
#slash(i) ⇒ Object
796 |
# File 'lib/fugit/cron.rb', line 796 def slash(i); rex(:slash, i, /\/\d\d?/); end |
#sor_dom(i) ⇒ Object
829 |
# File 'lib/fugit/cron.rb', line 829 def sor_dom(i); alt(nil, i, :star, :t_dom, :r_dom); end |
#sor_dow(i) ⇒ Object
831 |
# File 'lib/fugit/cron.rb', line 831 def sor_dow(i); alt(nil, i, :star, :t_dow, :r_dow); end |
#sor_hou(i) ⇒ Object
828 |
# File 'lib/fugit/cron.rb', line 828 def sor_hou(i); alt(nil, i, :star, :t_hou, :r_hou); end |
#sor_mon(i) ⇒ Object
830 |
# File 'lib/fugit/cron.rb', line 830 def sor_mon(i); alt(nil, i, :star, :t_mon, :r_mon); end |
#sor_mos(i) ⇒ Object
sor: star or range
827 |
# File 'lib/fugit/cron.rb', line 827 def sor_mos(i); alt(nil, i, :star, :t_mos, :r_mos); end |
#sorws_dom(i) ⇒ Object
836 |
# File 'lib/fugit/cron.rb', line 836 def sorws_dom(i); seq(nil, i, :sor_dom, :slash, '?'); end |
#sorws_dow(i) ⇒ Object
838 |
# File 'lib/fugit/cron.rb', line 838 def sorws_dow(i); seq(nil, i, :sor_dow, :slash, '?'); end |
#sorws_hou(i) ⇒ Object
835 |
# File 'lib/fugit/cron.rb', line 835 def sorws_hou(i); seq(nil, i, :sor_hou, :slash, '?'); end |
#sorws_mon(i) ⇒ Object
837 |
# File 'lib/fugit/cron.rb', line 837 def sorws_mon(i); seq(nil, i, :sor_mon, :slash, '?'); end |
#sorws_mos(i) ⇒ Object
sorws: star or range with slash
834 |
# File 'lib/fugit/cron.rb', line 834 def sorws_mos(i); seq(nil, i, :sor_mos, :slash, '?'); end |
#star(i) ⇒ Object
789 |
# File 'lib/fugit/cron.rb', line 789 def star(i); str(nil, i, '*'); end |
#t_dom(i) ⇒ Object
822 |
# File 'lib/fugit/cron.rb', line 822 def t_dom(i); seq(nil, i, :dom, '?', :tilde, :dom, '?'); end |
#t_dow(i) ⇒ Object
824 |
# File 'lib/fugit/cron.rb', line 824 def t_dow(i); seq(nil, i, :dow, '?', :tilde, :dow, '?'); end |
#t_hou(i) ⇒ Object
821 |
# File 'lib/fugit/cron.rb', line 821 def t_hou(i); seq(nil, i, :hou, '?', :tilde, :hou, '?'); end |
#t_mon(i) ⇒ Object
823 |
# File 'lib/fugit/cron.rb', line 823 def t_mon(i); seq(nil, i, :mon, '?', :tilde, :mon, '?'); end |
#t_mos(i) ⇒ Object
t: tilde range
820 |
# File 'lib/fugit/cron.rb', line 820 def t_mos(i); seq(nil, i, :mos, '?', :tilde, :mos, '?'); end |
#tilde(i) ⇒ Object
791 |
# File 'lib/fugit/cron.rb', line 791 def tilde(i); str(:tilde, i, '~'); end |