Class: Optimist::DateOption
- Defined in:
- lib/rbcli/components/parser/optimist/optimist.rb
Overview
Option for dates. Uses Chronic if it exists.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Option
#default, #long, #multi_given, #name, #permitted, #short
Instance Method Summary collapse
Methods inherited from Option
#array_default?, #callback, create, #desc, #educate, #flag?, #full_description, #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
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
# File 'lib/rbcli/components/parser/optimist/optimist.rb', line 934 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_format ⇒ Object
930 931 932 |
# File 'lib/rbcli/components/parser/optimist/optimist.rb', line 930 def type_format "=<date>"; end |