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

Version Path
artfully_ose-1.2.0 app/models/imports/validations.rb
artfully_ose-1.2.0.beta.1 app/models/imports/validations.rb
artfully_ose-1.2.0.alpha.2 app/models/imports/validations.rb
artfully_ose-1.2.0.alpha.1 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.27 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.26 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.24 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.23 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.21 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.20 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.19 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.18 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.17 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.16 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.15 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.12 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.11 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.10 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.9 app/models/imports/validations.rb
artfully_ose-1.2.0.pre.8 app/models/imports/validations.rb