Class: AdvancedBilling::CreateOrUpdateSegmentPrice

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

Overview

CreateOrUpdateSegmentPrice Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(unit_price:, starting_quantity: SKIP, ending_quantity: SKIP, additional_properties: {}) ⇒ CreateOrUpdateSegmentPrice

Returns a new instance of CreateOrUpdateSegmentPrice.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/advanced_billing/models/create_or_update_segment_price.rb', line 47

def initialize(unit_price:, starting_quantity: SKIP, ending_quantity: SKIP,
               additional_properties: {})
  @starting_quantity = starting_quantity unless starting_quantity == SKIP
  @ending_quantity = ending_quantity unless ending_quantity == SKIP
  @unit_price = unit_price

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

Instance Attribute Details

#ending_quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


18
19
20
# File 'lib/advanced_billing/models/create_or_update_segment_price.rb', line 18

def ending_quantity
  @ending_quantity
end

#starting_quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


14
15
16
# File 'lib/advanced_billing/models/create_or_update_segment_price.rb', line 14

def starting_quantity
  @starting_quantity
end

#unit_priceObject

The price can contain up to 8 decimal places. i.e. 1.00 or 0.0012 or 0.00000065

Returns:

  • (Object)


23
24
25
# File 'lib/advanced_billing/models/create_or_update_segment_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.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/advanced_billing/models/create_or_update_segment_price.rb', line 60

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  unit_price = hash.key?('unit_price') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateOrUpdateSegmentPriceUnitPrice), hash['unit_price']
  ) : nil
  starting_quantity =
    hash.key?('starting_quantity') ? hash['starting_quantity'] : SKIP
  ending_quantity =
    hash.key?('ending_quantity') ? hash['ending_quantity'] : SKIP

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

  # Create object from extracted values.
  CreateOrUpdateSegmentPrice.new(unit_price: unit_price,
                                 starting_quantity: starting_quantity,
                                 ending_quantity: ending_quantity,
                                 additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



26
27
28
29
30
31
32
# File 'lib/advanced_billing/models/create_or_update_segment_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

.nullablesObject

An array for nullable fields



43
44
45
# File 'lib/advanced_billing/models/create_or_update_segment_price.rb', line 43

def self.nullables
  []
end

.optionalsObject

An array for optional fields



35
36
37
38
39
40
# File 'lib/advanced_billing/models/create_or_update_segment_price.rb', line 35

def self.optionals
  %w[
    starting_quantity
    ending_quantity
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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

def self.validate(value)
  if value.instance_of? self
    return UnionTypeLookUp.get(:CreateOrUpdateSegmentPriceUnitPrice)
                          .validate(value.unit_price)
  end

  return false unless value.instance_of? Hash

  UnionTypeLookUp.get(:CreateOrUpdateSegmentPriceUnitPrice)
                 .validate(value['unit_price'])
end