Class: ApiReference::TieredPercentageDiscount

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

Overview

TieredPercentageDiscount 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:, applies_to_price_ids: SKIP, filters: SKIP, reason: SKIP, additional_properties: nil) ⇒ TieredPercentageDiscount

Returns a new instance of TieredPercentageDiscount.



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

def initialize(tiers:, 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 = 'tiered_percentage'
  @applies_to_price_ids = applies_to_price_ids unless applies_to_price_ids == SKIP
  @filters = filters unless filters == SKIP
  @reason = reason unless reason == SKIP
  @tiers = tiers
  @additional_properties = additional_properties
end

Instance Attribute Details

#applies_to_price_idsArray[String]

List of price_ids that this discount applies to. For plan/plan phase discounts, this can be a subset of prices.

Returns:

  • (Array[String])


19
20
21
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 19

def applies_to_price_ids
  @applies_to_price_ids
end

#discount_typeString (readonly)

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 14

def discount_type
  @discount_type
end

#filtersArray[PriceFilter]

The filters that determine which prices to apply this discount to.

Returns:



23
24
25
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 23

def filters
  @filters
end

#reasonString

The filters that determine which prices to apply this discount to.

Returns:

  • (String)


27
28
29
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 27

def reason
  @reason
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 (progressive fill-a-tier).

Returns:



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

def tiers
  @tiers
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
117
118
119
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 78

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')
  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.
  TieredPercentageDiscount.new(tiers: tiers,
                               applies_to_price_ids: applies_to_price_ids,
                               filters: filters,
                               reason: reason,
                               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



36
37
38
39
40
41
42
43
44
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 36

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['tiers'] = 'tiers'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    applies_to_price_ids
    filters
    reason
  ]
end

.optionalsObject

An array for optional fields



47
48
49
50
51
52
53
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 47

def self.optionals
  %w[
    applies_to_price_ids
    filters
    reason
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 123

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)
    )
  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)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



156
157
158
159
160
161
162
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 156

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}, tiers: #{@tiers.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



148
149
150
151
152
153
# File 'lib/api_reference/models/tiered_percentage_discount.rb', line 148

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}, tiers: #{@tiers},"\
  " additional_properties: #{@additional_properties}>"
end