Class: AdvancedBilling::OveragePricing
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- AdvancedBilling::OveragePricing
- Defined in:
- lib/advanced_billing/models/overage_pricing.rb
Overview
OveragePricing Model.
Instance Attribute Summary collapse
-
#prices ⇒ Array[Price]
The identifier for the pricing scheme.
-
#pricing_scheme ⇒ PricingScheme
The identifier for the pricing scheme.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(pricing_scheme:, prices: SKIP, additional_properties: {}) ⇒ OveragePricing
constructor
A new instance of OveragePricing.
Methods inherited from BaseModel
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
#prices ⇒ Array[Price]
The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.
22 23 24 |
# File 'lib/advanced_billing/models/overage_pricing.rb', line 22 def prices @prices end |
#pricing_scheme ⇒ PricingScheme
The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.
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 |
.names ⇒ Object
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 |
.nullables ⇒ Object
An array for nullable fields
40 41 42 |
# File 'lib/advanced_billing/models/overage_pricing.rb', line 40 def self.nullables [] end |
.optionals ⇒ Object
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.
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 |