Class: NewStoreApi::PercentageDiscount
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- NewStoreApi::PercentageDiscount
- Defined in:
- lib/new_store_api/models/percentage_discount.rb
Overview
A percentage discount.
Instance Attribute Summary collapse
-
#applied_amount ⇒ Integer
The discount amount applied to this line item, in the currency's minor unit.
-
#coupon_code ⇒ String
The coupon code that triggered the discount, when one was used.
-
#description ⇒ String
Human-readable description of why the discount was applied.
-
#external_reference ⇒ String
To identify the discount in the external system.
-
#id ⇒ UUID | String
ID of the discount; shared across all lines from the same promotion so downstream can aggregate them.
-
#rate ⇒ Float
The discount percentage (0-100).
-
#scope ⇒ LevelEnum
Whether the discount was applied at the item level or prorated from an order-level discount.
-
#type ⇒ String
readonly
Discriminates a percentage discount.
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(applied_amount = nil, id = nil, rate = nil, scope = nil, coupon_code = SKIP, description = SKIP, external_reference = SKIP) ⇒ PercentageDiscount
constructor
A new instance of PercentageDiscount.
-
#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(applied_amount = nil, id = nil, rate = nil, scope = nil, coupon_code = SKIP, description = SKIP, external_reference = SKIP) ⇒ PercentageDiscount
Returns a new instance of PercentageDiscount.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 80 def initialize(applied_amount = nil, id = nil, rate = nil, scope = nil, coupon_code = SKIP, description = SKIP, external_reference = SKIP) @applied_amount = applied_amount @coupon_code = coupon_code unless coupon_code == SKIP @description = description unless description == SKIP @external_reference = external_reference unless external_reference == SKIP @id = id @rate = rate @scope = scope @type = 'percentage' end |
Instance Attribute Details
#applied_amount ⇒ Integer
The discount amount applied to this line item, in the currency's minor unit. For a discount prorated from an order-level promotion, this is only this line's share.
16 17 18 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 16 def applied_amount @applied_amount end |
#coupon_code ⇒ String
The coupon code that triggered the discount, when one was used.
20 21 22 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 20 def coupon_code @coupon_code end |
#description ⇒ String
Human-readable description of why the discount was applied.
24 25 26 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 24 def description @description end |
#external_reference ⇒ String
To identify the discount in the external system.
28 29 30 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 28 def external_reference @external_reference end |
#id ⇒ UUID | String
ID of the discount; shared across all lines from the same promotion so downstream can aggregate them.
33 34 35 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 33 def id @id end |
#rate ⇒ Float
The discount percentage (0-100).
37 38 39 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 37 def rate @rate end |
#scope ⇒ LevelEnum
Whether the discount was applied at the item level or prorated from an order-level discount.
42 43 44 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 42 def scope @scope end |
#type ⇒ String (readonly)
Discriminates a percentage discount.
46 47 48 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 46 def type @type end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 94 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. applied_amount = hash.key?('applied_amount') ? hash['applied_amount'] : nil id = hash.key?('id') ? hash['id'] : nil rate = hash.key?('rate') ? hash['rate'] : nil scope = hash.key?('scope') ? hash['scope'] : nil coupon_code = hash.key?('coupon_code') ? hash['coupon_code'] : SKIP description = hash.key?('description') ? hash['description'] : SKIP external_reference = hash.key?('external_reference') ? hash['external_reference'] : SKIP # Create object from extracted values. PercentageDiscount.new(applied_amount, id, rate, scope, coupon_code, description, external_reference) end |
.names ⇒ Object
A mapping from model property names to API property names.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 49 def self.names @_hash = {} if @_hash.nil? @_hash['applied_amount'] = 'applied_amount' @_hash['coupon_code'] = 'coupon_code' @_hash['description'] = 'description' @_hash['external_reference'] = 'external_reference' @_hash['id'] = 'id' @_hash['rate'] = 'rate' @_hash['scope'] = 'scope' @_hash['type'] = 'type' @_hash end |
.nullables ⇒ Object
An array for nullable fields
72 73 74 75 76 77 78 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 72 def self.nullables %w[ coupon_code description external_reference ] end |
.optionals ⇒ Object
An array for optional fields
63 64 65 66 67 68 69 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 63 def self.optionals %w[ coupon_code description external_reference ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 120 def self.validate(value) if value.instance_of? self return ( APIHelper.valid_type?(value.applied_amount, ->(val) { val.instance_of? Integer }) and APIHelper.valid_type?(value.id, ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value.rate, ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value.scope, ->(val) { LevelEnum.validate(val) }) and APIHelper.valid_type?(value.type, ->(val) { val.instance_of? String }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['applied_amount'], ->(val) { val.instance_of? Integer }) and APIHelper.valid_type?(value['id'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['rate'], ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value['scope'], ->(val) { LevelEnum.validate(val) }) and APIHelper.valid_type?(value['type'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
161 162 163 164 165 166 167 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 161 def inspect class_name = self.class.name.split('::').last "<#{class_name} applied_amount: #{@applied_amount.inspect}, coupon_code:"\ " #{@coupon_code.inspect}, description: #{@description.inspect}, external_reference:"\ " #{@external_reference.inspect}, id: #{@id.inspect}, rate: #{@rate.inspect}, scope:"\ " #{@scope.inspect}, type: #{@type.inspect}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
153 154 155 156 157 158 |
# File 'lib/new_store_api/models/percentage_discount.rb', line 153 def to_s class_name = self.class.name.split('::').last "<#{class_name} applied_amount: #{@applied_amount}, coupon_code: #{@coupon_code},"\ " description: #{@description}, external_reference: #{@external_reference}, id: #{@id},"\ " rate: #{@rate}, scope: #{@scope}, type: #{@type}>" end |