Sha256: 32f3fd71ce0de42d0ccdd8b7c91d2417d3c0d2c2cfebcd3643ce3b70d989fad1

Contents?: true

Size: 937 Bytes

Versions: 5

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

require 'fintecture/exceptions'

module Fintecture
  module Utils
    class Validation
      class << self
        def raise_if_klass_mismatch(target, klass, param_name = nil)
          return if target.is_a? klass

          raise Fintecture::ValidationException,
                "invalid #{param_name || 'parameter'} format, the parameter should be a #{klass} instead a #{target.class.name}"
        end

        def raise_if_invalid_date_format(date)
          return unless date

          valid_format = date.match(/\d{4}-\d{2}-\d{2}/)
          valid_date = begin
            ::Date.strptime(date, '%Y-%m-%d')
          rescue StandardError
            false
          end
          return if valid_format && valid_date

          raise Fintecture::ValidationException, "invalidss #{date} date, the format should be YYYY-MM-DD"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fintecture-0.5.1 lib/fintecture/utils/validation.rb
fintecture-0.5.0 lib/fintecture/utils/validation.rb
fintecture-0.4.1 lib/fintecture/utils/validation.rb
fintecture-0.3.1 lib/fintecture/utils/validation.rb
fintecture-0.3.0 lib/fintecture/utils/validation.rb