module Fugit::Nat
A natural language set of parsers for fugit. Focuses on cron expressions. The rest is better left to Chronic and friends.
Constants
- MAX_INPUT_LENGTH
Public Class Methods
do_parse(s, opts={})
click to toggle source
# File lib/fugit/nat.rb, line 42 def do_parse(s, opts={}) parse(s, opts.merge(do_parse: true)) || fail(ArgumentError.new("could not parse a nat #{s.inspect}")) end
parse(s, opts={})
click to toggle source
# File lib/fugit/nat.rb, line 14 def parse(s, opts={}) return s if s.is_a?(Fugit::Cron) || s.is_a?(Fugit::Duration) return nil unless s.is_a?(String) s = s.strip if s.length > MAX_INPUT_LENGTH fail ArgumentError.new( "input too long for a nat string, " + "#{s.length} > #{MAX_INPUT_LENGTH}" ) if opts[:do_parse] return nil end #p s; Raabro.pp(Parser.parse(s, debug: 3), colours: true) #(p s; Raabro.pp(Parser.parse(s, debug: 1), colours: true)) rescue nil if slots = Parser.parse(s) slots.to_crons(opts.merge(_s: s)) else nil end end