Class: ApiReference::UsageDiscount
- Defined in:
- lib/api_reference/models/usage_discount.rb
Overview
UsageDiscount 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.
-
#usage_discount ⇒ Float
Only available if discount_type is
usage.
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.
Instance Method Summary collapse
-
#initialize(usage_discount:, applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, additional_properties: nil) ⇒ UsageDiscount
constructor
A new instance of UsageDiscount.
-
#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(usage_discount:, applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, additional_properties: nil) ⇒ UsageDiscount
Returns a new instance of UsageDiscount.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/api_reference/models/usage_discount.rb', line 63 def initialize(usage_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 = 'usage' @applies_to_price_ids = applies_to_price_ids unless applies_to_price_ids == SKIP @filters = filters unless filters == SKIP @reason = reason unless reason == SKIP @usage_discount = usage_discount @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/usage_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/usage_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/usage_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/usage_discount.rb', line 27 def reason @reason end |
#usage_discount ⇒ Float
Only available if discount_type is usage. Number of usage units that
this discount is for
32 33 34 |
# File 'lib/api_reference/models/usage_discount.rb', line 32 def usage_discount @usage_discount 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/api_reference/models/usage_discount.rb', line 77 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. usage_discount = hash.key?('usage_discount') ? hash['usage_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. UsageDiscount.new(usage_discount: usage_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.
35 36 37 38 39 40 41 42 43 |
# File 'lib/api_reference/models/usage_discount.rb', line 35 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['usage_discount'] = 'usage_discount' @_hash end |
.nullables ⇒ Object
An array for nullable fields
55 56 57 58 59 60 61 |
# File 'lib/api_reference/models/usage_discount.rb', line 55 def self.nullables %w[ applies_to_price_ids filters reason ] end |
.optionals ⇒ Object
An array for optional fields
46 47 48 49 50 51 52 |
# File 'lib/api_reference/models/usage_discount.rb', line 46 def self.optionals %w[ applies_to_price_ids filters reason ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
121 122 123 124 125 126 127 |
# File 'lib/api_reference/models/usage_discount.rb', line 121 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}, usage_discount: #{@usage_discount.inspect}, additional_properties:"\ " #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
113 114 115 116 117 118 |
# File 'lib/api_reference/models/usage_discount.rb', line 113 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}, usage_discount:"\ " #{@usage_discount}, additional_properties: #{@additional_properties}>" end |