Method: AdvancedBilling::ProductFamily.from_hash

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

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



93
94
95
96
97
98
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
# File 'lib/advanced_billing/models/product_family.rb', line 93

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  accounting_code =
    hash.key?('accounting_code') ? hash['accounting_code'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               else
                 SKIP
               end

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

  # Create object from extracted values.
  ProductFamily.new(id: id,
                    name: name,
                    handle: handle,
                    accounting_code: accounting_code,
                    description: description,
                    created_at: created_at,
                    updated_at: updated_at,
                    additional_properties: hash)
end