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 = nil, starting_quantity = SKIP, ending_quantity = SKIP) ⇒ CreateOrUpdateSegmentPrice



47
48
49
50
51
52
# File 'lib/advanced_billing/models/create_or_update_segment_price.rb', line 47

def initialize(unit_price = nil, starting_quantity = SKIP,
               ending_quantity = SKIP)
  @starting_quantity = starting_quantity unless starting_quantity == SKIP
  @ending_quantity = ending_quantity unless ending_quantity == SKIP
  @unit_price = unit_price
end

Instance Attribute Details

#ending_quantityInteger

TODO: Write general description for this method



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



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



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.



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

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

  # Create object from extracted values.

  CreateOrUpdateSegmentPrice.new(unit_price,
                                 starting_quantity,
                                 ending_quantity)
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.



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

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