Class: ApiReference::TieredConfig

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

Overview

Configuration for tiered pricing

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:, prorated: false) ⇒ TieredConfig

Returns a new instance of TieredConfig.



41
42
43
44
# File 'lib/api_reference/models/tiered_config.rb', line 41

def initialize(tiers:, prorated: false)
  @tiers = tiers
  @prorated = prorated unless prorated == SKIP
end

Instance Attribute Details

#proratedTrueClass | FalseClass

If true, subtotals from this price are prorated based on the service period

Returns:

  • (TrueClass | FalseClass)


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

def prorated
  @prorated
end

#tiersArray[Tier]

Tiers for rating based on total usage quantities into the specified tier

Returns:



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

def tiers
  @tiers
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/api_reference/models/tiered_config.rb', line 47

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 << (Tier.from_hash(structure) if structure)
    end
  end

  tiers = nil unless hash.key?('tiers')
  prorated = hash['prorated'] ||= false

  # Create object from extracted values.
  TieredConfig.new(tiers: tiers,
                   prorated: prorated)
end

.namesObject

A mapping from model property names to API property names.



22
23
24
25
26
27
# File 'lib/api_reference/models/tiered_config.rb', line 22

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['tiers'] = 'tiers'
  @_hash['prorated'] = 'prorated'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    prorated
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (TieredConfig | Hash)

    value against the validation is performed.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/api_reference/models/tiered_config.rb', line 70

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.tiers,
                                 ->(val) { Tier.validate(val) },
                                 is_model_hash: true,
                                 is_inner_model_hash: true)
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['tiers'],
                        ->(val) { Tier.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.



93
94
95
96
# File 'lib/api_reference/models/tiered_config.rb', line 93

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} tiers: #{@tiers.inspect}, prorated: #{@prorated.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



87
88
89
90
# File 'lib/api_reference/models/tiered_config.rb', line 87

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} tiers: #{@tiers}, prorated: #{@prorated}>"
end