Class: AdvancedBilling::AllocationSettings

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/allocation_settings.rb

Overview

AllocationSettings Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(upgrade_charge: SKIP, downgrade_credit: SKIP, accrue_charge: SKIP, additional_properties: {}) ⇒ AllocationSettings

Returns a new instance of AllocationSettings.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/advanced_billing/models/allocation_settings.rb', line 54

def initialize(upgrade_charge: SKIP, downgrade_credit: SKIP,
               accrue_charge: SKIP, additional_properties: {})
  @upgrade_charge = upgrade_charge unless upgrade_charge == SKIP
  @downgrade_credit = downgrade_credit unless downgrade_credit == SKIP
  @accrue_charge = accrue_charge unless accrue_charge == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#accrue_chargeString

Either “true” or “false”.

Returns:

  • (String)


26
27
28
# File 'lib/advanced_billing/models/allocation_settings.rb', line 26

def accrue_charge
  @accrue_charge
end

#downgrade_creditCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Available values: ‘full`, `prorated`, `none`.

Returns:



22
23
24
# File 'lib/advanced_billing/models/allocation_settings.rb', line 22

def downgrade_credit
  @downgrade_credit
end

#upgrade_chargeCreditType

The type of credit to be created when upgrading/downgrading. Defaults to the component and then site setting if one is not provided. Available values: ‘full`, `prorated`, `none`.

Returns:



16
17
18
# File 'lib/advanced_billing/models/allocation_settings.rb', line 16

def upgrade_charge
  @upgrade_charge
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/advanced_billing/models/allocation_settings.rb', line 67

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  upgrade_charge =
    hash.key?('upgrade_charge') ? hash['upgrade_charge'] : SKIP
  downgrade_credit =
    hash.key?('downgrade_credit') ? hash['downgrade_credit'] : SKIP
  accrue_charge = hash.key?('accrue_charge') ? hash['accrue_charge'] : SKIP

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  AllocationSettings.new(upgrade_charge: upgrade_charge,
                         downgrade_credit: downgrade_credit,
                         accrue_charge: accrue_charge,
                         additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
# File 'lib/advanced_billing/models/allocation_settings.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['upgrade_charge'] = 'upgrade_charge'
  @_hash['downgrade_credit'] = 'downgrade_credit'
  @_hash['accrue_charge'] = 'accrue_charge'
  @_hash
end

.nullablesObject

An array for nullable fields



47
48
49
50
51
52
# File 'lib/advanced_billing/models/allocation_settings.rb', line 47

def self.nullables
  %w[
    upgrade_charge
    downgrade_credit
  ]
end

.optionalsObject

An array for optional fields



38
39
40
41
42
43
44
# File 'lib/advanced_billing/models/allocation_settings.rb', line 38

def self.optionals
  %w[
    upgrade_charge
    downgrade_credit
    accrue_charge
  ]
end