Class: AdvancedBilling::CompoundingStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/advanced_billing/models/compounding_strategy.rb

Overview

Applicable only to stackable coupons. For ‘compound`, Percentage-based discounts will be calculated against the remaining price, after prior discounts have been calculated. For `full-price`, Percentage-based discounts will always be calculated against the original item price, before other discounts are applied.

Constant Summary collapse

COMPOUNDING_STRATEGY =
[
  # TODO: Write general description for COMPOUND
  COMPOUND = 'compound'.freeze,

  # TODO: Write general description for FULLPRICE
  FULLPRICE = 'full-price'.freeze
].freeze

Class Method Summary collapse

Class Method Details

.from_value(value, default_value = COMPOUND) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/advanced_billing/models/compounding_strategy.rb', line 27

def self.from_value(value, default_value = COMPOUND)
  return default_value if value.nil?

  str = value.to_s.strip

  case str.downcase
  when 'compound' then COMPOUND
  when 'fullprice' then FULLPRICE
  else
    default_value
  end
end

.validate(value) ⇒ Object



21
22
23
24
25
# File 'lib/advanced_billing/models/compounding_strategy.rb', line 21

def self.validate(value)
  return false if value.nil?

  COMPOUNDING_STRATEGY.include?(value)
end