Class: Raas::BaseModel
- Inherits:
-
Object
- Object
- Raas::BaseModel
- Defined in:
- lib/raas/models/base_model.rb
Overview
Base model.
Direct Known Subclasses
AccountModel, AccountSummaryModel, BillingAddressModel, BrandModel, CatalogModel, CreateAccountRequestModel, CreateCreditCardRequestModel, CreateCustomerRequestModel, CreateOrderRequestModel, CreditCardModel, CurrencyBreakdownModel, CustomerModel, DepositRequestModel, DepositResponseModel, ExchangeRateModel, ExchangeRateResponseModel, FullNameEmailModel, GetDepositResponseModel, GetOrdersResponseModel, ItemModel, NameEmailModel, NewCreditCardModel, OrderModel, OrderSummaryModel, PageModel, RaasClientErrorModel, RaasServerErrorModel, ResendOrderResponseModel, RewardCredentialModel, RewardModel, SystemStatusResponseModel, UnregisterCreditCardRequestModel, UnregisterCreditCardResponseModel
Instance Method Summary collapse
-
#to_hash ⇒ Object
Returns a Hash representation of the current object.
-
#to_json(options = {}) ⇒ Object
Returns a JSON representation of the curent object.
Instance Method Details
#to_hash ⇒ Object
Returns a Hash representation of the current object.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/raas/models/base_model.rb', line 8 def to_hash hash = {} instance_variables.each do |name| value = instance_variable_get(name) name = name[1..-1] key = self.class.names.key?(name) ? self.class.names[name] : name if value.instance_of? Array hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v } elsif value.instance_of? Hash hash[key] = {} value.each do |k, v| hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v end else hash[key] = value.is_a?(BaseModel) ? value.to_hash : value end end hash end |
#to_json(options = {}) ⇒ Object
Returns a JSON representation of the curent object.
29 30 31 32 |
# File 'lib/raas/models/base_model.rb', line 29 def to_json( = {}) hash = to_hash hash.to_json() end |