Created
September 23, 2016 20:08
-
-
Save martinstreicher/c270005c38cfa874ca095c9ddf10ffbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Device < ActiveRecord::Base | |
belongs_to :participant | |
validates :participant, presence: true | |
validates :provider, presence: true | |
validates :serial_number, presence: true, uniqueness: { scope: :provider } | |
validates :serial_number, format: { with: /\A\d{15}\z/, message: 'IMEI must be 15 digits'}, | |
if: lambda { |d| d.provider == 'bodytrace' } | |
before_validation :normalize | |
private | |
def normalize | |
self.provider = provider&.downcase | |
self.serial_number = self.class.normalize_serial_number serial_number | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment