Sha256: fa949c3354ce2274db0eec7cf56e6f63167130bb4ccc5655853ec0c65d61ca22

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module Fugit

  def self.parse_cron(s); ::Fugit::Cron.parse(s); end
  def self.parse_duration(s); ::Fugit::Duration.parse(s); end
  def self.parse_nat(s); ::Fugit::Nat.parse(s); end
  def self.parse_at(s); ::Fugit::At.parse(s); end
  def self.parse_in(s); parse_duration(s); end

  def self.do_parse_cron(s); ::Fugit::Cron.do_parse(s); end
  def self.do_parse_duration(s); ::Fugit::Duration.do_parse(s); end
  def self.do_parse_nat(s); ::Fugit::Nat.do_parse(s); end
  def self.do_parse_at(s); ::Fugit::At.do_parse(s); end
  def self.do_parse_in(s); do_parse_duration(s); end

  def self.parse(s, opts={})

    opts[:at] = opts[:in] if opts.has_key?(:in)

    (opts[:cron] != false && parse_cron(s)) ||
    (opts[:duration] != false && parse_duration(s)) ||
    (opts[:at] != false && parse_at(s)) ||
    (opts[:nat] != false && parse_nat(s)) ||
    nil
  end

  def self.do_parse(s, opts={})

    parse(s, opts) ||
    fail(ArgumentError.new("found no time information in #{s.inspect}"))
  end

  def self.determine_type(s)

    case self.parse(s)
    when ::Fugit::Cron then 'cron'
    when ::Fugit::Duration then 'in'
    when ::Time, ::EtOrbi::EoTime then 'at'
    else nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fugit-1.1.3 lib/fugit/parse.rb
fugit-1.1.2 lib/fugit/parse.rb
fugit-1.1.1 lib/fugit/parse.rb
fugit-1.1.0 lib/fugit/parse.rb