app/models/chargeback_rate_detail.rb
# Check that tiers are complete and disjoint
Check that tiers are complete and disjoint
Check that tiers are complete and disjoint
def contiguous_tiers?
    error = false
    tiers = chargeback_tiers.sort_by(&:start)
    tiers.each_with_index do |tier, index|
      if single_tier?(tier,tiers)
        error = true if !tier.starts_with_zero? || !tier.ends_with_infinity?
      elsif first_tier?(tier,tiers)
        error = true if !tier.starts_with_zero? || tier.ends_with_infinity?
      elsif last_tier?(tier,tiers)
        error = true if !consecutive_tiers?(tier, tiers[index - 1])
        error = true if !tier.ends_with_infinity?
      elsif middle_tier?(tier,tiers)
        error = true if !consecutive_tiers?(tier, tiers[index - 1])
        error = true if tier.ends_with_infinity?
      end
      break if error
    end
    errors.add(:chargeback_tiers, _("must start at zero and not contain any gaps between start and prior end value.")) if error
    !error
  end
def contiguous_tiers? error = false tiers = chargeback_tiers . sort_by ( & :start ) tiers . each_with_index do | tier , index | if single_tier? ( tier , tiers ) error = true if ! tier . starts_with_zero? || ! tier . ends_with_infinity? elsif first_tier? ( tier , tiers ) error = true if ! tier . starts_with_zero? || tier . ends_with_infinity? elsif last_tier? ( tier , tiers ) error = true if ! consecutive_tiers? ( tier , tiers [ index - 1 ] ) error = true if ! tier . ends_with_infinity? elsif middle_tier? ( tier , tiers ) error = true if ! consecutive_tiers? ( tier , tiers [ index - 1 ] ) error = true if tier . ends_with_infinity? end break if error end errors . add ( :chargeback_tiers , _ ( "must start at zero and not contain any gaps between start and prior end value." ) ) if error ! error end
Check that tiers are complete and disjoint
Check that tiers are complete and disjoint
# Note, we use sort_by vs. order since we need to call this method against # the in memory chargeback_tiers association and NOT hit the database.