Class: ReservationProperty

Inherits:
ApplicationRecord show all
Includes:
ArTransactionChanges
Defined in:
app/models/reservation_property.rb

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Method Details

#add_on?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/models/reservation_property.rb', line 54

def add_on?
  add_on.present?
end

#custom_package_pricingObject



62
63
64
65
66
# File 'app/models/reservation_property.rb', line 62

def custom_package_pricing
  return nil unless package?

  package['custom_package_data']
end

#custom_package_pricing?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/reservation_property.rb', line 58

def custom_package_pricing?
  package? && package['custom_package_data'].present?
end

#package?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/reservation_property.rb', line 50

def package?
  package.present?
end

#price_centsInteger, BigDecimal

price_cents column is a virtual column in the database it is calculated as the sum of package price_cents and add-on price_cents if either package or add-on is nil, it is treated as 0 so needs to create an instance method to access the value correctly

Returns:

  • (Integer, BigDecimal)


85
86
87
88
# File 'app/models/reservation_property.rb', line 85

def price_cents
  value = (self[:price_cents] || 0).to_d
  value % 1 == 0 ? value.to_i : value
end

#revenueInteger, BigDecimal

revenue column is a virtual column in the database it is calculated as the sum of package revenue and add-on revenue if either package or add-on is nil, it is treated as 0 so needs to create an instance method to access the value correctly

Returns:

  • (Integer, BigDecimal)


74
75
76
77
# File 'app/models/reservation_property.rb', line 74

def revenue
  value = (self[:revenue] || 0).to_d
  value % 1 == 0 ? value.to_i : value
end