Class: ApiReference::AmountDiscount
- Defined in:
- lib/api_reference/models/amount_discount.rb
Overview
AmountDiscount Model.
Instance Attribute Summary collapse
-
#amount_discount ⇒ String
Only available if discount_type is
amount. -
#applies_to_price_ids ⇒ Array[String]
List of price_ids that this discount applies to.
-
#discount_type ⇒ String
readonly
TODO: Write general description for this method.
-
#filters ⇒ Array[PriceFilter]
The filters that determine which prices to apply this discount to.
-
#reason ⇒ String
The filters that determine which prices to apply this discount to.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(amount_discount:, applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, additional_properties: nil) ⇒ AmountDiscount
constructor
A new instance of AmountDiscount.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(amount_discount:, applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, additional_properties: nil) ⇒ AmountDiscount
Returns a new instance of AmountDiscount.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/api_reference/models/amount_discount.rb', line 62 def initialize(amount_discount:, applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @discount_type = 'amount' @applies_to_price_ids = applies_to_price_ids unless applies_to_price_ids == SKIP @filters = filters unless filters == SKIP @reason = reason unless reason == SKIP @amount_discount = amount_discount @additional_properties = additional_properties end |
Instance Attribute Details
#amount_discount ⇒ String
Only available if discount_type is amount.
31 32 33 |
# File 'lib/api_reference/models/amount_discount.rb', line 31 def amount_discount @amount_discount end |
#applies_to_price_ids ⇒ Array[String]
List of price_ids that this discount applies to. For plan/plan phase discounts, this can be a subset of prices.
19 20 21 |
# File 'lib/api_reference/models/amount_discount.rb', line 19 def applies_to_price_ids @applies_to_price_ids end |
#discount_type ⇒ String (readonly)
TODO: Write general description for this method
14 15 16 |
# File 'lib/api_reference/models/amount_discount.rb', line 14 def discount_type @discount_type end |
#filters ⇒ Array[PriceFilter]
The filters that determine which prices to apply this discount to.
23 24 25 |
# File 'lib/api_reference/models/amount_discount.rb', line 23 def filters @filters end |
#reason ⇒ String
The filters that determine which prices to apply this discount to.
27 28 29 |
# File 'lib/api_reference/models/amount_discount.rb', line 27 def reason @reason end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/api_reference/models/amount_discount.rb', line 76 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. amount_discount = hash.key?('amount_discount') ? hash['amount_discount'] : nil applies_to_price_ids = hash.key?('applies_to_price_ids') ? hash['applies_to_price_ids'] : SKIP # Parameter is an array, so we need to iterate through it filters = nil unless hash['filters'].nil? filters = [] hash['filters'].each do |structure| filters << (PriceFilter.from_hash(structure) if structure) end end filters = SKIP unless hash.key?('filters') reason = hash.key?('reason') ? hash['reason'] : SKIP # Create a new hash for additional properties, removing known properties. new_hash = hash.reject { |k, _| names.value?(k) } additional_properties = APIHelper.get_additional_properties( new_hash, proc { |value| value } ) # Create object from extracted values. AmountDiscount.new(amount_discount: amount_discount, applies_to_price_ids: applies_to_price_ids, filters: filters, reason: reason, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
34 35 36 37 38 39 40 41 42 |
# File 'lib/api_reference/models/amount_discount.rb', line 34 def self.names @_hash = {} if @_hash.nil? @_hash['discount_type'] = 'discount_type' @_hash['applies_to_price_ids'] = 'applies_to_price_ids' @_hash['filters'] = 'filters' @_hash['reason'] = 'reason' @_hash['amount_discount'] = 'amount_discount' @_hash end |
.nullables ⇒ Object
An array for nullable fields
54 55 56 57 58 59 60 |
# File 'lib/api_reference/models/amount_discount.rb', line 54 def self.nullables %w[ applies_to_price_ids filters reason ] end |
.optionals ⇒ Object
An array for optional fields
45 46 47 48 49 50 51 |
# File 'lib/api_reference/models/amount_discount.rb', line 45 def self.optionals %w[ applies_to_price_ids filters reason ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/api_reference/models/amount_discount.rb', line 113 def self.validate(value) if value.instance_of? self return ( APIHelper.valid_type?(value.discount_type, ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value.amount_discount, ->(val) { val.instance_of? String }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['discount_type'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['amount_discount'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
142 143 144 145 146 147 148 |
# File 'lib/api_reference/models/amount_discount.rb', line 142 def inspect class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type.inspect}, applies_to_price_ids:"\ " #{@applies_to_price_ids.inspect}, filters: #{@filters.inspect}, reason:"\ " #{@reason.inspect}, amount_discount: #{@amount_discount.inspect}, additional_properties:"\ " #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
134 135 136 137 138 139 |
# File 'lib/api_reference/models/amount_discount.rb', line 134 def to_s class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type}, applies_to_price_ids:"\ " #{@applies_to_price_ids}, filters: #{@filters}, reason: #{@reason}, amount_discount:"\ " #{@amount_discount}, additional_properties: #{@additional_properties}>" end |