Class: ApiReference::PercentCompositeConfig

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/percent_composite_config.rb

Overview

Configuration for a percent composite price. Charges percent of the sum of upstream subtotals matched by this price's composite filters. Optional minimum_amount and maximum_amount clamp the computed amount — leave both null for a pure pass-through percentage. Canonical bounded use case — service charge of the form "monthly fee = greater of X% of usage and $A, capped at $B": PercentCompositeConfig( percent=Decimal("0.08"), minimum_amount=MonetaryAmount(Decimal("5000")), maximum_amount=MonetaryAmount(Decimal("50000")), ) upstream sum $0 → fee $5,000 (minimum_amount) upstream sum $50,000 → fee $5,000 (minimum_amount; 8% = $4K < minimum_amount) upstream sum $100,000 → fee $8,000 (within bounds) upstream sum $1,000,000 → fee $50,000 (maximum_amount)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(percent:, minimum_amount: SKIP, maximum_amount: SKIP, prorated: SKIP) ⇒ PercentCompositeConfig

Returns a new instance of PercentCompositeConfig.



68
69
70
71
72
73
74
# File 'lib/api_reference/models/percent_composite_config.rb', line 68

def initialize(percent:, minimum_amount: SKIP, maximum_amount: SKIP,
               prorated: SKIP)
  @percent = percent
  @minimum_amount = minimum_amount unless minimum_amount == SKIP
  @maximum_amount = maximum_amount unless maximum_amount == SKIP
  @prorated = prorated unless prorated == SKIP
end

Instance Attribute Details

#maximum_amountString

Maximum amount to charge. If unset, the fee has no upper bound.

Returns:

  • (String)


33
34
35
# File 'lib/api_reference/models/percent_composite_config.rb', line 33

def maximum_amount
  @maximum_amount
end

#minimum_amountString

Minimum amount to charge. If unset, the fee is bounded below by 0.

Returns:

  • (String)


29
30
31
# File 'lib/api_reference/models/percent_composite_config.rb', line 29

def minimum_amount
  @minimum_amount
end

#percentFloat

Fraction of the component subtotals to charge (0 < percent <= 1).

Returns:

  • (Float)


25
26
27
# File 'lib/api_reference/models/percent_composite_config.rb', line 25

def percent
  @percent
end

#proratedTrueClass | FalseClass

If true, the minimum_amount is prorated based on the service period. The maximum_amount is an absolute cap (never prorated), and the percent applied to upstream subtotals is never prorated either.

Returns:

  • (TrueClass | FalseClass)


39
40
41
# File 'lib/api_reference/models/percent_composite_config.rb', line 39

def prorated
  @prorated
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/api_reference/models/percent_composite_config.rb', line 77

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  percent = hash.key?('percent') ? hash['percent'] : nil
  minimum_amount =
    hash.key?('minimum_amount') ? hash['minimum_amount'] : SKIP
  maximum_amount =
    hash.key?('maximum_amount') ? hash['maximum_amount'] : SKIP
  prorated = hash.key?('prorated') ? hash['prorated'] : SKIP

  # Create object from extracted values.
  PercentCompositeConfig.new(percent: percent,
                             minimum_amount: minimum_amount,
                             maximum_amount: maximum_amount,
                             prorated: prorated)
end

.namesObject

A mapping from model property names to API property names.



42
43
44
45
46
47
48
49
# File 'lib/api_reference/models/percent_composite_config.rb', line 42

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['percent'] = 'percent'
  @_hash['minimum_amount'] = 'minimum_amount'
  @_hash['maximum_amount'] = 'maximum_amount'
  @_hash['prorated'] = 'prorated'
  @_hash
end

.nullablesObject

An array for nullable fields



61
62
63
64
65
66
# File 'lib/api_reference/models/percent_composite_config.rb', line 61

def self.nullables
  %w[
    minimum_amount
    maximum_amount
  ]
end

.optionalsObject

An array for optional fields



52
53
54
55
56
57
58
# File 'lib/api_reference/models/percent_composite_config.rb', line 52

def self.optionals
  %w[
    minimum_amount
    maximum_amount
    prorated
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



103
104
105
106
107
# File 'lib/api_reference/models/percent_composite_config.rb', line 103

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} percent: #{@percent.inspect}, minimum_amount: #{@minimum_amount.inspect},"\
  " maximum_amount: #{@maximum_amount.inspect}, prorated: #{@prorated.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



96
97
98
99
100
# File 'lib/api_reference/models/percent_composite_config.rb', line 96

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} percent: #{@percent}, minimum_amount: #{@minimum_amount}, maximum_amount:"\
  " #{@maximum_amount}, prorated: #{@prorated}>"
end