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 = nil, prices = SKIP) ⇒ OveragePricing

Returns a new instance of OveragePricing.



44
45
46
47
# File 'lib/advanced_billing/models/overage_pricing.rb', line 44

def initialize(pricing_scheme = nil, prices = SKIP)
  @pricing_scheme = pricing_scheme
  @prices = prices unless prices == SKIP
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.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/advanced_billing/models/overage_pricing.rb', line 50

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  pricing_scheme = hash.key?('pricing_scheme') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:OveragePricingPricingScheme), 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')

  # Create object from extracted values.
  OveragePricing.new(pricing_scheme,
                     prices)
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.



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/advanced_billing/models/overage_pricing.rb', line 75

def self.validate(value)
  if value.instance_of? self
    return UnionTypeLookUp.get(:OveragePricingPricingScheme)
                          .validate(value.pricing_scheme)
  end

  return false unless value.instance_of? Hash

  UnionTypeLookUp.get(:OveragePricingPricingScheme)
                 .validate(value['pricing_scheme'])
end