Class: ApiReference::CreditNoteDiscount
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- ApiReference::CreditNoteDiscount
- Defined in:
- lib/api_reference/models/credit_note_discount.rb
Overview
CreditNoteDiscount Model.
Instance Attribute Summary collapse
-
#amount_applied ⇒ String
TODO: Write general description for this method.
-
#applies_to_prices ⇒ Array[CreditNoteDiscountAppliesToPrice]
TODO: Write general description for this method.
-
#discount_type ⇒ String
readonly
TODO: Write general description for this method.
-
#percentage_discount ⇒ Float
TODO: Write general description for this method.
-
#reason ⇒ String
TODO: Write general description for this method.
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(percentage_discount:, amount_applied:, reason: SKIP, applies_to_prices: SKIP, additional_properties: nil) ⇒ CreditNoteDiscount
constructor
A new instance of CreditNoteDiscount.
-
#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(percentage_discount:, amount_applied:, reason: SKIP, applies_to_prices: SKIP, additional_properties: nil) ⇒ CreditNoteDiscount
Returns a new instance of CreditNoteDiscount.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 59 def initialize(percentage_discount:, amount_applied:, reason: SKIP, applies_to_prices: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @discount_type = 'percentage' @percentage_discount = percentage_discount @amount_applied = amount_applied @reason = reason unless reason == SKIP @applies_to_prices = applies_to_prices unless applies_to_prices == SKIP @additional_properties = additional_properties end |
Instance Attribute Details
#amount_applied ⇒ String
TODO: Write general description for this method
22 23 24 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 22 def amount_applied @amount_applied end |
#applies_to_prices ⇒ Array[CreditNoteDiscountAppliesToPrice]
TODO: Write general description for this method
30 31 32 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 30 def applies_to_prices @applies_to_prices end |
#discount_type ⇒ String (readonly)
TODO: Write general description for this method
14 15 16 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 14 def discount_type @discount_type end |
#percentage_discount ⇒ Float
TODO: Write general description for this method
18 19 20 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 18 def percentage_discount @percentage_discount end |
#reason ⇒ String
TODO: Write general description for this method
26 27 28 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 26 def reason @reason end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
73 74 75 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 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 73 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. percentage_discount = hash.key?('percentage_discount') ? hash['percentage_discount'] : nil amount_applied = hash.key?('amount_applied') ? hash['amount_applied'] : nil reason = hash.key?('reason') ? hash['reason'] : SKIP # Parameter is an array, so we need to iterate through it applies_to_prices = nil unless hash['applies_to_prices'].nil? applies_to_prices = [] hash['applies_to_prices'].each do |structure| applies_to_prices << (CreditNoteDiscountAppliesToPrice.from_hash(structure) if structure) end end applies_to_prices = SKIP unless hash.key?('applies_to_prices') # 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. CreditNoteDiscount.new(percentage_discount: percentage_discount, amount_applied: amount_applied, reason: reason, applies_to_prices: applies_to_prices, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
33 34 35 36 37 38 39 40 41 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 33 def self.names @_hash = {} if @_hash.nil? @_hash['discount_type'] = 'discount_type' @_hash['percentage_discount'] = 'percentage_discount' @_hash['amount_applied'] = 'amount_applied' @_hash['reason'] = 'reason' @_hash['applies_to_prices'] = 'applies_to_prices' @_hash end |
.nullables ⇒ Object
An array for nullable fields
52 53 54 55 56 57 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 52 def self.nullables %w[ reason applies_to_prices ] end |
.optionals ⇒ Object
An array for optional fields
44 45 46 47 48 49 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 44 def self.optionals %w[ reason applies_to_prices ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 110 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.percentage_discount, ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value.amount_applied, ->(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['percentage_discount'], ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value['amount_applied'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
144 145 146 147 148 149 150 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 144 def inspect class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type.inspect}, percentage_discount:"\ " #{@percentage_discount.inspect}, amount_applied: #{@amount_applied.inspect}, reason:"\ " #{@reason.inspect}, applies_to_prices: #{@applies_to_prices.inspect},"\ " additional_properties: #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
135 136 137 138 139 140 141 |
# File 'lib/api_reference/models/credit_note_discount.rb', line 135 def to_s class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type}, percentage_discount:"\ " #{@percentage_discount}, amount_applied: #{@amount_applied}, reason: #{@reason},"\ " applies_to_prices: #{@applies_to_prices}, additional_properties:"\ " #{@additional_properties}>" end |