Class: Optimist::DateOption

Inherits:
Option
  • Object
show all
Defined in:
lib/optimist.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, #permitted, #permitted_response, #short

Instance Method Summary collapse

Methods inherited from Option

#array_default?, #callback, create, #desc, #doesnt_need_autogen_short, #educate, #flag?, #format_stdio, #full_description, #initialize, #multi, #multi_arg?, #opts, #opts=, #permitted_type_valid?, #permitted_valid_string, #permitted_value?, register_alias, #required?, #single_arg?, #validate_permitted

Constructor Details

This class inherits a constructor from Optimist::Option

Instance Method Details

#parse(paramlist, _neg_given) ⇒ Object



1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# File 'lib/optimist.rb', line 1076

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 '#{self.name}' needs a date"
      end
    end
  end
end

#type_formatObject



1075
# File 'lib/optimist.rb', line 1075

def type_format ; "=<date>" ; end