Class: ApiReference::AmountDiscountInterval
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- ApiReference::AmountDiscountInterval
- Defined in:
- lib/api_reference/models/amount_discount_interval.rb
Overview
AmountDiscountInterval Model.
Instance Attribute Summary collapse
-
#amount_discount ⇒ String
Only available if discount_type is
amount. -
#applies_to_price_interval_ids ⇒ Array[String]
The price interval ids that this discount interval applies to.
-
#discount_type ⇒ String
readonly
TODO: Write general description for this method.
-
#end_date ⇒ DateTime
The end date of the discount interval.
-
#filters ⇒ Array[PriceFilter]
The filters that determine which prices this discount interval applies to.
-
#start_date ⇒ DateTime
The start date of the discount interval.
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:, start_date:, end_date:, filters:, applies_to_price_interval_ids:, additional_properties: nil) ⇒ AmountDiscountInterval
constructor
A new instance of AmountDiscountInterval.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_end_date ⇒ Object
- #to_custom_start_date ⇒ Object
-
#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:, start_date:, end_date:, filters:, applies_to_price_interval_ids:, additional_properties: nil) ⇒ AmountDiscountInterval
Returns a new instance of AmountDiscountInterval.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 62 def initialize(amount_discount:, start_date:, end_date:, filters:, applies_to_price_interval_ids:, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @discount_type = 'amount' @amount_discount = amount_discount @start_date = start_date @end_date = end_date @filters = filters @applies_to_price_interval_ids = applies_to_price_interval_ids @additional_properties = additional_properties end |
Instance Attribute Details
#amount_discount ⇒ String
Only available if discount_type is amount.
19 20 21 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 19 def amount_discount @amount_discount end |
#applies_to_price_interval_ids ⇒ Array[String]
The price interval ids that this discount interval applies to.
35 36 37 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 35 def applies_to_price_interval_ids @applies_to_price_interval_ids end |
#discount_type ⇒ String (readonly)
TODO: Write general description for this method
15 16 17 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 15 def discount_type @discount_type end |
#end_date ⇒ DateTime
The end date of the discount interval.
27 28 29 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 27 def end_date @end_date end |
#filters ⇒ Array[PriceFilter]
The filters that determine which prices this discount interval applies to.
31 32 33 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 31 def filters @filters end |
#start_date ⇒ DateTime
The start date of the discount interval.
23 24 25 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 23 def start_date @start_date 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 111 112 113 114 115 116 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 77 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. amount_discount = hash.key?('amount_discount') ? hash['amount_discount'] : nil start_date = if hash.key?('start_date') (DateTimeHelper.from_rfc3339(hash['start_date']) if hash['start_date']) end end_date = if hash.key?('end_date') (DateTimeHelper.from_rfc3339(hash['end_date']) if hash['end_date']) end # 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 = nil unless hash.key?('filters') applies_to_price_interval_ids = hash.key?('applies_to_price_interval_ids') ? hash['applies_to_price_interval_ids'] : nil # 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. AmountDiscountInterval.new(amount_discount: amount_discount, start_date: start_date, end_date: end_date, filters: filters, applies_to_price_interval_ids: applies_to_price_interval_ids, 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 48 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 38 def self.names @_hash = {} if @_hash.nil? @_hash['discount_type'] = 'discount_type' @_hash['amount_discount'] = 'amount_discount' @_hash['start_date'] = 'start_date' @_hash['end_date'] = 'end_date' @_hash['filters'] = 'filters' @_hash['applies_to_price_interval_ids'] = 'applies_to_price_interval_ids' @_hash end |
.nullables ⇒ Object
An array for nullable fields
56 57 58 59 60 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 56 def self.nullables %w[ end_date ] end |
.optionals ⇒ Object
An array for optional fields
51 52 53 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 51 def self.optionals [] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 128 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 }) and APIHelper.valid_type?(value.start_date, ->(val) { val.instance_of? DateTime }) and APIHelper.valid_type?(value.end_date, ->(val) { val.instance_of? DateTime }) and APIHelper.valid_type?(value.filters, ->(val) { PriceFilter.validate(val) }, is_model_hash: true, is_inner_model_hash: true) and APIHelper.valid_type?(value.applies_to_price_interval_ids, ->(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 }) and APIHelper.valid_type?(value['start_date'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['end_date'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['filters'], ->(val) { PriceFilter.validate(val) }, is_model_hash: true, is_inner_model_hash: true) and APIHelper.valid_type?(value['applies_to_price_interval_ids'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
178 179 180 181 182 183 184 185 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 178 def inspect class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type.inspect}, amount_discount:"\ " #{@amount_discount.inspect}, start_date: #{@start_date.inspect}, end_date:"\ " #{@end_date.inspect}, filters: #{@filters.inspect}, applies_to_price_interval_ids:"\ " #{@applies_to_price_interval_ids.inspect}, additional_properties:"\ " #{@additional_properties}>" end |
#to_custom_end_date ⇒ Object
122 123 124 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 122 def to_custom_end_date DateTimeHelper.to_rfc3339(end_date) end |
#to_custom_start_date ⇒ Object
118 119 120 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 118 def to_custom_start_date DateTimeHelper.to_rfc3339(start_date) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
169 170 171 172 173 174 175 |
# File 'lib/api_reference/models/amount_discount_interval.rb', line 169 def to_s class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type}, amount_discount: #{@amount_discount},"\ " start_date: #{@start_date}, end_date: #{@end_date}, filters: #{@filters},"\ " applies_to_price_interval_ids: #{@applies_to_price_interval_ids}, additional_properties:"\ " #{@additional_properties}>" end |