Class: ApiReference::PercentageTier

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

Overview

One band of a tiered percentage discount. Bounds are denominated in the discount's currency. lower_bound is the exclusive start of the band and upper_bound is the inclusive end; upper_bound is null only for the open-ended final tier.

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(lower_bound:, percentage:, upper_bound: SKIP, additional_properties: nil) ⇒ PercentageTier

Returns a new instance of PercentageTier.



52
53
54
55
56
57
58
59
60
61
# File 'lib/api_reference/models/percentage_tier.rb', line 52

def initialize(lower_bound:, percentage:, upper_bound: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @lower_bound = lower_bound
  @upper_bound = upper_bound unless upper_bound == SKIP
  @percentage = percentage
  @additional_properties = additional_properties
end

Instance Attribute Details

#lower_boundFloat

Exclusive lower bound of cumulative spend for this tier.

Returns:

  • (Float)


17
18
19
# File 'lib/api_reference/models/percentage_tier.rb', line 17

def lower_bound
  @lower_bound
end

#percentageFloat

The percentage (between 0 and 1) discounted from spend that falls within this tier.

Returns:

  • (Float)


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

def percentage
  @percentage
end

#upper_boundFloat

Inclusive upper bound of cumulative spend for this tier; null for the final open-ended tier.

Returns:

  • (Float)


22
23
24
# File 'lib/api_reference/models/percentage_tier.rb', line 22

def upper_bound
  @upper_bound
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/api_reference/models/percentage_tier.rb', line 64

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  lower_bound = hash.key?('lower_bound') ? hash['lower_bound'] : nil
  percentage = hash.key?('percentage') ? hash['percentage'] : nil
  upper_bound = hash.key?('upper_bound') ? hash['upper_bound'] : 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.
  PercentageTier.new(lower_bound: lower_bound,
                     percentage: percentage,
                     upper_bound: upper_bound,
                     additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
# File 'lib/api_reference/models/percentage_tier.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['lower_bound'] = 'lower_bound'
  @_hash['upper_bound'] = 'upper_bound'
  @_hash['percentage'] = 'percentage'
  @_hash
end

.nullablesObject

An array for nullable fields



46
47
48
49
50
# File 'lib/api_reference/models/percentage_tier.rb', line 46

def self.nullables
  %w[
    upper_bound
  ]
end

.optionalsObject

An array for optional fields



39
40
41
42
43
# File 'lib/api_reference/models/percentage_tier.rb', line 39

def self.optionals
  %w[
    upper_bound
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (PercentageTier | Hash)

    value against the validation is performed.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/api_reference/models/percentage_tier.rb', line 88

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.lower_bound,
                            ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.percentage,
                              ->(val) { val.instance_of? Float })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['lower_bound'],
                          ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['percentage'],
                            ->(val) { val.instance_of? Float })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



116
117
118
119
120
# File 'lib/api_reference/models/percentage_tier.rb', line 116

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} lower_bound: #{@lower_bound.inspect}, upper_bound: #{@upper_bound.inspect},"\
  " percentage: #{@percentage.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



109
110
111
112
113
# File 'lib/api_reference/models/percentage_tier.rb', line 109

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} lower_bound: #{@lower_bound}, upper_bound: #{@upper_bound}, percentage:"\
  " #{@percentage}, additional_properties: #{@additional_properties}>"
end