Class: AdvancedBilling::OveragePricing

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

Overview

OveragePricing Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(pricing_scheme:, prices: SKIP, additional_properties: {}) ⇒ OveragePricing

Returns a new instance of OveragePricing.



44
45
46
47
48
49
50
51
52
# File 'lib/advanced_billing/models/overage_pricing.rb', line 44

def initialize(pricing_scheme:, prices: SKIP, additional_properties: {})
  @pricing_scheme = pricing_scheme
  @prices = prices unless prices == SKIP

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

Instance Attribute Details

#pricesArray[Price]

The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.

Returns:



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

def prices
  @prices
end

#pricing_schemePricingScheme

The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.

Returns:



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

def pricing_scheme
  @pricing_scheme
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/advanced_billing/models/overage_pricing.rb', line 55

def self.from_hash(hash)
  return nil unless hash

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

  prices = SKIP unless hash.key?('prices')

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

  # Create object from extracted values.
  OveragePricing.new(pricing_scheme: pricing_scheme,
                     prices: prices,
                     additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
# File 'lib/advanced_billing/models/overage_pricing.rb', line 25

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

.nullablesObject

An array for nullable fields



40
41
42
# File 'lib/advanced_billing/models/overage_pricing.rb', line 40

def self.nullables
  []
end

.optionalsObject

An array for optional fields



33
34
35
36
37
# File 'lib/advanced_billing/models/overage_pricing.rb', line 33

def self.optionals
  %w[
    prices
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (OveragePricing | Hash)

    value against the validation is performed.



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/advanced_billing/models/overage_pricing.rb', line 83

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.pricing_scheme,
                                 ->(val) { PricingScheme.validate(val) })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['pricing_scheme'],
                        ->(val) { PricingScheme.validate(val) })
end