Method: AdvancedBilling::ComponentPricePoint.from_hash
- Defined in:
- lib/advanced_billing/models/component_price_point.rb
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/advanced_billing/models/component_price_point.rb', line 201 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. id = hash.key?('id') ? hash['id'] : SKIP type = hash.key?('type') ? hash['type'] : SKIP default = hash.key?('default') ? hash['default'] : SKIP name = hash.key?('name') ? hash['name'] : SKIP pricing_scheme = hash.key?('pricing_scheme') ? hash['pricing_scheme'] : SKIP component_id = hash.key?('component_id') ? hash['component_id'] : SKIP handle = hash.key?('handle') ? hash['handle'] : SKIP archived_at = if hash.key?('archived_at') (DateTimeHelper.from_rfc3339(hash['archived_at']) if hash['archived_at']) else SKIP end 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 # Parameter is an array, so we need to iterate through it prices = nil unless hash['prices'].nil? prices = [] hash['prices'].each do |structure| prices << (ComponentPrice.from_hash(structure) if structure) end end prices = SKIP unless hash.key?('prices') use_site_exchange_rate = hash.key?('use_site_exchange_rate') ? hash['use_site_exchange_rate'] : SKIP subscription_id = hash.key?('subscription_id') ? hash['subscription_id'] : SKIP tax_included = hash.key?('tax_included') ? hash['tax_included'] : SKIP interval = hash.key?('interval') ? hash['interval'] : SKIP interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : SKIP # Parameter is an array, so we need to iterate through it currency_prices = nil unless hash['currency_prices'].nil? currency_prices = [] hash['currency_prices'].each do |structure| currency_prices << (ComponentCurrencyPrice.from_hash(structure) if structure) end end currency_prices = SKIP unless hash.key?('currency_prices') # Clean out expected properties from Hash. names.each_value { |k| hash.delete(k) } # Create object from extracted values. ComponentPricePoint.new(id: id, type: type, default: default, name: name, pricing_scheme: pricing_scheme, component_id: component_id, handle: handle, archived_at: archived_at, created_at: created_at, updated_at: updated_at, prices: prices, use_site_exchange_rate: use_site_exchange_rate, subscription_id: subscription_id, tax_included: tax_included, interval: interval, interval_unit: interval_unit, currency_prices: currency_prices, additional_properties: hash) end |