Class: ApiReference::TieredPercentageDiscountInterval

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/tiered_percentage_discount_interval.rb

Overview

TieredPercentageDiscountInterval Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(tiers:, start_date:, end_date:, filters:, applies_to_price_interval_ids:, additional_properties: nil) ⇒ TieredPercentageDiscountInterval

Returns a new instance of TieredPercentageDiscountInterval.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 64

def initialize(tiers:, 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 = 'tiered_percentage'
  @tiers = tiers
  @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

#applies_to_price_interval_idsArray[String]

The price interval ids that this discount interval applies to.

Returns:

  • (Array[String])


37
38
39
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 37

def applies_to_price_interval_ids
  @applies_to_price_interval_ids
end

#discount_typeString (readonly)

TODO: Write general description for this method

Returns:

  • (String)


15
16
17
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 15

def discount_type
  @discount_type
end

#end_dateDateTime

The end date of the discount interval.

Returns:

  • (DateTime)


29
30
31
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 29

def end_date
  @end_date
end

#filtersArray[PriceFilter]

The filters that determine which prices this discount interval applies to.

Returns:



33
34
35
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 33

def filters
  @filters
end

#start_dateDateTime

The start date of the discount interval.

Returns:

  • (DateTime)


25
26
27
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 25

def start_date
  @start_date
end

#tiersArray[PercentageTier]

Only available if discount_type is tiered_percentage. The ordered, contiguous bands of cumulative eligible spend, each discounted at its own percentage.

Returns:



21
22
23
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 21

def tiers
  @tiers
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
117
118
119
120
121
122
123
124
125
126
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 79

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  tiers = nil
  unless hash['tiers'].nil?
    tiers = []
    hash['tiers'].each do |structure|
      tiers << (PercentageTier.from_hash(structure) if structure)
    end
  end

  tiers = nil unless hash.key?('tiers')
  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.
  TieredPercentageDiscountInterval.new(tiers: tiers,
                                       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

.namesObject

A mapping from model property names to API property names.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 40

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['discount_type'] = 'discount_type'
  @_hash['tiers'] = 'tiers'
  @_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

.nullablesObject

An array for nullable fields



58
59
60
61
62
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 58

def self.nullables
  %w[
    end_date
  ]
end

.optionalsObject

An array for optional fields



53
54
55
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 53

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 138

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.tiers,
                              ->(val) { PercentageTier.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) 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['tiers'],
                            ->(val) { PercentageTier.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) 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

#inspectObject

Provides a debugging-friendly string with detailed object information.



192
193
194
195
196
197
198
199
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 192

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_type: #{@discount_type.inspect}, tiers: #{@tiers.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_dateObject



132
133
134
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 132

def to_custom_end_date
  DateTimeHelper.to_rfc3339(end_date)
end

#to_custom_start_dateObject



128
129
130
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 128

def to_custom_start_date
  DateTimeHelper.to_rfc3339(start_date)
end

#to_sObject

Provides a human-readable string representation of the object.



183
184
185
186
187
188
189
# File 'lib/api_reference/models/tiered_percentage_discount_interval.rb', line 183

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_type: #{@discount_type}, tiers: #{@tiers}, 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