Class: Optimist::DateOption

Inherits:
Option
  • Object
show all
Defined in:
lib/optimist_with_insert_blanks.rb

Overview

Option for dates. Uses Chronic if it exists.

Direct Known Subclasses

DateArrayOption

Instance Attribute Summary

Attributes inherited from Option

#default, #long, #multi_given, #name, #short

Instance Method Summary collapse

Methods inherited from Option

#array_default?, #callback, create, #desc, #description_with_default, #educate, #flag?, get_klass_from_default, get_type_from_disdef, handle_long_opt, handle_short_opt, #initialize, #multi, #multi_arg?, #opts, #opts=, register_alias, #required?, #short?, #single_arg?

Constructor Details

This class inherits a constructor from Optimist::Option

Instance Method Details

#parse(paramlist, _neg_given) ⇒ Object



997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/optimist_with_insert_blanks.rb', line 997

def parse(paramlist, _neg_given)
  paramlist.map do |pg|
    pg.map do |param|
      next param if param.is_a?(Date)

      begin
        begin
          require 'chronic'
          time = Chronic.parse(param)
        rescue LoadError
          # chronic is not available
        end
        time ? Date.new(time.year, time.month, time.day) : Date.parse(param)
      rescue ArgumentError
        raise CommandlineError, "option '#{name}' needs a date"
      end
    end
  end
end

#type_formatObject



993
994
995
# File 'lib/optimist_with_insert_blanks.rb', line 993

def type_format
  '=<date>'
end