Class: AdvancedBilling::Price
- Defined in:
- lib/advanced_billing/models/price.rb
Overview
Price Model.
Instance Attribute Summary collapse
-
#ending_quantity ⇒ Object
TODO: Write general description for this method.
-
#starting_quantity ⇒ Object
TODO: Write general description for this method.
-
#unit_price ⇒ Object
The price can contain up to 8 decimal places.
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(starting_quantity:, unit_price:, ending_quantity: SKIP, additional_properties: {}) ⇒ Price
constructor
A new instance of Price.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(starting_quantity:, unit_price:, ending_quantity: SKIP, additional_properties: {}) ⇒ Price
Returns a new instance of Price.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/advanced_billing/models/price.rb', line 48 def initialize(starting_quantity:, unit_price:, ending_quantity: SKIP, additional_properties: {}) # Add additional model properties to the instance. additional_properties.each do |_name, _value| instance_variable_set("@#{_name}", _value) end @starting_quantity = starting_quantity @ending_quantity = ending_quantity unless ending_quantity == SKIP @unit_price = unit_price end |
Instance Attribute Details
#ending_quantity ⇒ Object
TODO: Write general description for this method
18 19 20 |
# File 'lib/advanced_billing/models/price.rb', line 18 def ending_quantity @ending_quantity end |
#starting_quantity ⇒ Object
TODO: Write general description for this method
14 15 16 |
# File 'lib/advanced_billing/models/price.rb', line 14 def starting_quantity @starting_quantity end |
#unit_price ⇒ Object
The price can contain up to 8 decimal places. i.e. 1.00 or 0.0012 or 0.00000065
23 24 25 |
# File 'lib/advanced_billing/models/price.rb', line 23 def unit_price @unit_price end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/advanced_billing/models/price.rb', line 61 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. starting_quantity = hash.key?('starting_quantity') ? APIHelper.deserialize_union_type( UnionTypeLookUp.get(:PriceStartingQuantity), hash['starting_quantity'] ) : nil unit_price = hash.key?('unit_price') ? APIHelper.deserialize_union_type( UnionTypeLookUp.get(:PriceUnitPrice), hash['unit_price'] ) : nil ending_quantity = hash.key?('ending_quantity') ? APIHelper.deserialize_union_type( UnionTypeLookUp.get(:PriceEndingQuantity), hash['ending_quantity'] ) : SKIP # Clean out expected properties from Hash. additional_properties = hash.reject { |k, _| names.value?(k) } # Create object from extracted values. Price.new(starting_quantity: starting_quantity, unit_price: unit_price, ending_quantity: ending_quantity, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
26 27 28 29 30 31 32 |
# File 'lib/advanced_billing/models/price.rb', line 26 def self.names @_hash = {} if @_hash.nil? @_hash['starting_quantity'] = 'starting_quantity' @_hash['ending_quantity'] = 'ending_quantity' @_hash['unit_price'] = 'unit_price' @_hash end |
.nullables ⇒ Object
An array for nullable fields
42 43 44 45 46 |
# File 'lib/advanced_billing/models/price.rb', line 42 def self.nullables %w[ ending_quantity ] end |
.optionals ⇒ Object
An array for optional fields
35 36 37 38 39 |
# File 'lib/advanced_billing/models/price.rb', line 35 def self.optionals %w[ ending_quantity ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/advanced_billing/models/price.rb', line 87 def self.validate(value) if value.instance_of? self return ( UnionTypeLookUp.get(:PriceStartingQuantity) .validate(value.starting_quantity) and UnionTypeLookUp.get(:PriceUnitPrice) .validate(value.unit_price) ) end return false unless value.instance_of? Hash ( UnionTypeLookUp.get(:PriceStartingQuantity) .validate(value['starting_quantity']) and UnionTypeLookUp.get(:PriceUnitPrice) .validate(value['unit_price']) ) end |