Sha256: d636bf87987357ffc90d7ff37fa3e9f65fd373e805295b571fb0fc20c13dc556
Contents?: true
Size: 1.08 KB
Versions: 31
Compression:
Stored size: 1.08 KB
Contents
module Imports module Validations def valid_date?(date_str) if date_str.blank? raise Import::RowError, "Please include a date" end #Check for MM/ or M/ if date_str.match(/^[0-9][0-9]\//) || date_str.match(/^[0-9]\//) raise Import::RowError, "Invalid date: #{date_str} Make sure the date is in the format YEAR/MONTH/DAY (2012/04/18) or DAY-MONTH-YEAR (18-Apr-12)." end begin DateTime.parse(date_str) rescue raise Import::RowError, "Invalid date: #{date_str} Make sure the date is in the format YEAR/MONTH/DAY (2012/04/18) or DAY-MONTH-YEAR (18-Apr-12)." end true end # # Amount should be a string. Will throw a RowError unless amount_str is all numeric with one dot and two digits after the dot # def valid_amount?(amount_str) if amount_str.match(/^\d+??(?:\.\d{0,2})?$/).nil? raise Import::RowError, "Invalid amount: #{amount_str} Please input numbers and decimal points only, no currency symbols or other characters." end end end end
Version data entries
31 entries across 31 versions & 1 rubygems