# encoding: utf-8 module Okei # Stores and validates units of measure class Unit < ActiveRecord::Base UUID_FORMAT = /\A[\d|a-f]{8}-([\d|a-f]{4}-){3}[\d|a-f]{12}\z/ NUM_FORMAT = /\A\d{3}\z/ validates :uuid, :code, :name, :base, :factor, :measure, presence: true validates :uuid, :code, :name, uniqueness: true, allow_nil: true validates :factor, allow_nil: true, numericality: { greater_than: 0.0 } validates :num, allow_nil: true, format: { with: NUM_FORMAT } validates :uuid, allow_nil: true, format: { with: UUID_FORMAT } end end