Class: Asdawqw::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/asdawqw/models/base_model.rb

Overview

Base model.

Direct Known Subclasses

APIResponseWithoutData, AsynchronousValidationModel, AttributesWithQuantity, Authorization, AvailabilityModel, AvailableCount, Bed, Bedroom, BedroomConfiguration, Beds, CancelReservationNotificationObject, CancellationPolicy, CheckIn, CheckOut, Company, CompanyAddress, CompanyDetails, CreateAndUpdateLOSRequest, CreateAndUpdateRatesAndAvailabilityRequest, CreateFeeAndTaxRequest, CreateImagesRequest, CreateNewUpdatePropertyManagerRequest, CreateUpdatePropertyRequest, CreateYieldRequest, CreditCard, DeleteListOfImagesRequest, DescriptionTextModel, Fee, FeeTax, FeeTaxMandatory, FeeTaxMandatorySetting, FeeTaxResponse, FeeTaxValidationSettingResponse, FeeTaxValidationSettings, FunctionsRequestToBook, FunctionsRequestToBookTest, GetImageListByProductID, GetMessageListForSpecificThreadResponse, GetMessageThreadsResponse, GetPmsList, Image, ImageUrlForCreate, ImageUrlList, InternetPolicy, LOSRatesResponse, Location, LosRate, LosRatesProduct, ManualPolicies, ManualPolicy, MaxStayModel, MessageModel, MessageRequestFromSupplier, MessagesModel, MinStayModel, NearbyAmenity, Notes, ParkingPolicy, Payment, PaymentGateways, PaymentPolicy, PetPolicy, Phone, Pms, Policies, Policy, PostNewMessageForSpecificThreadRequest, ProductResponse, Property, PropertyListRequest, PropertyManagerDetailsResponse, PushNotificationLinksModel, PushNotificationLinksRequest, PushNotificationLinksResponse, Rate, RatesAvailability, RatesAvailabilityResponse, RequestToBookAnswerFromPmsRequest, RequestToBookCancelRequestModel, RequestToBookRequestModel, RequestToBookTestRequest, ReservationCommissionsNotificationModel, ReservationFeeNotificationModel, ReservationGetResponse, ReservationNotificationObject, ReservationPushResponse, ReservationRateNotifcationModel, ReservationTaxNotificationModel, Restriction, SetFeeAndTaxValidationSettingRequest, SplitPayment, Taxes, Text, Thread, ThreadsModel, TransportYield, ValidationAsynchronousPushMessageRequest, ValidationForListOfPropertiesRequest, ValidationPropertyIDsList, Yield, YieldResponse

Instance Method Summary collapse

Instance Method Details

#to_hashObject

Returns a Hash representation of the current object.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/asdawqw/models/base_model.rb', line 10

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.



31
32
33
34
# File 'lib/asdawqw/models/base_model.rb', line 31

def to_json(options = {})
  hash = to_hash
  hash.to_json(options)
end