Method: AdvancedBilling::InvoiceLineItemEventData.from_hash

Defined in:
lib/advanced_billing/models/invoice_line_item_event_data.rb

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/advanced_billing/models/invoice_line_item_event_data.rb', line 195

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  uid = hash.key?('uid') ? hash['uid'] : SKIP
  title = hash.key?('title') ? hash['title'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  quantity = hash.key?('quantity') ? hash['quantity'] : SKIP
  quantity_delta =
    hash.key?('quantity_delta') ? hash['quantity_delta'] : SKIP
  unit_price = hash.key?('unit_price') ? hash['unit_price'] : SKIP
  period_range_start =
    hash.key?('period_range_start') ? hash['period_range_start'] : SKIP
  period_range_end =
    hash.key?('period_range_end') ? hash['period_range_end'] : SKIP
  amount = hash.key?('amount') ? hash['amount'] : SKIP
  line_references =
    hash.key?('line_references') ? hash['line_references'] : SKIP
  pricing_details_index =
    hash.key?('pricing_details_index') ? hash['pricing_details_index'] : SKIP
  # Parameter is an array, so we need to iterate through it
  pricing_details = nil
  unless hash['pricing_details'].nil?
    pricing_details = []
    hash['pricing_details'].each do |structure|
      pricing_details << (InvoiceLineItemPricingDetail.from_hash(structure) if structure)
    end
  end

  pricing_details = SKIP unless hash.key?('pricing_details')
  tax_code = hash.key?('tax_code') ? hash['tax_code'] : SKIP
  tax_amount = hash.key?('tax_amount') ? hash['tax_amount'] : SKIP
  product_id = hash.key?('product_id') ? hash['product_id'] : SKIP
  product_price_point_id =
    hash.key?('product_price_point_id') ? hash['product_price_point_id'] : SKIP
  price_point_id =
    hash.key?('price_point_id') ? hash['price_point_id'] : SKIP
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  billing_schedule_item_id =
    hash.key?('billing_schedule_item_id') ? hash['billing_schedule_item_id'] : SKIP
  custom_item = hash.key?('custom_item') ? hash['custom_item'] : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  InvoiceLineItemEventData.new(uid: uid,
                               title: title,
                               description: description,
                               quantity: quantity,
                               quantity_delta: quantity_delta,
                               unit_price: unit_price,
                               period_range_start: period_range_start,
                               period_range_end: period_range_end,
                               amount: amount,
                               line_references: line_references,
                               pricing_details_index: pricing_details_index,
                               pricing_details: pricing_details,
                               tax_code: tax_code,
                               tax_amount: tax_amount,
                               product_id: product_id,
                               product_price_point_id: product_price_point_id,
                               price_point_id: price_point_id,
                               component_id: component_id,
                               billing_schedule_item_id: billing_schedule_item_id,
                               custom_item: custom_item,
                               additional_properties: additional_properties)
end