Class: ApiReference::TrialDiscount
- Defined in:
- lib/api_reference/models/trial_discount.rb
Overview
TrialDiscount Model.
Instance Attribute Summary collapse
-
#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.
-
#trial_amount_discount ⇒ String
Only available if discount_type is
trial. -
#trial_percentage_discount ⇒ Float
Only available if discount_type is
trial.
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(applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, trial_amount_discount: SKIP, trial_percentage_discount: SKIP, additional_properties: nil) ⇒ TrialDiscount
constructor
A new instance of TrialDiscount.
-
#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(applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, trial_amount_discount: SKIP, trial_percentage_discount: SKIP, additional_properties: nil) ⇒ TrialDiscount
Returns a new instance of TrialDiscount.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/api_reference/models/trial_discount.rb', line 71 def initialize(applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, trial_amount_discount: SKIP, trial_percentage_discount: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @discount_type = 'trial' @applies_to_price_ids = applies_to_price_ids unless applies_to_price_ids == SKIP @filters = filters unless filters == SKIP @reason = reason unless reason == SKIP @trial_amount_discount = trial_amount_discount unless trial_amount_discount == SKIP unless trial_percentage_discount == SKIP @trial_percentage_discount = trial_percentage_discount end @additional_properties = additional_properties end |
Instance Attribute Details
#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/trial_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/trial_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/trial_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/trial_discount.rb', line 27 def reason @reason end |
#trial_amount_discount ⇒ String
Only available if discount_type is trial
31 32 33 |
# File 'lib/api_reference/models/trial_discount.rb', line 31 def trial_amount_discount @trial_amount_discount end |
#trial_percentage_discount ⇒ Float
Only available if discount_type is trial
35 36 37 |
# File 'lib/api_reference/models/trial_discount.rb', line 35 def trial_percentage_discount @trial_percentage_discount end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/api_reference/models/trial_discount.rb', line 90 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. 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 trial_amount_discount = hash.key?('trial_amount_discount') ? hash['trial_amount_discount'] : SKIP trial_percentage_discount = hash.key?('trial_percentage_discount') ? hash['trial_percentage_discount'] : 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. TrialDiscount.new(applies_to_price_ids: applies_to_price_ids, filters: filters, reason: reason, trial_amount_discount: trial_amount_discount, trial_percentage_discount: trial_percentage_discount, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/api_reference/models/trial_discount.rb', line 38 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['trial_amount_discount'] = 'trial_amount_discount' @_hash['trial_percentage_discount'] = 'trial_percentage_discount' @_hash end |
.nullables ⇒ Object
An array for nullable fields
61 62 63 64 65 66 67 68 69 |
# File 'lib/api_reference/models/trial_discount.rb', line 61 def self.nullables %w[ applies_to_price_ids filters reason trial_amount_discount trial_percentage_discount ] end |
.optionals ⇒ Object
An array for optional fields
50 51 52 53 54 55 56 57 58 |
# File 'lib/api_reference/models/trial_discount.rb', line 50 def self.optionals %w[ applies_to_price_ids filters reason trial_amount_discount trial_percentage_discount ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/api_reference/models/trial_discount.rb', line 130 def self.validate(value) if value.instance_of? self return APIHelper.valid_type?(value.discount_type, ->(val) { val.instance_of? String }) end return false unless value.instance_of? Hash APIHelper.valid_type?(value['discount_type'], ->(val) { val.instance_of? String }) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
152 153 154 155 156 157 158 159 |
# File 'lib/api_reference/models/trial_discount.rb', line 152 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}, trial_amount_discount: #{@trial_amount_discount.inspect},"\ " trial_percentage_discount: #{@trial_percentage_discount.inspect}, additional_properties:"\ " #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
143 144 145 146 147 148 149 |
# File 'lib/api_reference/models/trial_discount.rb', line 143 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}, trial_amount_discount:"\ " #{@trial_amount_discount}, trial_percentage_discount: #{@trial_percentage_discount},"\ " additional_properties: #{@additional_properties}>" end |