Module: Fugit::Nat

Defined in:
lib/fugit/nat.rb

Overview

A natural language set of parsers for fugit. Focuses on cron expressions. The rest is better left to Chronic and friends.

Defined Under Namespace

Modules: Parser Classes: Slot, SlotGroup

Class Method Summary collapse

Class Method Details

.do_parse(s, opts = {}) ⇒ Object



30
31
32
33
34
# File 'lib/fugit/nat.rb', line 30

def do_parse(s, opts={})

  parse(s, opts) ||
  fail(ArgumentError.new("could not parse a nat #{s.inspect}"))
end

.parse(s, opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fugit/nat.rb', line 12

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

#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