Sha256: 2cb6ca494c2b2c31e5bf757044b812f31b8782d29c60e7ed779aee2a69678386

Contents?: true

Size: 838 Bytes

Versions: 5

Compression:

Stored size: 838 Bytes

Contents

module Mks
  module Rate
    class ChargeableServiceDiscount < ApplicationRecord
      validates :unit_variable, :from, :to, :value, :chargeable_service_id, presence: true
      validate :compare_from_and_to
      validate :check_for_negative_value

      belongs_to :chargeable_service

      private

      def compare_from_and_to
        if !from.nil? && !to.nil?
          if from > to
            errors.add(:from, 'The value of from can not exced the value of to')
          end
        end
      end

      def check_for_negative_value
        if !from.nil? && !to.nil?
          if from.negative?
            errors.add(:from, 'The value of from can not be less than zero')
          elsif to.negative?
            errors.add(:to, 'The value of to can not be less than zero')
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mks_rate-1.0.5 app/models/mks/rate/chargeable_service_discount.rb
mks_rate-1.0.4 app/models/mks/rate/chargeable_service_discount.rb
mks_rate-1.0.3 app/models/mks/rate/chargeable_service_discount.rb
mks_rate-1.0.2 app/models/mks/rate/chargeable_service_discount.rb
mks_rate-1.0.1 app/models/mks/rate/chargeable_service_discount.rb