lib/ig_markets/cli/main.rb
# Parses and validates a `Date` or `Time` option received as a command-line argument. Raises `ArgumentError` if
# it has been specified in an invalid format.
#
# @param [Hash] attributes The attributes hash.
# @param [Symbol] attribute The name of the date or time attribute to parse and validate.
# @param [Date, Time] klass The class to validate with.
# @param [String] format The `strptime` format string for the attribute.
# @param [String] display_format The human-readable version of `format` to put into the raised exception if
#                 there is a problem parsing the attribute.
Parses and validates a `Date` or `Time` option received as a command-line argument. Raises `ArgumentError` if
it has been specified in an invalid format.
Parses and validates a ` Date ` or ` Time ` option received as a command - line argument . Raises ` ArgumentError ` if it has been specified in an invalid format .
def parse_date_time(attributes, attribute, klass, format, display_format)
          return unless attributes.key? attribute
          if !['', attribute.to_s].include? attributes[attribute].to_s
            begin
              attributes[attribute] = klass.strptime attributes[attribute], format
            rescue ArgumentError
              raise ArgumentError, %(invalid #{attribute}, use format "#{display_format}")
            end
          else
            attributes[attribute] = nil
          end
        end
def parse_date_time ( attributes , attribute , klass , format , display_format ) return unless attributes . key? attribute if ! [ '' , attribute . to_s ] . include? attributes [ attribute ] . to_s begin attributes [ attribute ] = klass . strptime attributes [ attribute ] , format rescue ArgumentError raise ArgumentError , %(invalid #{attribute}, use format "#{display_format}") end else attributes [ attribute ] = nil end end
Parses and validates a `Date` or `Time` option received as a command-line argument.
Parses and validates a ` Date ` or ` Time ` option received as a command - line argument .
attributes
attribute
klass
format
display_format
display_format The human-readable version of `format` to put into the raised exception if there is a problem parsing the attribute.
display_format The human - readable version of ` format ` to put into the raised exception if there is a problem parsing the attribute .