Class: AdvancedBilling::SegmentPrice

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

Overview

SegmentPrice Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id: SKIP, component_id: SKIP, starting_quantity: SKIP, ending_quantity: SKIP, unit_price: SKIP, price_point_id: SKIP, formatted_unit_price: SKIP, segment_id: SKIP, additional_properties: {}) ⇒ SegmentPrice

Returns a new instance of SegmentPrice.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/advanced_billing/models/segment_price.rb', line 79

def initialize(id: SKIP, component_id: SKIP, starting_quantity: SKIP,
               ending_quantity: SKIP, unit_price: SKIP,
               price_point_id: SKIP, formatted_unit_price: SKIP,
               segment_id: SKIP, additional_properties: {})
  @id = id unless id == SKIP
  @component_id = component_id unless component_id == SKIP
  @starting_quantity = starting_quantity unless starting_quantity == SKIP
  @ending_quantity = ending_quantity unless ending_quantity == SKIP
  @unit_price = unit_price unless unit_price == SKIP
  @price_point_id = price_point_id unless price_point_id == SKIP
  @formatted_unit_price = formatted_unit_price unless formatted_unit_price == SKIP
  @segment_id = segment_id unless segment_id == SKIP

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

Instance Attribute Details

#component_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def component_id
  @component_id
end

#ending_quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


26
27
28
# File 'lib/advanced_billing/models/segment_price.rb', line 26

def ending_quantity
  @ending_quantity
end

#formatted_unit_priceString

TODO: Write general description for this method

Returns:

  • (String)


38
39
40
# File 'lib/advanced_billing/models/segment_price.rb', line 38

def formatted_unit_price
  @formatted_unit_price
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def id
  @id
end

#price_point_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


34
35
36
# File 'lib/advanced_billing/models/segment_price.rb', line 34

def price_point_id
  @price_point_id
end

#segment_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


42
43
44
# File 'lib/advanced_billing/models/segment_price.rb', line 42

def segment_id
  @segment_id
end

#starting_quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


22
23
24
# File 'lib/advanced_billing/models/segment_price.rb', line 22

def starting_quantity
  @starting_quantity
end

#unit_priceString

TODO: Write general description for this method

Returns:

  • (String)


30
31
32
# File 'lib/advanced_billing/models/segment_price.rb', line 30

def unit_price
  @unit_price
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/advanced_billing/models/segment_price.rb', line 99

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  starting_quantity =
    hash.key?('starting_quantity') ? hash['starting_quantity'] : SKIP
  ending_quantity =
    hash.key?('ending_quantity') ? hash['ending_quantity'] : SKIP
  unit_price = hash.key?('unit_price') ? hash['unit_price'] : SKIP
  price_point_id =
    hash.key?('price_point_id') ? hash['price_point_id'] : SKIP
  formatted_unit_price =
    hash.key?('formatted_unit_price') ? hash['formatted_unit_price'] : SKIP
  segment_id = hash.key?('segment_id') ? hash['segment_id'] : SKIP

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

  # Create object from extracted values.
  SegmentPrice.new(id: id,
                   component_id: component_id,
                   starting_quantity: starting_quantity,
                   ending_quantity: ending_quantity,
                   unit_price: unit_price,
                   price_point_id: price_point_id,
                   formatted_unit_price: formatted_unit_price,
                   segment_id: segment_id,
                   additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['component_id'] = 'component_id'
  @_hash['starting_quantity'] = 'starting_quantity'
  @_hash['ending_quantity'] = 'ending_quantity'
  @_hash['unit_price'] = 'unit_price'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['formatted_unit_price'] = 'formatted_unit_price'
  @_hash['segment_id'] = 'segment_id'
  @_hash
end

.nullablesObject

An array for nullable fields



73
74
75
76
77
# File 'lib/advanced_billing/models/segment_price.rb', line 73

def self.nullables
  %w[
    ending_quantity
  ]
end

.optionalsObject

An array for optional fields



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/advanced_billing/models/segment_price.rb', line 59

def self.optionals
  %w[
    id
    component_id
    starting_quantity
    ending_quantity
    unit_price
    price_point_id
    formatted_unit_price
    segment_id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (SegmentPrice | Hash)

    value against the validation is performed.



133
134
135
136
137
138
139
# File 'lib/advanced_billing/models/segment_price.rb', line 133

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end